#!/bin/sh
#
# schedwireg:        Starts the Schedwi server daemon
#
# chkconfig: - 97 03
# description:  This is the registrar daemon which registers agents. \
#               When an agent starts for the first time it sends a \
#               Certificate request to this daemon. The request is then \
#               signed (schedwica) by an administrator.  The CA \
#               certificate is also provided to the agents through the \
#               schedwireg daemon
#
# processname: schedwireg
# config: /etc/schedwisrv.conf
# pidfile: /var/run/schedwisrv/schedwireg.pid
#

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

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

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

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

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

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