#!/bin/sh
#
# htpdate		This shell script synchronizes time with htpdate (HTP client)
#
# chkconfig:	2345 55 10
# description:	htpdate is the HTP client.

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

# Source networking configuration.
. /etc/sysconfig/network

# Source ntp configuration
. /etc/sysconfig/htpdate

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down htpdate
		exit 1
	fi
else
	exit 0
fi

[ -x /usr/sbin/htpdate ] || exit 0

RETVAL=0
# See how we were called.
case "$1" in
cronsettime)
	is_yes "$HTPDATE_CRON" && /usr/sbin/htpdate -l $HTPDATE_OPTIONS $HTPDATE_SERVERS > /dev/null 2>&1
	RETVAL=$?
	;;
start)
	show "Syncing time with htpdate (backgrounding)"
	daemon --fork /usr/sbin/htpdate -l $HTPDATE_OPTIONS $HTPDATE_SERVERS
	RETVAL=$?
	;;
stop)
	exit $RETVAL
	;;
restart|force-reload)
	$0 start
	exit $?
	;;
*)
	msg_usage "$0 {start|restart|force-reload}"
	exit 3
esac

exit $RETVAL
