summaryrefslogtreecommitdiff
path: root/recipes-support/ntp/files/ntp.init.patch
blob: b60d8ca63dbc2d6f4a46346aee8800e04f917987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
diff -Naur old/ntpd new/ntpd
--- old/ntpd	2017-02-02 18:00:38.415645575 -0600
+++ new/ntpd	2017-02-02 18:14:50.986092592 -0600
@@ -1,6 +1,8 @@
-#! /bin/sh
+#! /bin/bash
 #
+. /etc/default/ntpd
 PATH=/sbin:/bin:/usr/bin:/usr/sbin
+GNSSRST=/sys/devices/platform/mts-io/gnss-reset
 
 # ntpd	init.d script for ntpdc from ntp.isc.org
 test -x /usr/sbin/ntpd -a -r /etc/ntp.conf || exit 0
@@ -18,13 +20,32 @@
 	}
 }
 startdaemon(){
-	# The -g option allows ntpd to step the time to correct it just
-	# once.  The daemon will exit if the clock drifts too much after
-	# this.  If ntpd seems to disappear after a while assume TICKADJ
-	# above is set to a totally incorrect value.
-	echo -n "Starting ntpd: "
-	start-stop-daemon --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@"
-	echo "done"
+	/usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd --test -- -u ntp:ntp -p /var/run/ntp.pid "$@" \
+	  || return 1
+	if ((GPSD_REQUIRED == 1)) && [[ -L /dev/gps0 ]] && [[ -f "${GNSSRST}" ]]; then
+		. /etc/default/gpsd
+		# Could not get ntpd -gq to work with the GPS. 
+		# So read the GPS time directly and set the system
+		# clock.
+		if ((SET_SYSTEM_CLOCK == 1)) && /usr/sbin/gpsd_ubx_settime ; then
+		   # System time set by the GPS.
+		   /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@"
+		else
+		  # Need a GPS fix before startint ntp.
+		  /usr/sbin/start-stop-daemon -b -n z1e9d3qb -N -20 --start -x /bin/bash -- -c "sleep $GPSD_WAIT_TIME;/etc/init.d/ntpd start"
+		fi
+	else
+	  if ((SET_SYSTEM_CLOCK == 1)) ; then
+	    ntpd -gq
+	    shift
+	  fi
+
+	  # The -g option allows ntpd to step the time to correct it just
+	  # once.  The daemon will exit if the clock drifts too much after
+	  # this.  If ntpd seems to disappear after a while assume TICKADJ
+	  # above is set to a totally incorrect value.
+	  /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@"
+	fi
 }
 stopdaemon(){
 	echo -n "Stopping ntpd: "
@@ -34,24 +55,37 @@
 
 case "$1" in
   start)
-  	settick
-	startdaemon -g
+	if ! [[ $ENABLED =~ ^[yY][eE][sS]$ ]] ; then
+		exit 0
+	fi
+	if [[ -n "$CONFIGFILE" ]] ; then
+		$CONFIGOPT="-c ${CONFIGFILE}"
+		STATSDIR=$(grep "^statsdir" ${CONFIGFILE} | sed -r 's/[^[:SPACE:]]+[[:SPACE:]]//')
+		if ! [[ -d ${STATSDIR} ]] ; then
+			mkdir -m 0755 -p ${STATSDIR}
+		fi
+		if [[ -d ${STATSDIR} ]] ; then
+			chown ntp:ntp ${STATSDIR}
+		fi
+	fi
+	settick
+	startdaemon -g $CONFIGOPT
 	;;
   stop)
-  	stopdaemon
+	stopdaemon
 	;;
   force-reload)
-  	stopdaemon
-  	settick
+	stopdaemon
+	settick
 	startdaemon -g
 	;;
   restart)
-  	# Don't reset the tick here
+	# Don't reset the tick here
 	stopdaemon
 	startdaemon -g
 	;;
   reload)
-  	# Must do this by hand, but don't do -g
+	# Must do this by hand, but don't do -g
 	stopdaemon
 	startdaemon
 	;;
diff -Naur old/ntpd.orig new/ntpd.orig
--- old/ntpd.orig	2017-02-02 17:58:25.316767036 -0600
+++ new/ntpd.orig	1969-12-31 18:00:00.000000000 -0600
@@ -1,88 +0,0 @@
-#! /bin/bash
-#
-. /etc/default/ntpd
-PATH=/sbin:/bin:/usr/bin:/usr/sbin
-GNSSRST=/sys/devices/platform/mts-io/gnss-reset
-
-# ntpd	init.d script for ntpdc from ntp.isc.org
-test -x /usr/sbin/ntpd -a -r /etc/ntp.conf || exit 0
-# rcS contains TICKADJ
-test -r /etc/default/rcS && . /etc/default/rcS
-
-# Functions to do individual actions
-settick(){
-  	# If TICKADJ is set we *must* adjust it before we start, because the
-	# driftfile relies on the correct setting
-	test -n "$TICKADJ" -a -x /usr/sbin/tickadj && {
-		echo -n "Setting tick to $TICKADJ: "
-		/usr/sbin/tickadj "$TICKADJ"
-		echo "done"
-	}
-}
-startdaemon(){
-	/usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd --test -- -u ntp:ntp -p /var/run/ntp.pid "$@" \
-	  || return 1
-	if ((GPSD_REQUIRED == 1)) && [[ -L /dev/gps0 ]] && [[ -f "${GNSSRST}" ]]; then
-		. /etc/default/gpsd
-		# Could not get ntpd -gq to work with the GPS. 
-		# So read the GPS time directly and set the system
-		# clock.
-		if ((SET_SYSTEM_CLOCK == 1)) && /usr/sbin/gpsd_ubx_settime ; then
-		   # System time set by the GPS.
-		   /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@"
-		else
-		  # Need a GPS fix before startint ntp.
-		  /usr/sbin/start-stop-daemon -b -n z1e9d3qb -N -20 --start -x /bin/bash -- -c "sleep $GPSD_WAIT_TIME;/etc/init.d/ntpd start"
-		fi
-	else
-	  if ((SET_SYSTEM_CLOCK == 1)) ; then
-	    ntpd -gq
-	    shift
-	  fi
-
-	  # The -g option allows ntpd to step the time to correct it just
-	  # once.  The daemon will exit if the clock drifts too much after
-	  # this.  If ntpd seems to disappear after a while assume TICKADJ
-	  # above is set to a totally incorrect value.
-	  /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@"
-	fi
-}
-stopdaemon(){
-	echo -n "Stopping ntpd: "
-	start-stop-daemon --stop -p /var/run/ntp.pid
-	echo "done"
-}
-
-case "$1" in
-  start)
-	if ! [[ $ENABLED =~ ^[yY][eE][sS]$ ]] ; then
-		exit 0
-	fi
-	settick
-	startdaemon -g
-	;;
-  stop)
-	stopdaemon
-	;;
-  force-reload)
-	stopdaemon
-	settick
-	startdaemon -g
-	;;
-  restart)
-	# Don't reset the tick here
-	stopdaemon
-	startdaemon -g
-	;;
-  reload)
-	# Must do this by hand, but don't do -g
-	stopdaemon
-	startdaemon
-	;;
-  *)
-	echo "Usage: ntpd { start | stop | restart | reload }" >&2
-	exit 1
-	;;
-esac
-
-exit 0