summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-09-29 16:37:15 +0200
committerSimon Rettberg2023-09-29 16:37:15 +0200
commit134bf3e3bdad7927de9c3ef7b57f9faf358cdffa (patch)
tree4e57eb21018627e3aec030af3bb81432205d3a16
parent[SSPS] timesync: Use more privacy-friendly URLs (diff)
downloadsetup-scripts-134bf3e3bdad7927de9c3ef7b57f9faf358cdffa.tar.gz
setup-scripts-134bf3e3bdad7927de9c3ef7b57f9faf358cdffa.tar.xz
setup-scripts-134bf3e3bdad7927de9c3ef7b57f9faf358cdffa.zip
[SSPS] timesync: Add cronjob to sync once a day
-rw-r--r--satellit_installer/static_files/timesync/etc/cron.d/slx-timesync8
-rw-r--r--satellit_installer/static_files/timesync/etc/systemd/system/redneck-timesync.service2
-rwxr-xr-xsatellit_installer/static_files/timesync/usr/local/sbin/redneck-timesync.sh24
3 files changed, 30 insertions, 4 deletions
diff --git a/satellit_installer/static_files/timesync/etc/cron.d/slx-timesync b/satellit_installer/static_files/timesync/etc/cron.d/slx-timesync
new file mode 100644
index 0000000..e0a7c22
--- /dev/null
+++ b/satellit_installer/static_files/timesync/etc/cron.d/slx-timesync
@@ -0,0 +1,8 @@
+# Run our http-based timesync once a day
+# This script will check whether ntpd or systemd-timesyncd is
+# running, in which case it does nothing.
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+33 2 * * * root /usr/local/sbin/redneck-timesync.sh -s
diff --git a/satellit_installer/static_files/timesync/etc/systemd/system/redneck-timesync.service b/satellit_installer/static_files/timesync/etc/systemd/system/redneck-timesync.service
index e019a92..0d67124 100644
--- a/satellit_installer/static_files/timesync/etc/systemd/system/redneck-timesync.service
+++ b/satellit_installer/static_files/timesync/etc/systemd/system/redneck-timesync.service
@@ -6,7 +6,7 @@ After=network.target network-online.target
[Service]
Type=oneshot
RemainAfterExit=no
-ExecStart=/usr/local/sbin/redneck-timesync.sh -s
+ExecStart=/usr/local/sbin/redneck-timesync.sh -s -b
[Install]
WantedBy=network-online.target
diff --git a/satellit_installer/static_files/timesync/usr/local/sbin/redneck-timesync.sh b/satellit_installer/static_files/timesync/usr/local/sbin/redneck-timesync.sh
index 2fbed8a..7dc538c 100755
--- a/satellit_installer/static_files/timesync/usr/local/sbin/redneck-timesync.sh
+++ b/satellit_installer/static_files/timesync/usr/local/sbin/redneck-timesync.sh
@@ -6,8 +6,26 @@ if [ "$USR" != 0 ]; then
exit 1
fi
-DRYRUN=false
-[ "x$1" = "x-s" ] || DRYRUN=true
+DRYRUN=true
+BOOTUP=false
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ -s)
+ DRYRUN=false
+ ;;
+ -b)
+ BOOTUP=true
+ esac
+done
+
+if ! $BOOTUP; then
+ # Not bootup mode, ntpd present, ntpq yields no error:
+ # Assume ntpd is up and running, so don't do anything
+ command -v ntpd > /dev/null && ntpq -p > /dev/null 2>&1 && exit 0
+ # Same for systemd timesync
+ systemctl -q is-active systemd-timesyncd && exit 0
+fi
+
# Check if clock is set properly by probing a bunch of web servers for
# their current time. Then -- after applying some sanity checks -- pick
@@ -35,7 +53,7 @@ F=$(mktemp)
NOW=$(date +%s)
ECODE=0
-/usr/local/sbin/slx-wait-online
+$BOOTUP && /usr/local/sbin/slx-wait-online
# Request all at once, HEAD only, 2 sec timeout
for url in $URLS; do