This repository was archived by the owner on Mar 22, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtimeserverd
More file actions
63 lines (55 loc) · 1.71 KB
/
timeserverd
File metadata and controls
63 lines (55 loc) · 1.71 KB
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
#!/bin/sh
#shellcheck disable=SC2039
trap '' SIGHUP
# Wait for NTP before starting
logger -st timeserverd "Waiting for NTP to sync before starting..."
ntpwaitcount=0
while [ "$(nvram get ntp_ready)" -eq 0 ] && [ "$ntpwaitcount" -lt 600 ]; do
ntpwaitcount="$((ntpwaitcount + 30))"
logger -st timeserverd "Waiting for NTP to sync..."
sleep 30
done
if [ "$ntpwaitcount" -ge 600 ]; then
logger -st timeserverd "NTP failed to sync after 10 minutes - please check immediately!"
exit 1
fi
if [ -f "/opt/share/ntpmerlin.d/config" ]; then
SCRIPT_STORAGE_DIR="/opt/share/ntpmerlin.d"
else
SCRIPT_STORAGE_DIR="/jffs/addons/ntpmerlin.d"
fi
if [ "$1" = "S77ntpd" ]; then
ntpd -c "$SCRIPT_STORAGE_DIR/ntp.conf" -g > /dev/null 2>&1 &
while true; do
sleep 5
if [ "$(pidof ntpd | wc -w)" -lt 1 ]; then
logger -t timeserverd "ntpd dead, restarting..."
killall -q ntpd
sleep 5
ntpd -c "$SCRIPT_STORAGE_DIR/ntp.conf" -g > /dev/null 2>&1 &
logger -t timeserverd "ntpd restarted"
fi
done
elif [ "$1" = "S77chronyd" ]; then
if [ -f /opt/etc/init.d/S06chronyd ]; then
/opt/etc/init.d/S06chronyd stop
rm -f /opt/etc/init.d/S06chronyd
fi
mkdir -p /opt/var/lib/chrony
mkdir -p /opt/var/run/chrony
chown -R nobody:nobody /opt/var/lib/chrony
chown -R nobody:nobody /opt/var/run/chrony
chmod -R 770 /opt/var/lib/chrony
chmod -R 770 /opt/var/run/chrony
chronyd -r -u nobody -f "$SCRIPT_STORAGE_DIR/chrony.conf" > /dev/null 2>&1 &
while true; do
sleep 5
if [ "$(pidof chronyd | wc -w)" -lt 1 ]; then
logger -t timeserverd "chronyd dead, restarting..."
killall -q chronyd
sleep 5
chronyd -r -u nobody -f "$SCRIPT_STORAGE_DIR/chrony.conf" > /dev/null 2>&1 &
logger -t timeserverd "chronyd restarted"
fi
done
fi