#! /bin/sh
#
# maxdb-server: startup file for MaxDB vserver
#
### BEGIN INIT INFO
# Provides: maxdb-xserver
# Required-Start: $local_fs $remote_fs $time
# Required-Stop: $local_fs $remove_fs
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop of MaxDB communication server
# Description: multiline_description
### END INIT INFO
#
# (c) 2004-2007 by Martin Kittel.
# Based on the example file written by
# Miquel van Smoorenburg <miquels@cistron.nl> and
# Ian Murdock <imurdock@gnu.ai.mit.edu>.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
XSERVER=/usr/lib/maxdb/programs/bin/x_server
VSERVER=/usr/lib/maxdb/programs/pgm/vserver
NAME=x_server
DESC="MaxDB communication server"

test -x $XSERVER || exit 0

set -e


case "$1" in
  start)

        echo -n "Starting $DESC: ";  start-stop-daemon --quiet --exec $VSERVER --startas $XSERVER --chuid sdb --group sdba --start 2> /dev/null
        echo "$NAME."
	;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --quiet --exec $VSERVER --stop 2> /dev/null || true
	echo "$NAME."
	;;
  reload)
	# echo "Reloading $DESC."
        ;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#

	echo -n "Restarting $DESC: "
        start-stop-daemon --quiet --exec $VSERVER --stop 2> /dev/null
	sleep 1
        start-stop-daemon --quiet --exec $VSERVER --startas $XSERVER --chuid sdb --group sdba --start 2> /dev/null
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
