diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-05-05 06:29:50 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-05-05 06:29:50 +0000 |
| commit | e18d6958b2470a2e68cc637945ccf3a1dae5c0a2 (patch) | |
| tree | 90e065e7b7422c2f2dbd5d924dfcd14a2866de39 /examples/source/ntpclient | |
| parent | 09ccd3128f2296d3a0cd1602e64caf06cf22c64f (diff) | |
| download | s6-rc-e18d6958b2470a2e68cc637945ccf3a1dae5c0a2.tar.gz | |
Update examples
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'examples/source/ntpclient')
| -rw-r--r-- | examples/source/ntpclient/dependencies | 2 | ||||
| -rw-r--r-- | examples/source/ntpclient/notification-fd | 1 | ||||
| -rwxr-xr-x | examples/source/ntpclient/run | 60 |
3 files changed, 50 insertions, 13 deletions
diff --git a/examples/source/ntpclient/dependencies b/examples/source/ntpclient/dependencies index 8b11827..be178b3 100644 --- a/examples/source/ntpclient/dependencies +++ b/examples/source/ntpclient/dependencies @@ -1,2 +1,2 @@ -wan dns-cache +init-clock diff --git a/examples/source/ntpclient/notification-fd b/examples/source/ntpclient/notification-fd new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/examples/source/ntpclient/notification-fd @@ -0,0 +1 @@ +3 diff --git a/examples/source/ntpclient/run b/examples/source/ntpclient/run index 238580c..8ded1c1 100755 --- a/examples/source/ntpclient/run +++ b/examples/source/ntpclient/run @@ -1,20 +1,56 @@ #!/command/execlineb -P fdmove -c 2 1 -if + + +# 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 + s6-dnsip4 -t 30000 -- ${I}.fr.pool.ntp.org +} +importas -u p1 ! + + +# Ask for a NTP exchange with the servers we get. +# If the exchange can't be completed in 5 seconds, kill it. +# All the queries are parallelized. + +pipeline { - pipeline - { - s6-setuidgid ntp - backtick -n NTPSERVERIP - { - pipeline { s6-dnsip4 -t 16000 0.fr.pool.ntp.org } - s6-head -n 1 - } + s6-setuidgid ntp + forstdin -p -d"\n" NTPSERVERIP importas -u NTPSERVERIP NTPSERVERIP - s6-sntpclock -v 2 $NTPSERVERIP - } - s6-clockadd -e 120000 + s6-sntpclock -T 5000 ${NTPSERVERIP} } +importas -u p2 ! + + +# Take the first answer we get + +pipeline +{ + s6-setuidgid nobody + s6-head -Sc 12 +} +importas -u p3 ! + + +# Update the system clock. Accept 10 minutes of discrepancy. + +if { s6-clockadd -e 600000 } + + +# Success. Send a readiness notification, reap zombies, +# and sleep for 4 hours. + s6-setuidgid nobody +if { fdmove 1 3 s6-echo } +wait { ${p1} ${p2} ${p3} } s6-sleep 14400 |
