From 134bf3e3bdad7927de9c3ef7b57f9faf358cdffa Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 29 Sep 2023 16:37:15 +0200 Subject: [SSPS] timesync: Add cronjob to sync once a day --- .../static_files/timesync/etc/cron.d/slx-timesync | 8 ++++++++ .../etc/systemd/system/redneck-timesync.service | 2 +- .../timesync/usr/local/sbin/redneck-timesync.sh | 24 +++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 satellit_installer/static_files/timesync/etc/cron.d/slx-timesync (limited to 'satellit_installer') 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 -- cgit v1.2.3-55-g7522