#! /bin/bash
#
# chkconfig: 2345 30 70 
# description: Hypertext Time Protocol
#
# processname: htpd
# config: /etc/htpd.conf
# pidfile: /var/run/htpd.pid
#
### BEGIN INIT INFO
# Provides:             htpd
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# Description: Hypertext Time Protocol
# Short-Description: Sets time using HTTP Date header
### END INIT INFO

# Source function library.
[ -f /etc/init.d/functions ] && . /etc/init.d/functions

RETVAL=0

# See how we were called.
prog="htpd"

prefix="/usr"
exec_prefix="${prefix}"
bindir="${exec_prefix}/bin"
mandir="${prefix}/share/man"
sysconfdir="/etc"
datadir="${prefix}/share"
localstatedir="/var"
skipstartfile="${sysconfdir}/htp-disable"

start() {
	if [ -f "${skipstartfile}" ]; then
		echo "HTP is disabled, skipping."
		return 1
	fi
	echo -n $"Starting $prog: "
	daemon "${bindir}/htpd"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/run/htpd.pid
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	"${bindir}/htpd" -k
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/run/htpd.pid
	return $RETVAL
}	

restart() {
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	force-start)
		rm -f "${skipstartfile}"
		start
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|force-start}"
		exit 1
esac

exit $?
