summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-09-29 15:57:03 +0200
committerSimon Rettberg2023-09-29 15:57:29 +0200
commit9dfbd328d5440054be6e5d6e1138c86c076a51e8 (patch)
tree848f2756417947381ef70861477d02164eccc78d
parentThis should never have worked (diff)
downloadmltk-9dfbd328d5440054be6e5d6e1138c86c076a51e8.tar.gz
mltk-9dfbd328d5440054be6e5d6e1138c86c076a51e8.tar.xz
mltk-9dfbd328d5440054be6e5d6e1138c86c076a51e8.zip
[bwlp-stage4-tweaks] Add daily ntp sync script
Closes #3947
-rw-r--r--core/modules/bwlp-stage4-tweaks/data/etc/cron.d/slx-timesync7
-rwxr-xr-xcore/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/cron-ntp40
2 files changed, 47 insertions, 0 deletions
diff --git a/core/modules/bwlp-stage4-tweaks/data/etc/cron.d/slx-timesync b/core/modules/bwlp-stage4-tweaks/data/etc/cron.d/slx-timesync
new file mode 100644
index 00000000..6acc48d5
--- /dev/null
+++ b/core/modules/bwlp-stage4-tweaks/data/etc/cron.d/slx-timesync
@@ -0,0 +1,7 @@
+# Sync time once a day; script includes a random startup delay
+# Avoid clients running for weeks to run out of sync with the server too much
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/openslx/sbin:/opt/openslx/bin
+
+19 1 * * * root /opt/openslx/scripts/cron-ntp
diff --git a/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/cron-ntp b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/cron-ntp
new file mode 100755
index 00000000..64dc2fda
--- /dev/null
+++ b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/cron-ntp
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+. /opt/openslx/config
+
+[ -z "$SLX_NTP_SERVER" ] && exit 0
+
+declare -a cmd
+if command -v ntpdate &> /dev/null; then
+ cmd=( ntpdate )
+ ntpdate --help 2>&1 | grep -q '\s-B\s' && cmd+=( -B )
+ ntpdate --help 2>&1 | grep -q '\s-t\s' && cmd+=( -t 5 )
+elif command -v ntpdig &> /dev/null; then
+ cmd=( ntpdig )
+ ntpdig --help 2>&1 | grep -q '\s-s\s' && cmd+=( -s )
+ ntpdig --help 2>&1 | grep -q '\s-t\s' && cmd+=( -t 5 )
+ ntpdig --help 2>&1 | grep -q '\s-p\s' && cmd+=( -p 2 )
+elif busybox ntpd --help &> /dev/null; then
+ command -v timeout &> /dev/null && cmd=( timeout 5 )
+ cmd+=( busybox ntpd -q -n -p )
+fi
+
+# Random delay if not run on terminal
+[ -t 0 ] || sleep $(( RANDOM % 60 ))
+
+for srv in $SLX_NTP_SERVER; do
+ "${cmd[@]}" "$srv" || continue
+ # Success
+ echo "Time updated from NTP"
+ command -v hwclock &> /dev/null || exit 0
+ sleep 1
+ if [ "$SLX_BIOS_CLOCK" = "local" ]; then
+ hwclock -l -w || echo "... but could not set BIOS clock to localtime"
+ elif [ "$SLX_BIOS_CLOCK" = "utc" ]; then
+ hwclock -u -w || echo "... but could not set BIOS clock to UTC"
+ fi
+ exit 0
+done
+
+echo 'No NTP server reachable!'
+exit 1