#! /bin/sh
### BEGIN INIT INFO
# Provides:             shibd
# Required-Start:       $local_fs $remote_fs $network
# Required-Stop:        $local_fs $remote_fs $network
# Default-Start:        2 3 4 5
# Default-Stop:         S 0 1 6
# Short-Description:    Shibboleth session and attribute daemon
# Description:          Starts the separate daemon used by the Shibboleth
#                       Apache module to manage sessions and to retrieve
#                       attributes from Shibboleth federation servers.
### END INIT INFO
#
# Written by Quanah Gibson-Mount <quanah@stanford.edu>
# Based on the dh-make template written by:
#
#     Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#     Modified for Debian 
#     by Ian Murdock <imurdock@gnu.ai.mit.edu>.

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="Shibboleth daemons"
NAME=shibd
DAEMON=/usr/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed.
[ -x "$DAEMON" ] || exit 0

# Read configuration if it is present.
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Get the setting of VERBOSE and other rcS variables.
[ -f /etc/default/rcS ] && . /etc/default/rcS

case "$1" in
start)
    # Don't start shibd if NO_START is set.
    if [ "$NO_START" = 1 ] ; then
        echo "Not starting $DESC (see /etc/default/$NAME)"
        exit 0
    fi
    echo -n "Starting $DESC: "
    start-stop-daemon --background --start --quiet \
        --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
    echo "$NAME."
    ;;
stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
        --exec $DAEMON
    echo "$NAME."
    ;;
restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
        --exec $DAEMON
    sleep 1
    start-stop-daemon --background --start --quiet \
        --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
    echo "$NAME."
    ;;
*)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0
