#!/bin/sh
#
# cyclient          This shell script takes care of starting and stopping
#                   the cyphesis service.

### BEGIN INIT INFO
# Provides:     cyclient
# Required-Start:   $local_fs $remote_fs $network
# Required-Stop:    $local_fs $remote_fs $network
# Default-Start:    3 5
# Default-Stop:     0 1 2 6
# Short-Description:    cyclient service
# Description:      Cyphesis is a server for WorldForge online games.
### END INIT INFO

. /etc/rc.status

rc_reset

# Source cyphesis service configuration
if [ -f /etc/cyphesis/cyphesis.sysconfig ] ; then
	. /etc/cyphesis/cyphesis.sysconfig
else
	CYPHESISUSER=cyphesis
fi

# Run the client
start() {
	echo -n $"Populating cyphesis world: "
	
	# Run the server, in self daemonising mode
	su $CYPHESISUSER -c "/usr/bin/cyclient" >/dev/null 2>&1
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		rc_status -v
	else
		rc_failed
		rc_status -v
	fi
	return $RETVAL
}

stop() {
	rc_status -v1
	return 0
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		stop
		start
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 (start|stop)"
		exit 1
esac

exit $RETVAL
