#! /bin/sh
### BEGIN INIT INFO
# Provides:          boss_build-status
# Required-Start:    $remote_fs boss
# Required-Stop:     $null
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Participant for build failed packages
# Description:       Participant for build failed packages
### END INIT INFO

#set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="OBS Package building stutus monitor service"
NAME=$0
SCRIPTNAME=/etc/init.d/$NAME
CONFIG=/etc/boss/boss-participant-build-status.conf
PNAME=obs_build_status
SNAME=boss-build-status-participant

. /etc/rc.status

# First reset status of this service
rc_reset

#
#       Function that starts the daemon/service.
#
d_start()
{
        if [ -f /var/run/boss/$PNAME.pid ]; then
            echo -n " already running"
        else
            startproc /usr/bin/$SNAME.py -c $CONFIG
        fi
}

#
#       Function that stops the daemon/service.
#
d_stop() {
        killproc /usr/bin/$SNAME.py \
                          || echo -n " not running"
        if [ -f /var/run/boss/$PNAME.pid ]; then
           rm /var/run/boss/$PNAME.pid
        fi
}

ACTION="$1"
case "$ACTION" in
    start)
        echo -n "Starting $DESC "
        [ -d /var/run/boss ] || mkdir /var/run/boss
        d_start
        echo "."
        ;;

    stop)
        echo -n "Stopping $DESC "
        d_stop
        echo "."
        ;;

    restart|force-reload)
        echo -n "Restarting $DESC "
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
    status)
        checkproc -p /var/run/boss/$PNAME.pid /usr/bin/$SNAME.py
        rc_status -v
        ;;
    *)
        echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

rc_exit

