#!/bin/sh
#
# rhnsd:	Starts the Spacewalk Daemon
#
# chkconfig: 345 97 03
# description:  This is a daemon which handles the task of connecting \
#		periodically to the Spacewalk servers to \
#		check for updates, notifications and perform system \
#		monitoring tasks according to the service level that \
#		this server is subscribed for		
#
# processname: rhnsd
# pidfile: /var/run/rhnsd.pid
#

### BEGIN INIT INFO
# Provides: rhnsd
# Required-Start: $local_fs $network $remote_fs $named $time
# Required-Stop: $local_fs $network $remote_fs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the Spacewalk Daemon
# Description: This is a daemon which handles the task of connecting
#               periodically to the Spacewalk servers to
#               check for updates, notifications and perform system
#               monitoring tasks according to the service level that
#               this server is subscribed for.
### END INIT INFO


# interval in minutes to connect to Spacewalk server. The minimum allowed
# value is currently 1 hour; by default rhnsd will connect every four hours.
# This should be more than suitable for the vast majority of systems.  You
# may adjust the interval by editing the file /etc/sysconfig/rhn/rhnsd.

RHNSD=/usr/sbin/rhnsd

# Sanity checks.
[ -x $RHNSD ] || exit 6

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

RETVAL=0

start() {
    echo -n $"Starting Spacewalk Daemon: "
    daemon rhnsd
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/rhnsd
}

stop() {
    echo -n $"Stopping Spacewalk Daemon: "
    killproc rhnsd -TERM
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/rhnsd
    fi
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
        status rhnsd
	RETVAL=$?
        ;;
    restart|force-reload)
	stop
	start
	;;
    condrestart|try-restart)
	if [ -f /var/lock/subsys/rhnsd ]; then
	    stop
	    start
	fi
	;;
    reload)
        echo -n $"Reloading Spacewalk Daemon: "
        if [ -n "`pidfileofproc $RHNSD`" ] ; then
            killproc $RHNSD -HUP
            RETVAL=$?
        else
            failure $"Reloading rhnsd"
            # not running
            RETVAL=7
        fi
        echo
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|force-reload|condrestart|try-restart|reload}"
        exit 2
esac
exit $RETVAL
