#!/bin/sh
#
# schedwisrv:        Starts the Schedwi server daemon
#
# chkconfig: - 97 03
# description:  This is the server daemon which schedules the tasks and \
#               submits them to the agents.  The execution of a task \
#               can be triggered by date and time but also by the \
#               result of a previous task or by the existence of a file \
#               on a remote agent (useful when a task must process a \
#               file generated by a previous task)
#
# processname: schedwisrv
# config: /etc/schedwisrv.conf
# pidfile: /var/run/schedwisrv/schedwisrv.pid
#

# Sanity checks.
[ -x "/usr/bin/schedwisrv" ] || exit 0

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

RETVAL=0
PIDFILE="/var/run/schedwisrv/schedwisrv.pid"

start() {
    echo -n $"Starting the Schedwi Server Daemon: "
    daemon --pidfile="${PIDFILE}" "/usr/bin/schedwisrv"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/schedwisrv
}

stop() {
    echo -n $"Stopping the Schedwi Server Daemon: "
    killproc -p "${PIDFILE}" "/usr/bin/schedwisrv"
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/schedwisrv
    fi
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status schedwisrv
        RETVAL=$?
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/schedwisrv ]; then
            stop
            start
        fi
        ;;
    reload)
        killproc -p "${PIDFILE}" "/usr/bin/schedwisrv" -HUP
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        ;;
esac
exit $RETVAL
