#! /bin/sh
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 40 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

WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/crond.pid
LOCKFILE=/var/lock/subsys/crond
RETVAL=0

start()
{
	local nprocs load=

	load=
	nprocs=`egrep -cs ^cpu[0-9]+ /proc/stat ||:`
	if [ "$nprocs" -gt 1 ] 2>/dev/null; then
		load="-l $nprocs.5"
	fi

	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- crond $load
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root crond
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading crond
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP crond
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root crond
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
