#!/bin/sh
### BEGIN INIT INFO
# Provides:          sssd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: System Security Services Daemon
# Description:       Provides a set of daemons to manage access to
#                    remote directories and authentication
#                    mechanisms. It provides an NSS and PAM interface
#                    toward the system and a pluggable backend system
#                    to connect to multiple different account sources.
### END INIT INFO
# start on filesystem
# stop on runlevel [06]

DESCRIPTION="System Security Services Daemon"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=sssd
DAEMON_OPTS=""
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

if [ -f /etc/default/sssd ] ; then
    . /etc/default/sssd
fi

initdmain() {
    case "$1" in
        start)
            [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESCRIPTION" "$NAME"
            start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS
            RC=$?
            case "$RC" in
                0)
                    [ "$VERBOSE" != no ] && log_end_msg $RC
                    ;;
                *)
                # Report error also when VERBOSE=no
                    log_daemon_msg "Starting $DESCRIPTION" "$NAME"
                    log_end_msg $RC
                    ;;
            esac
            ;;
        stop)
            [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESCRIPTION" "$NAME"
            killproc -p $PIDFILE $DAEMON
            RC=$?
            case "$RC" in
                0)
                    [ "$VERBOSE" != no ] && log_end_msg $RC
                    ;;
                *)
                # Report error also when VERBOSE=no
                    log_daemon_msg "Stopping $DESCRIPTION" "$NAME"
                    log_end_msg $RC
                    ;;
            esac
            ;;
        force-reload|restart)
            $0 stop
            $0 start
            ;;
        status)
            status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
            ;;
        *)
            echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}"
            exit 1
            ;;
    esac
}

initdmain $@

exit 0
