#!/bin/sh
#
# shinken-arbiter - Startup script for the Shinken Arbiter Daemon
#
# chkconfig: - 20 80
# description:  Shinken is a monitoring tool and the Arbiter \
#               is one of its daemon. This one reads the configuration, \
#               cuts it into parts and dispatches it. Then it waits \
#               for orders from the users to dispatch them too.

### BEGIN INIT INFO
# Provides:          shinken-arbiter
# Required-Start:    $all 
# Required-Stop:     $all
# Should-Start:    
# Should-Stop: 
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Shinken arbiter daemon
# Description:       Shinken is a monitoring tool and the Arbiter
#                    is one of its daemon. This one reads the configuration,
#                    cuts it into parts and dispatches it. Then it waits
#                    for orders from the users to dispatch them too.
### END INIT INFO



# Source function library.
. /etc/rc.d/init.d/functions


daemon_args="-d -c /etc/shinken/nagios.cfg -c /etc/shinken/shinken-specific.cfg"             # Arguments to run the daemon with
pidfile=/var/run/shinken/arbiterd.pid

exec="/usr/sbin/shinken-arbiter"
prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {

    directory=$(dirname $pidfile)                                                                                                                                    
    [ ! -d $directory ] && mkdir -p $directory
    chown nagios:root $directory

    echo -n $"Starting $prog: "
    $exec $daemon_args
    # if not running, start it up here, usually something like "daemon $exec"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile}
    # stop it here, often "killproc $prog"
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        status $prog
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
	;;
    reload)
        # If config can be reloaded without restarting, implement it here,
        # remove the "exit", and add "reload" to the usage message below.
        # For example:
        # status $prog >/dev/null || exit 7
        # killproc $prog -HUP
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
        exit 2
esac
