#!/bin/bash
# . /etc/rc.conf
# . /etc/rc.d/functions

PID=$(pidof -o %PPID /usr/sbin/crond)
case $1 in
start)
	echo "Starting Cron Daemon"

	# defaults to using syslog, and sendmail-ing cron output to local user
	# to mail output to remote address instead, add "-m user@host"
	if [[ -z $PID ]] && /usr/sbin/crond -S -l info; then
		PID=$(pidof -o %PPID /usr/sbin/crond)
		echo "$PID" > /var/run/crond.pid
		echo "crond started"
	else
	        echo "crond failed to start"
		exit 1
	fi
	;;

stop)
	echo "Stopping Cron Daemon"
	if [[ ! -z $PID ]]  && kill "$PID" &>/dev/null; then
		rm -f /var/run/crond.pid
		echo "crond stopped"
	else
		echo "crond failed to stop"
		exit 1
	fi
	;;

restart)
	$0 stop
	$0 start
	;;

*)
	echo "Usage: $0 {start|stop|restart}" >&2
	exit 1

esac

