#!/usr/bin/bash
#
# Copyright 2001-2010 WiKID Systems, Inc.
# License: WiKID Systems, Inc. All Rights Reserved.
#
# Control script designed to allow an easy command line interface
# to controlling WiKID. Not much here right now, since we're just
# wrapping the existing setup script, but stay tuned ...
#
# Adapted from apachectl, written by Marc Slemko, 1997/08/23
# 
ARGV="$@"
#
# |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
# --------------------                              --------------------
# 
# pick up any necessary environment variables
if test -f /etc/WiKID/setenv.sh; then
  . /etc/WiKID/setenv.sh
fi
#
# Set this variable to a command that increases the maximum
# number of file descriptors allowed per child process. This is
# critical for configurations that use many file descriptors,
# such as mass vhosting, or a multithreaded server.
ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"
# --------------------                              --------------------
# ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||

# Set the maximum number of file descriptors allowed per child process.
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
    $ULIMIT_MAX_FILES
fi

ERROR=0
#if [ "x$ARGV" = "x" ] ; then 
#    ARGV="-h"
#fi

OPENDS_BIN=$WIKID_HOME/directory/bin
SUDO="/usr/bin/sudo -E -u $WIKID_USER"

if [ "x$1" = "xstart" ] ; then 
	$SUDO $OPENDS_BIN/start-ds
elif [ "x$1" = "xstop" ] ; then 
	$SUDO $OPENDS_BIN/stop-ds
elif [ "x$1" = "xrestart" ] ; then 
	$SUDO $OPENDS_BIN/stop-ds
	sleep 3
	$SUDO $OPENDS_BIN/start-ds
	ERROR=$?
else
	echo "Unknown command."
	ERROR=$?
fi

exit $ERROR

