diff options
author | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
---|---|---|
committer | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
commit | 1130873aa55c9b0a7e5af48edc44bd6c6fd1f888 (patch) | |
tree | 0fcfa186cd631d8d36611b3d4bc509fd38841d51 /modules.d/slx-clock | |
parent | Merge branch 'centos8' into downloader (diff) | |
download | systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.gz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.xz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.zip |
restructure repo
* remove packager
* move everything from builder/* back to root
Diffstat (limited to 'modules.d/slx-clock')
-rwxr-xr-x | modules.d/slx-clock/module-setup.sh | 20 | ||||
-rwxr-xr-x | modules.d/slx-clock/scripts/ntp-sync.sh | 55 |
2 files changed, 75 insertions, 0 deletions
diff --git a/modules.d/slx-clock/module-setup.sh b/modules.d/slx-clock/module-setup.sh new file mode 100755 index 00000000..0c21b032 --- /dev/null +++ b/modules.d/slx-clock/module-setup.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +check() { + if ! hash ntpdate; then + derror "Missing 'ntpdate'. Please install it." + return 1 + fi + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + echo dnbd3-rootfs busybox +} +install() { + # wait til we have the openslx config for ntp servers + # which happens in pre-mount/10 + inst_multiple ntpdate /etc/services /usr/share/zoneinfo/Europe/Berlin + inst /usr/share/zoneinfo/Europe/Berlin /etc/localtime + inst_hook pre-mount 15 "$moddir/scripts/ntp-sync.sh" +} diff --git a/modules.d/slx-clock/scripts/ntp-sync.sh b/modules.d/slx-clock/scripts/ntp-sync.sh new file mode 100755 index 00000000..887d5b13 --- /dev/null +++ b/modules.d/slx-clock/scripts/ntp-sync.sh @@ -0,0 +1,55 @@ +#!/bin/ash +# Sync time via network + +. /etc/openslx + +ntp_sync() { + # Try to merge with servers from DHCP. Prefer DHCP, skip duplicates + for SERVER in $SLX_NTP_SERVER; do + if ! echo "$SLX_DHCP_NTP" | grep -wq "$SERVER"; then + SLX_DHCP_NTP="$SLX_DHCP_NTP $SERVER" + fi + done + local SUCCESS= + for SERVER in $SLX_DHCP_NTP; do + if ntpdate -u -p 2 "$SERVER"; then + echo "Successfully queried $SERVER for time." + if [ "x$SLX_BIOS_CLOCK" = "xlocal" ]; then + usleep 100000 + hwclock -l -w || echo "... but could not set BIOS clock to localtime" + elif [ "x$SLX_BIOS_CLOCK" = "xutc" ]; then + usleep 100000 + hwclock -u -w || echo "... but could not set BIOS clock to UTC" + fi + SUCCESS=1 + break + fi + echo "Error querying $SERVER for current time." + done + if [ -z "$SUCCESS" ]; then + echo "No NTP server reachable" + # See if we have a timestamp in our server-config - should only be a few seconds off by now + if [ -n "$SLX_NOW" ] && [ "$SLX_NOW" -gt 1234567890 ]; then + TTS="$SLX_NOW" + if [ -n "$CONFIG_DOWNLOAD_TIME" ]; then + NOW_TIME=$(sed -r 's/^([0-9]+)\.([0-9]+).*$/\1\2/' /proc/uptime) + if [ "$CONFIG_DOWNLOAD_TIME" -gt 0 ] && [ "$NOW_TIME" -gt 0 ]; then + TTS=$(( TTS + ( NOW_TIME - CONFIG_DOWNLOAD_TIME ) / 100 )) + fi + fi + echo "Setting time to SLX_NOW ($SLX_NOW, corrected $TTS)" + date -s "@$TTS" + else + echo "No fallback option for timesync available, relying on correct RTC setup" + if [ "x$SLX_BIOS_CLOCK" = "xlocal" ]; then + # Linux defaults to RTC = UTC, so read again in this case + hwclock -l -s + fi + fi + fi +} + +ntp_sync & + +true + |