summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-10-10 23:28:47 +0000
committerAlyssa Ross <hi@alyssa.is>2023-02-26 19:12:45 +0000
commit0dea82c967956fea4305cdc0da09303679072a01 (patch)
treebde8843240326ab3f76968e3f6a271eca70afd54
parentbf36d81385314ba454125c9c6909a6d3cf70fca9 (diff)
downloadspectrum-0dea82c967956fea4305cdc0da09303679072a01.tar
spectrum-0dea82c967956fea4305cdc0da09303679072a01.tar.gz
spectrum-0dea82c967956fea4305cdc0da09303679072a01.tar.bz2
spectrum-0dea82c967956fea4305cdc0da09303679072a01.tar.lz
spectrum-0dea82c967956fea4305cdc0da09303679072a01.tar.xz
spectrum-0dea82c967956fea4305cdc0da09303679072a01.tar.zst
spectrum-0dea82c967956fea4305cdc0da09303679072a01.zip
img/app: don't block app startup on network online
Not all VMs will even have networking!  So it makes more sense to put
waiting for the network in the application-specific part.

The "listen" and "wait" scripts are copied from the host system.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
Message-Id: <20221010232909.1953738-8-hi@alyssa.is>
-rw-r--r--img/app/Makefile2
-rwxr-xr-ximg/app/etc/mdev/iface4
-rwxr-xr-ximg/app/etc/mdev/listen12
-rwxr-xr-ximg/app/etc/mdev/wait15
-rw-r--r--img/app/etc/s6-rc/ok-all/contents1
-rw-r--r--vm/app/catgirl.nix1
-rw-r--r--vm/app/lynx.nix1
7 files changed, 34 insertions, 2 deletions
diff --git a/img/app/Makefile b/img/app/Makefile
index b697135..5902c2c 100644
--- a/img/app/Makefile
+++ b/img/app/Makefile
@@ -35,6 +35,8 @@ VM_FILES = \
 	etc/init \
 	etc/mdev.conf \
 	etc/mdev/iface \
+	etc/mdev/listen \
+	etc/mdev/wait \
 	etc/passwd \
 	etc/resolv.conf \
 	etc/s6-linux-init/scripts/rc.init
diff --git a/img/app/etc/mdev/iface b/img/app/etc/mdev/iface
index d8ceda5..93a12eb 100755
--- a/img/app/etc/mdev/iface
+++ b/img/app/etc/mdev/iface
@@ -1,6 +1,6 @@
 #!/bin/execlineb -P
 # SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2020-2021 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2020-2022 Alyssa Ross <hi@alyssa.is>
 
 importas -i INTERFACE INTERFACE
 
@@ -33,4 +33,4 @@ foreground {
   }
 }
 
-s6-rc -u change app
+/etc/mdev/listen network-online
diff --git a/img/app/etc/mdev/listen b/img/app/etc/mdev/listen
new file mode 100755
index 0000000..6bc6f2c
--- /dev/null
+++ b/img/app/etc/mdev/listen
@@ -0,0 +1,12 @@
+#!/bin/execlineb -s1
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+
+foreground {
+  redirfd -w 2 /dev/null
+  foreground { mkdir /run/wait }
+  mkfifo /run/wait/${1}
+}
+
+redirfd -w 1 /run/wait/${1}
+echo
diff --git a/img/app/etc/mdev/wait b/img/app/etc/mdev/wait
new file mode 100755
index 0000000..3b85de8
--- /dev/null
+++ b/img/app/etc/mdev/wait
@@ -0,0 +1,15 @@
+#!/bin/execlineb -s1
+# SPDX-License-Identifier: EUPL-1.2+
+# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+
+foreground {
+  redirfd -w 2 /dev/null
+  foreground { mkdir /run/wait }
+  mkfifo /run/wait/${1}
+}
+
+foreground {
+  redirfd -w 1 /dev/null
+  head -1 /run/wait/${1}
+}
+rm /run/wait/${1}
diff --git a/img/app/etc/s6-rc/ok-all/contents b/img/app/etc/s6-rc/ok-all/contents
index c4ea84f..92f3ef1 100644
--- a/img/app/etc/s6-rc/ok-all/contents
+++ b/img/app/etc/s6-rc/ok-all/contents
@@ -2,3 +2,4 @@
 # SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
 #
 mdevd-coldplug
+app
diff --git a/vm/app/catgirl.nix b/vm/app/catgirl.nix
index 7cd76a9..755852b 100644
--- a/vm/app/catgirl.nix
+++ b/vm/app/catgirl.nix
@@ -9,6 +9,7 @@ import ../make-vm.nix { inherit config; } {
     { writeScript, catgirl }:
     writeScript "run-catgirl" ''
       #!/bin/execlineb -P
+      if { /etc/mdev/wait network-online }
       foreground { printf "IRC nick (to join #spectrum): " }
       backtick -E nick { head -1 }
       ${catgirl}/bin/catgirl -h irc.libera.chat -j "#spectrum" -n $nick
diff --git a/vm/app/lynx.nix b/vm/app/lynx.nix
index 21cb56e..d4560f4 100644
--- a/vm/app/lynx.nix
+++ b/vm/app/lynx.nix
@@ -9,6 +9,7 @@ import ../make-vm.nix { inherit config; } {
     { writeScript, lynx }:
     writeScript "run-lynx" ''
       #!/bin/execlineb -P
+      if { /etc/mdev/wait network-online }
       ${lynx}/bin/lynx https://spectrum-os.org
     ''
   ) { };