#!/bin/sh
# Start/stop the cron daemon.

DESC="cron daemon"
NAME=crond
DAEMON=/usr/sbin/crond
SCRIPTNAME=/etc/init.d/S99cron
CRONTAB_PATH=/var/spool/cron/crontabs
CRON_ENABLED="/opt/userdata/.cron-enabled"
ISC_TEMPLATE_DIR="/opt/gira/etc/iscapphost/"

test -f $DAEMON || exit 0

. /opt/gira/share/devicestack/ipmodule-vars

start() {
	logger "[S99cron] Starting periodic command scheduler"
	if ! [ -d "$CRONTAB_PATH" ]
	then
		mkdir -p "$CRONTAB_PATH"
	fi
	crontab "$ISC_TEMPLATE_DIR"/isc_crontab_logrotate
	$DAEMON
}

stop() {
	logger "[S99cron] Stopping periodic command scheduler"
	killall "$NAME"
}

restart() {
logger "[S99cron] Restarting periodic command scheduler"
	$0 stop
	$0 start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	start-once)
		start
		;;
	*)
		echo "Usage: $SCRIPTNAME {start|stop|restart}"
		exit 2
		;;
esac

exit $?
