#! /bin/sh
### BEGIN INIT INFO
# Provides:				al-session-daemon
# Required-Start:		$syslog
# Required-Stop:		$syslog
# Should-Start:			$local_fs
# Should-Stop:			$local_fs
# Default-Start:		2 3 4 5
# Default-Stop:			0 1 6
# Short-Description:	Start Albatross Session Server Daemon
# Description:			Start the Albatross Session Server Daemon
### END INIT INFO

# albatross	SysV init script for Albatross Session Server Daemon
#		and Albatross Standalone Application Server
#
#               Copyright 2003-2005 Fabian Fagerholm <fabbe@paniq.net>.
#
#               Based on a skeletal version with the following credits:
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=albatross
USER=albatross

SESSION_SERVER=/usr/bin/al-session-daemon
SESSION_NAME=al-session-daemon
SESSION_LOGFILE=/var/log/albatross/albatross-session-daemon.log
SESSION_PIDFILE=/var/run/albatross/al-session-daemon.pid
SESSION_DESC="session server"

# Define LSB functions
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Source defaults or user configuration.
[ -r /etc/default/albatross ] && . /etc/default/albatross

test -x $SESSION_SERVER || exit 0

if [ $SESSION_ENABLE -eq 0 ]; then
    echo "Albatross session server not enabled."
    exit 0
fi

set -e

case "$1" in
    start)
	log_daemon_msg "Starting Albatross" "$SESSION_DESC"

	start-stop-daemon --start \
	    --verbose \
	    --exec $SESSION_SERVER \
	    --pidfile $SESSION_PIDFILE \
	    --user $USER \
	    --name $SESSION_NAME \
	    -- \
	    --port=$SESSION_PORT \
	    --log=$SESSION_LOGFILE \
	    --pidfile=$SESSION_PIDFILE \
	    start
		
	log_end_msg 0
	;;
    stop)
	log_daemon_msg "Stopping Albatross" "$SESSION_DESC"

	start-stop-daemon --start \
	    --verbose \
	    --exec $SESSION_SERVER \
	    --pidfile $SESSION_PIDFILE \
	    --user $USER \
	    --name $SESSION_NAME \
	    -- \
	    --port=$SESSION_PORT \
	    --log=$SESSION_LOGFILE \
	    --pidfile=$SESSION_PIDFILE \
	    stop

	log_end_msg 0
	;;
    restart|force-reload)
	$0 stop
	$0 start
	;;
	status)
	if [ "`id -ru`" -ne "0" ]
	then
		log_failure_msg "You must be root to check the status."
		exit 1
	fi
	$SESSION_SERVER status
	;;
  *)
	N=/etc/init.d/$NAME
	log_success_msg "Usage: $N {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0
