#!/bin/sh
#
# osad     This shell script starts the osad daemon
#
# chkconfig: - 86 04
# description: osad is a daemon used by the Spacewalk
#
### BEGIN INIT INFO
# Provides: osad
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: This shell script starts the osad daemon
# Description:       osad is a daemon used by the Spacewalk
### END INIT INFO

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

# Source networking configuration.
. /etc/sysconfig/network

# Source prog-specific configuration
if [ -f /etc/sysconfig/osad ]; then
	. /etc/sysconfig/osad
fi

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

RETVAL=0
prog="osad"
script="/usr/sbin/osad"

[ -f $script ] || exit 0

start() {
    # Start daemon
    echo -n "Starting $prog: "
    if [ "$prog" == "osa-dispatcher" ]; then
        /usr/sbin/spacewalk-startup-helper wait-for-jabberd
    fi
    daemon $script --pid-file /var/run/$prog.pid
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}


stop() {
    # Stop daemon
    echo -n "Shutting down $prog: "
    killproc $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        stop
        start
        ;;
    status)
        status "$script"
        RETVAL=$?
        ;;
    condrestart)
        if status "$script" >/dev/null; then
            stop
            start
        fi
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
        exit 1
esac

exit $RETVAL

