blob: d1b9c4907623f08115c20fd67d8b3017fea42b47 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001#! /bin/sh
2
3### BEGIN INIT INFO
4# Provides: ntp
5# Required-Start: $network $remote_fs $syslog
6# Required-Stop: $network $remote_fs $syslog
7# Default-Start: 2 3 4 5
8# Default-Stop:
9# Short-Description: Start NTP daemon
10### END INIT INFO
11
12PATH=/sbin:/bin:/usr/bin:/usr/sbin
13
14DAEMON=/usr/sbin/ntpd
15PIDFILE=/var/run/ntpd.pid
16
17# ntpd init.d script for ntpdc from ntp.isc.org
18test -x $DAEMON -a -r /etc/ntp.conf || exit 0
19
20# rcS contains TICKADJ
21test -r /etc/default/rcS && . /etc/default/rcS
22
23# Source function library.
24. /etc/init.d/functions
25
26# Functions to do individual actions
27settick(){
28 # If TICKADJ is set we *must* adjust it before we start, because the
29 # driftfile relies on the correct setting
30 test -n "$TICKADJ" -a -x /usr/sbin/tickadj && {
31 echo -n "Setting tick to $TICKADJ: "
32 /usr/sbin/tickadj "$TICKADJ"
33 echo "done"
34 }
35}
36startdaemon(){
37 # The -g option allows ntpd to step the time to correct it just
38 # once. The daemon will exit if the clock drifts too much after
39 # this. If ntpd seems to disappear after a while assume TICKADJ
40 # above is set to a totally incorrect value.
41 echo -n "Starting ntpd: "
42 start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -u ntp:ntp -p $PIDFILE "$@"
43 echo "done"
44}
45stopdaemon(){
46 echo -n "Stopping ntpd: "
47 start-stop-daemon --stop --quiet --oknodo -p $PIDFILE
48 echo "done"
49}
50
51case "$1" in
52 start)
53 settick
54 startdaemon -g
55 ;;
56 stop)
57 stopdaemon
58 ;;
59 force-reload)
60 stopdaemon
61 settick
62 startdaemon -g
63 ;;
64 restart)
65 # Don't reset the tick here
66 stopdaemon
67 startdaemon -g
68 ;;
69 reload)
70 # Must do this by hand, but don't do -g
71 stopdaemon
72 startdaemon
73 ;;
74 status)
75 status /usr/sbin/ntpd;
76 exit $?
77 ;;
78 *)
79 echo "Usage: ntpd { start | stop | status | restart | reload }" >&2
80 exit 1
81 ;;
82esac
83
84exit 0