#! /bin/sh
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.
# processname: crond
# config: /etc/crontab
# pidfile: /var/run/crond.pid

RETVAL=0
prog="crond"
CROND=/sbin/crond
CRONDARGS="-c /etc/cron.d -b"
LOCK_FILE=/var/lock/subsys/crond

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

if [ -f /usr/local/etc/cron.d/root ]; then
    cp -f /usr/local/etc/cron.d/root /etc/cron.d/
fi
    
if [ -d /crontabs ]; then
    ln -sf /etc/cron.d/ /crontabs
fi

prog="crond"

start() {
	echo -n "Starting $prog: "
	daemon $prog $CRONDARGS && success || failure
	RETVAL=$?
	[ "$RETVAL" = 0 ] && touch $LOCK_FILE
	echo
}

stop() {
	echo -n "Stopping $prog: "
	if [ -n "`pidfileofproc $CROND`" ]; then
		killproc $CROND
		RETVAL=3
	else
		failure "Stopping $prog"
	fi
	RETVAL=$?
	[ "$RETVAL" = 0 ] && rm -f $LOCK_FILE
	echo
}	

reload() {
	echo -n "Reloading $prog: "
	if [ -n "`pidfileofproc $CROND`" ]; then
		killproc $CROND -HUP
	else
		failure "Reloading $prog"
	fi
	RETVAL=$?
	echo
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
  	start
	;;
  reload)
  	reload
	;;
  status)
	status $CROND
	;;
  condrestart)
    if [ -f  $LOCK_FILE ]; then
        if [ "$RETVAL" = 0 ]; then
            stop
            sleep 3
            start
        fi
    fi
    ;;
  *)
	echo "Usage: $0 {start|stop|status|reload|restart|condrestart}"
	RETVAL=3
esac
exit $RETVAL

