#!/bin/sh
#
-# ntp This shell script takes care of starting and stopping
+# ntpd This shell script takes care of starting and stopping
# ntp (NTP daemon).
#
# chkconfig: 2345 55 10
-# description: ntp is the NTP daemon.
+# description: ntpd is the NTP daemon.
# Source function library.
. /etc/rc.d/init.d/functions
+upstart_controlled
+
# Source networking configuration.
. /etc/sysconfig/network
# Source ntp configuration
-. /etc/sysconfig/ntp
+. /etc/sysconfig/ntpd
# Check that networking is up.
if is_yes "${NETWORKING}"; then
- if [ ! -f /var/lock/subsys/network ]; then
- # nls "ERROR: Networking is down. %s can't be run." <service>
- msg_network_down ntp
+ if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+ msg_network_down "ntpd"
exit 1
fi
else
exit 0
fi
-[ -x /usr/sbin/ntpd -a -f /etc/ntp/ntp.conf ] || exit 0
+[ -f /etc/ntp/ntp.conf ] || exit 0
-RETVAL=0
-# See how we were called.
-case "$1" in
- start)
+start() {
# Check if the service is already running?
- if [ ! -f /var/lock/subsys/ntp ]; then
- if is_yes "$SYNC_TIME"; then
- # Adjust time to make life easy for ntp
- run_cmd "Syncing time for ntp" "/usr/sbin/ntpdate $NTPDATE_OPTIONS $NTPDATE_SERVERS"
- fi
- msg_starting ntp
- daemon ntpd -c /etc/ntp/ntp.conf
+ if [ ! -f /var/lock/subsys/ntpd ]; then
+ msg_starting "ntpd"
+ daemon /usr/sbin/ntpd -c /etc/ntp/ntp.conf -p /var/run/ntpd.pid -u ntp:ntp $NTPD_OPTIONS
RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntp
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
else
- msg_already_running ntp
+ msg_already_running "ntpd"
fi
- ;;
- stop)
- if [ -f /var/lock/subsys/ntp ]; then
- msg_stopping ntp
+}
+
+stop() {
+ if [ -f /var/lock/subsys/ntpd ]; then
+ msg_stopping "ntpd"
killproc ntpd
- rm -f /var/lock/subsys/ntp
+ rm -f /var/lock/subsys/ntpd
+ else
+ msg_not_running "ntpd"
+ fi
+}
+
+condrestart() {
+ if [ -f /var/lock/subsys/ntpd ]; then
+ stop
+ start
else
- msg_not_running ntp
+ msg_not_running "ntpd"
+ RETVAL=$1
fi
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ # NB! don't remove 'condrestart': dhcpcd calls this
+ try-restart|condrestart)
+ condrestart 0
+ ;;
+ force-reload)
+ condrestart 7
;;
status)
status ntpd
exit $?
;;
- restart|force-reload)
- $0 stop
- $0 start
- exit $?
- ;;
*)
- msg_usage "$0 {start|stop|restart|force-reload|status}"
+ msg_usage "$0 {start|stop|restart|try-restart|force-reload|condrestart|status}"
exit 3
esac