-
Notifications
You must be signed in to change notification settings - Fork 1
/
ntp-backup.init
executable file
·58 lines (44 loc) · 1.43 KB
/
ntp-backup.init
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: ntp-backup
# Required-Start:
# Required-Stop: umountroot
# Should-Stop:
# X-Start-Before: checkroot
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: Save the current clock & ntp drift on read-only filesystem
# Description:
### END INIT INFO
set -e
case "${1:-}" in
stop|reload|restart|force-reload)
# When restarted by the hourly cron ( /etc/corn.hourly/ntp-backup )
# or during shutdown save the current time and ntp drift value.
echo "Running ntp-backup to save current clock data."
dfile=/var/lib/ntp/ntp.drift
# Get current drift value from ntpd (will be if ntpd is not running)
dval=`ntpdc -c kerninfo | grep "pll frequency" | awk -F' ' '{print $3}'`
# remount as writable
mount -t ext4 -o remount,rw /dev/mmcblk0p2 /
# if drift value is not empty then save to file
if [ $dval ] ; then
echo $dval > $dfile
fi
# run fake-hwclock's save command if it's installed and accessible
if (command -v fake-hwclock >/dev/null 2>&1) ; then
fake-hwclock save
fi
# remount read only
mount -t ext4 -o remount,ro /dev/mmcblk0p2 /
;;
start)
# Do nothing at start up. fake-hwclock will load the last stored
# time and date to the system clock if it is installed & active.
echo "Starting ntp-backup."
;;
*)
echo "Usage: ${0:-} {start|stop|status|restart|reload|force-reload}" >&2
exit 1
;;
esac