#!/bin/sh
# chkconfig: 345 99 01
#
# gwsetup:       Starts the genealogy Server Administration service
#
# Version:      @(#) /etc/rc.d/init.d/gwsetup 1.0
#
# description: Starts and stops the genealogy Server Administration service at boot time and shutdown.
#
# processname: gwsetup
# hide: true

# Source function library.
if [ -f /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions
fi

HD="/opt/geneweb/gw/gw"
BIN="$\{HD\}/gwsetup"

USER="root"		#geneweb"
GWLANG=$(/sbin/e-smith/db configuration getprop sysconfig Language | sed -e 's/_.*$//')

BD=$(/sbin/e-smith/db configuration getprop geneweb DBDir || echo "/opt/geneweb/bases")
TcpPort=$(/sbin/e-smith/db configuration getprop gwsetup TCPPort)

#OPTIONS="-lang $GWLANG -gd $HD -bindir $HD -p $TcpPort"

start() \{
	echo -n "Starting GeneWeb Setup service (gwsetup):"
	$HD/gwsetup -daemon -gd $HD -bindir $HD -p $TcpPort -lang $GWLANG
#	daemon --user $USER $BIN -daemon -lang $GWLANG -gd $HD -bindir $HD -p $TcpPort
#	daemon --user $USER $BIN $OPTIONS
#		 1>> /var/log/gwsetup.log 2>&1
#	daemon --check $servicename --user $USER $BIN $OPTIONS
	touch /var/lock/subsys/gwsetup
\}

stop() \{
	echo -n "Shutting down GeneWeb Setup service (gwsetup):"
	killproc $BIN
	rm -f /var/lock/subsys/gwsetup
	echo ""
\}

restart() \{
	echo "Restarting GeneWeb Setup service (gwsetup): "
	stop
	sleep 1
	start
\}

# See how we were called.
cd $BD
 
case "$1" in
	start|stop|restart)
	    $1
	    ;;
	status)
	    status $BIN
	    ;;
	*)
	    echo "*** Usage: gwsetup \{start|stop|status|restart\}"
	    exit 1
esac

exit 0
