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

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

{
    my $db_dir = ${'geneweb'}{'DBDir'} || "/opt/geneweb/bases";
    $OUT .= <<END_BD;
BD="$db_dir"
END_BD
}
#BD="/opt/geneweb/bases" (default)
HD="/opt/geneweb/gw/gw"

start() \{
	echo "Starting GeneWeb Services:"
	$HD/gwd -log /var/log/gwd.log -daemon -hd $HD -bd $BD -setup_link
	$HD/gwsetup -daemon -gd $HD 2>> /var/log/gwsetup.log
	touch /var/lock/subsys/gwd
\}

stop() \{
	echo -n "Shutting down GeneWeb Services: "
	killproc $HD/gwd
	killproc $HD/gwsetup
	rm -f /var/lock/subsys/gwd
	echo
\}

restart() \{
	echo -n "Restarting GeneWeb Services: "
	stop
	sleep 1
	start
\}

# See how we were called.
cd $BD

case "$1" in
	start|stop|restart)
	    $1
	    ;;
	status)
	    status gwd
	    ;;
	*)
	    echo "*** Usage: gwd \{start|stop|status|restart\}"
	    exit 1
esac

exit 0
