aboutsummaryrefslogtreecommitdiffstats
path: root/layout/rootfs/etc/s6-rc/source-base/init-clock
diff options
context:
space:
mode:
Diffstat (limited to 'layout/rootfs/etc/s6-rc/source-base/init-clock')
-rw-r--r--layout/rootfs/etc/s6-rc/source-base/init-clock/dependencies2
-rw-r--r--layout/rootfs/etc/s6-rc/source-base/init-clock/down1
-rw-r--r--layout/rootfs/etc/s6-rc/source-base/init-clock/type1
-rw-r--r--layout/rootfs/etc/s6-rc/source-base/init-clock/up71
4 files changed, 75 insertions, 0 deletions
diff --git a/layout/rootfs/etc/s6-rc/source-base/init-clock/dependencies b/layout/rootfs/etc/s6-rc/source-base/init-clock/dependencies
new file mode 100644
index 0000000..7988b5d
--- /dev/null
+++ b/layout/rootfs/etc/s6-rc/source-base/init-clock/dependencies
@@ -0,0 +1,2 @@
+activate-eth0
+dnscache
diff --git a/layout/rootfs/etc/s6-rc/source-base/init-clock/down b/layout/rootfs/etc/s6-rc/source-base/init-clock/down
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/layout/rootfs/etc/s6-rc/source-base/init-clock/down
@@ -0,0 +1 @@
+
diff --git a/layout/rootfs/etc/s6-rc/source-base/init-clock/type b/layout/rootfs/etc/s6-rc/source-base/init-clock/type
new file mode 100644
index 0000000..bdd22a1
--- /dev/null
+++ b/layout/rootfs/etc/s6-rc/source-base/init-clock/type
@@ -0,0 +1 @@
+oneshot
diff --git a/layout/rootfs/etc/s6-rc/source-base/init-clock/up b/layout/rootfs/etc/s6-rc/source-base/init-clock/up
new file mode 100644
index 0000000..43e0c65
--- /dev/null
+++ b/layout/rootfs/etc/s6-rc/source-base/init-clock/up
@@ -0,0 +1,71 @@
+#!/command/execlineb -P
+
+# Get the local country code as well as a few other codes
+# for countries all around the world.
+
+pipeline
+{
+ s6-setuidgid nobody
+ foreground
+ {
+ s6-envdir /etc/s6-linux-init/env-stage2
+ import -u COUNTRY_CODE
+ s6-echo ${COUNTRY_CODE}
+ }
+ forx CODE { uk de ru cn kr jp us ca br au il za }
+ import -u CODE
+ s6-echo ${CODE}
+}
+
+
+# Suppress duplicates (e.g. if the local country code is in the list).
+
+pipeline
+{
+ s6-setuidgid nobody
+ s6-sort -u
+}
+
+
+# Get the IP addresses for some NTP servers in those countries.
+# 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
+ forstdin -p -d"\n" CODE
+ import -u CODE
+ forx -p I { 0 1 }
+ import -u I
+ redirfd -w 2 /dev/null
+ s6-dnsip4 -t 30000 -- ${I}.${CODE}.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
+ import -u 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