#!/bin/sh
#
# crond		Start/Stop the cron clock daemon.
#
# chkconfig:	2345 40 60
#
# description:	Fcron is a periodical command scheduler which aims at replacing \
#		Vixie Cron, so it implements most of its functionalities.
#
# processname:	crond
# config:	/etc/fcron.conf
# pidfile:	/var/run/crond.pid


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

# Get service config
[ -f /etc/sysconfig/cron ] && . /etc/sysconfig/cron

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/crond ]; then
		msg_starting fcron
		[ -f /var/spool/cron/systab.orig ] && rm -rf /var/spool/cron/systab.orig
		FIND=`find /etc/cron.d/ \( -type f ! -name '*~' ! -name \*\.swp \
		      ! -name \*\.rpmorig ! -name \*\.rpmnew ! -name \*\.rpmsave \)`
			for FILE in $FIND; do
				cat $FILE >>/var/spool/cron/systab.orig
			done
		fcrontab -u systab -z > /dev/null 2>&1
		daemon /usr/sbin/crond -b -c /etc/fcron.conf
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/crond
		else
		msg_already_running fcron
	fi
	;;
  stop)
	# Stop daemons.
	if [ -f /var/lock/subsys/crond ]; then
		msg_stopping fcron
		killproc crond
		rm -f /var/lock/subsys/crond >/dev/null 2>&1
	else
		msg_not_running fcron
	fi

	;;
  status)
	status crond
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
