#!/bin/sh
#
# rhnsd:	Starts the SpacewalkDaemon
#
# chkconfig: 345 97 03
# description:  This is a daemon which handles the task of connecting \
#		periodically to the Spacewalkservers 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: 3 5
# Default-Stop: 0 1 6
# Short-Description: Starts the SpacewalkDaemon
# 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
RHNSD_PIDFILE=/var/run/rhnsd.pid

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

# Source function library.
. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

start() {
    echo -n $"Starting Spacewalk Daemon: "
    startproc -p $RHNSD_PIDFILE $RHNSD
    rc_status -v
    [ -x /usr/sbin/spacewalk-update-status ] && /usr/sbin/spacewalk-update-status
}

stop() {
    echo -n $"Stopping Spacewalk Daemon: "
    killproc -p $RHNSD_PIDFILE $RHNSD
    rc_status -v
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
        echo -n "Checking for service rhnsd: "
        checkproc -p $RHNSD_PIDFILE $RHNSD
	rc_status -v
        ;;
    restart|force-reload)
	stop
	start
	;;
    condrestart|try-restart)
        $0 status
        if test $? = 0; then
            $0 restart
        else
            rc_reset
        fi
        rc_status
	;;
    reload)
        echo -n $"Reloading Spacewalk Daemon: "
        killproc -p $RHNSD_PIDFILE -HUP $RHNSD
        rc_status -v
        echo
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|force-reload|condrestart|try-restart|reload}"
        exit 2
esac
rc_exit
