#! /bin/sh
### BEGIN INIT INFO
# Provides:          ltsp-cluster-accountmanager
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Required-Start:
# Required-Stop:
# Short-Description: LTSP account manager (used for temporary login)
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/ltsp-cluster-accountmanager
NAME=ltsp-cluster-accountmanager
CONFIG=/etc/ltsp/accountmanager.conf
PIDFILE=/var/run/$NAME.pid
DESC="LTSP account manager"

unset TMPDIR

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
	log_begin_msg "Starting $DESC: $NAME"
	start-stop-daemon -m --background --start --quiet --oknodo --pidfile "$PIDFILE" --exec $DAEMON $CONFIG

	log_end_msg $?
	;;
  stop)
	log_begin_msg "Stopping $DESC: $NAME"
	start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE
	log_end_msg $?
	;;
  restart|force-reload)
	log_begin_msg "Restarting $DESC: $NAME"
	if start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE; then
		start-stop-daemon -m --background --start --quiet --pidfile "$PIDFILE" --exec $DAEMON $CONFIG
	fi
	log_end_msg $?
	;;
  status)
	echo -n "Status of $DESC: "
	if [ ! -r "$PIDFILE" ]; then
		echo "$NAME is not running."
		exit 3
	fi
	if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
		echo "$NAME is running."
		exit 0
	else
		echo "$NAME is not running but $PIDFILE exists."
		exit 1
	fi
	;;
  *)
	N=/etc/init.d/${0##*/}
	echo "Usage: $N {start|stop|restart|status}" >&2
	exit 1
	;;
esac

exit 0
