aboutsummaryrefslogtreecommitdiffstats
path: root/examples/source/init-clock/up
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-05-05 06:29:50 +0000
committerLaurent Bercot <ska@appnovation.com>2025-05-05 06:29:50 +0000
commite18d6958b2470a2e68cc637945ccf3a1dae5c0a2 (patch)
tree90e065e7b7422c2f2dbd5d924dfcd14a2866de39 /examples/source/init-clock/up
parent09ccd3128f2296d3a0cd1602e64caf06cf22c64f (diff)
downloads6-rc-e18d6958b2470a2e68cc637945ccf3a1dae5c0a2.tar.gz
Update examples
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'examples/source/init-clock/up')
-rw-r--r--examples/source/init-clock/up42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/source/init-clock/up b/examples/source/init-clock/up
new file mode 100644
index 0000000..a548ab5
--- /dev/null
+++ b/examples/source/init-clock/up
@@ -0,0 +1,42 @@
+#!/command/execlineb -P
+
+# Get the IP addresses for some NTP servers.
+# Limit the DNS queries to 30 seconds: if the DNS is slower than
+# that, chances are the server isn't good for us anyway.
+# All the queries are parallelized, so it's fast.
+
+pipeline
+{
+ s6-setuidgid nobody
+ forx -p I { 0 1 2 }
+ importas -u I I
+ redirfd -w 2 /dev/null
+ s6-dnsip4 -t 30000 -- ${I}.fr.pool.ntp.org
+}
+
+
+# Ask for a NTP exchange with the servers we get. Accept anything.
+# If the exchange can't be completed in 5 seconds, kill it.
+# All the queries are parallelized.
+
+pipeline
+{
+ s6-setuidgid ntp
+ forstdin -p -d"\n" NTPSERVERIP
+ importas -u NTPSERVERIP NTPSERVERIP
+ redirfd -w 2 /dev/null
+ s6-sntpclock -f -T 5000 ${NTPSERVERIP}
+}
+
+
+# Take the first answer we get.
+
+pipeline
+{
+ s6-setuidgid nobody
+ s6-head -Sc 12
+}
+
+# Update the system clock. Accept anything.
+
+s6-clockadd -f