#!/sbin/sh
#
# @(#) $Revision: 78.1 $
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#

#
# Start cron
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "ERROR CODE $x"
		rval=1
	fi
}

case $1 in
start_msg)
	echo "Start clock daemon"
	;;

stop_msg)
	echo "Stop clock daemon"
	;;

'start')
	if [ -f /etc/rc.config.d/cron ] ; then
		. /etc/rc.config.d/cron
	else
		echo "ERROR: /etc/rc.config.d/cron defaults file MISSING"
	fi
	
	if [ "$CRON" -eq 1 -a -x /usr/sbin/cron ]; then
		if [ -f /var/adm/cron/log ]; then
			mv /var/adm/cron/log /var/adm/cron/OLDlog
		fi
		/usr/sbin/cron && echo cron started
		set_return
	else
		rval=2
	fi

	;;

'stop')
	#
	# Determine PID of process(es) to stop
	#
	pid=`ps -el | awk '( ($NF ~ /cron/) && ($4 != mypid) && ($5 != mypid)  ){ print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "cron stopped"
		else
			set_return
			echo "Unable to stop cron"
		fi
	fi
	;;

*)
	echo "usage: $0 {start|stop}"
	;;
esac

exit $rval
