#! /bin/sh
### BEGIN INIT INFO
# Provides:          likewise-open-lsassd
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Start Likewise Identity and Authentication Service
# Description: Start and Stop the Likewise Identity and Authentication Service
### END INIT INFO

# Author: Thierry Carrez <thierry.carrez@ubuntu.com>

PATH=/usr/sbin:/usr/bin:/sbin:/bin
NAME=lsassd
DESC="Likewise Identity and Authentication Service"
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
PROG_ARGS="--start-as-daemon"
PROG_ERR=/var/lib/likewise-open5/$NAME/$NAME.err

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

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

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

#unset TMPDIR

# Define LSB functions.
. /lib/lsb/init-functions

case "$1" in
    start)
        log_daemon_msg "Starting $DESC"
        if [ -f "$PROG_ERR" ]; then
            rm -f "$PROG_ERR"
        fi
        # --quiet --oknodo are from our initscript
        start-stop-daemon --start --oknodo --exec $DAEMON -- $PROG_ARGS
        status=$?
        sleep 1 # From likewise initscript
        log_end_msg $status
        ;;

    stop)
        log_daemon_msg "Stopping $DESC"
        start-stop-daemon --stop --oknodo --quiet --exec $DAEMON --retry 5
        status=$?
        log_end_msg $status
        ;;

    status)
        status_of_proc $DAEMON $NAME && exit 0 || exit $?
        ;;

    restart|force-reload)
        $0 stop && sleep 1 && $0 start
        status=$?
        ;;

    reload)
        log_daemon_msg "Reloading $DESC"
        start-stop-daemon --stop --signal HUP --pidfile $PIDFILE
        status=$?
        log_end_msg $status
        ;;

    *)
        echo "Usage: $0 {start|stop|status|restart|reload|force-reload}"
        exit 1
        ;;

esac
exit $status
