#!/bin/sh

# Bring up/down crond

. /etc/sysconfig/rc.conf
. /bin/network-functions
. /etc/image_features

SETSID=/usr/bin/setsid
PIDFILE=/var/run/crond.pid
SERVICE=crond
PROCESS_NAME=crond
#-s            directory of system crontabs (defaults to /etc/cron.d)
#-c            directory of per-user crontabs (defaults to /var/spool/cron/crontabs)
#-t            directory of timestamps (defaults to /var/spool/cron/cronstamps)
#-m user@host  where should cron output be directed? (defaults to local user)
#-M mailer     (defaults to /usr/sbin/sendmail)
#-S            log to syslog using identity 'crond' (default)
#-L file       log to specified file instead of syslog
#-l loglevel   log events <= this level (defaults to notice (level 5))
#-b            run in background (default)
#-f            run in foreground
#-d            run in debugging mode

CCRONTABS="/var/spool/cron/crontabs"
CRONSTAMPS="/var/spool/cron/cronstamps"
CROND_ARGS="-S -l info -c $CCRONTABS -t $CRONSTAMPS"

KILLALL=/usr/bin/killall

do_start ()
{
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	if [ ! -d /etc/fiad-conf/cron ]; then
		mkdir /etc/fiad-conf/cron
	fi
	
	if [ ! -d /etc/fiad-conf/cron/crontabs ]; then
		mkdir /etc/fiad-conf/cron/crontabs
	fi
	
	if [ ! -d /etc/fiad-conf/cron/cronstamps ]; then
		mkdir /etc/fiad-conf/cron/cronstamps
	fi

	/etc/init.d/softdogd wait
	/bin/$PROCESS_NAME $CROND_ARGS > /dev/null 2>/dev/null
        
	PID=$(pidof -o %PPID crond)
	echo "$PID" > $PIDFILE
	
	ServiceCheckRunning2

	return $?
}

do_stop ()
{
	local RESULT;

	/etc/init.d/softdogd wait
	ServiceStop
	RESULT=$?

	return $RESULT
}

do_status ()
{
	local crondSTATUS;

	ServiceStatus
	crondSTATUS=$?

	return $crondSTATUS
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	status)
		do_status
		;;
	restart)
		do_stop
		do_start
		;;
	*)
		echo "Usage: $0 {start|stop|status|restart}"
		exit 1
esac

exit $?
