#!/bin/sh
#
# schedwiclnt:        Starts the Schedwi agent daemon
#
# chkconfig: 2345 97 03
# description:  This is the agent daemon which receives task requests \
#               from the Schedwi server and runs them on the local host. \
#               When a task is finished, it reports its status back \
#               to te server
#
# processname: schedwiclnt
# config: /etc/schedwiclnt.conf
# pidfile: /var/run/schedwiclnt.pid
#

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

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

RETVAL=0

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

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

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