#!/bin/sh
# chkconfig: 2345 24 76
### BEGIN INIT INFO
# Provides:          ntpd time
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start ntpd at boot time
# Description:       Enable service provided by ntpd.
# X-Start-Before:    
# X-Stop-After:      
# X-Timesys-Start-Number:  24
# X-Timesys-Stop-Number:  76
### END INIT INFO


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


case "$1" in
	start)

    echo -n "Starting ntpd: "

    if [ -n "$(pidof ntpd)" ]; then
      echo "ntpd already running"
      exit 1
    fi

		ntpd -g -c /etc/ntp.conf
    if [ $? -ne 0 ]; then
      echo "[FAIL]"
      exit 1
    fi
    echo "[OK]"
	;;
	stop)
    echo -n "Stopping ntpd: "
		PID=$(pidof ntpd)
		if [ -z "$PID" ]; then
			echo "ntpd not running"
			exit 1
		fi
		for pid in $PID;do kill $pid >/dev/null 2>&1;done
    echo "[OK]"
	;;
	restart)
		$0 stop
		$0 start
	;;
	*)
		echo "Usage: $0 [start|stop|restart]"
		exit 1
	;;
esac
