#!/bin/bash
#
#	/etc/rc.d/init.d/tcrond
#
# Start the tcron daemon.
#
# chkconfig: 2345 21 60
# description: tcron is a UNIX program that runs user-specified \
#              programs at periodic scheduled times; and it can set rtc
#              to power up/down your PC with ATX support.
# processname: tcrond
# config: /etc/tcrontab
# pidfile: /var/run/tcrond.pid
### BEGIN INIT INFO
# Provides: tcrond tcrontab
# Default-Start: 3 4 5
# Short-Description: Starts the at daemon
# Description: Runs commands scheduled by the at command at the time
#              specified when at was run
### END INIT INFO

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


RETVAL=0

# See how we were called.

prog="tcrond"

start() {
	gprintf "Starting %s: " "$prog"
	if [ -x /usr/local/sbin/tcrond ]; then
	  daemon /usr/local/sbin/tcrond
	else
	  daemon tcrond
	fi
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/tcrond
	return $RETVAL
}

stop() {
	gprintf "Stopping %s: " "$prog"
	killproc /usr/local/sbin/tcrond
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/tcrond
	return $RETVAL
}

status_tcron() {
	status tcrond
}

restart() {
  	stop
	start
}

reload() {
	gprintf "Reloading tcron daemon configuration: "
	killproc tcrond -HUP
	retval=$?
	echo
	return $RETVAL
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	status_tcron
	;;
  condrestart)
  	[ -f /var/lock/subsys/tcrond ] && restart || :
	;;
  *)
	gprintf "Usage: %s {start|stop|status|reload|restart|condrestart}\n" "$0"
	exit 1
esac

exit $?
