From 7f9971512de566d940b92703594fb71e2c95eb1f Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 8 Jul 2024 21:13:49 +0100 Subject: [PATCH] a6-rc-up-tree: handle blocked deps, exit 1 if nothing started --- pkgs/s6-rc-up-tree/default.nix | 14 ++++++++++-- pkgs/s6-rc-up-tree/s6-rc-up-tree.fnl | 33 ++++++++++++++++++++-------- pkgs/s6-rc-up-tree/scripts/s6-rc | 1 + pkgs/s6-rc-up-tree/scripts/s6-rc-db | 14 ++++++++++-- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/pkgs/s6-rc-up-tree/default.nix b/pkgs/s6-rc-up-tree/default.nix index 529193a..e62f044 100644 --- a/pkgs/s6-rc-up-tree/default.nix +++ b/pkgs/s6-rc-up-tree/default.nix @@ -46,9 +46,19 @@ stdenv.mkDerivation { # started controlled rdepends are running, so starting them is harmless - # descendants which depend on a _different_ controlled service, which is down, don't start + # descendants which depend on a _different_ controlled service, + # which is down, don't start: + # Given: + # - modeswitch is controlled + # - atz is controlled + # - atz => modeswitch + # - ifconfig => atz + # Then: if atz is down, ifconfig should not start when modeswitch is started + fennelrepl ./test.fnl ${./test-services} modeswitch + expect "modeswitch" # descendants which depend on a _different_ controlled service, which is up, do start - + ATZ=up fennelrepl ./test.fnl ${./test-services} modeswitch + expect "modeswitch atz ifconfig" ''; } diff --git a/pkgs/s6-rc-up-tree/s6-rc-up-tree.fnl b/pkgs/s6-rc-up-tree/s6-rc-up-tree.fnl index 2ad8017..c73aafb 100644 --- a/pkgs/s6-rc-up-tree/s6-rc-up-tree.fnl +++ b/pkgs/s6-rc-up-tree/s6-rc-up-tree.fnl @@ -38,16 +38,31 @@ (with-popen [h (.. "s6-rc -b -u change " name)] (print (h:read "*a")))) +(fn keys [t] + (icollect [_ v (pairs t)] v)) + (fn run [dir] (let [service (. arg 1) - blocks (stopped-controlled-services (or dir "/run/services/controlled"))] - (print :service service :blocks (view blocks)) - (each [_ s (ipairs (reverse-dependencies service))] - (print :dep s) - (when - (accumulate [start true - _ dep (ipairs (dependencies s))] - (and start (or (= s service) (not (. blocks dep))))) - (start-service s))))) + blocks (doto + (stopped-controlled-services (or dir "/run/services/controlled")) + (tset service nil)) + rdepends (reverse-dependencies service) + starts + (icollect [_ s (ipairs rdepends)] + (when + (accumulate [start true + _ dep (ipairs (dependencies s))] + (and start (not (. blocks dep)))) + s))] + (print "s6-rc-up-tree" + service + "blocks (" (table.concat (keys blocks) ", ") ")" + ;; "rdepends (" (table.concat rdepends ", ") ")" + "start (" (table.concat starts ", ") ")") + (if (> (# starts) 0) + (each [_ s (ipairs starts)] + (start-service s)) + (os.exit 1)))) + { : run } diff --git a/pkgs/s6-rc-up-tree/scripts/s6-rc b/pkgs/s6-rc-up-tree/scripts/s6-rc index 43f56ce..135b388 100755 --- a/pkgs/s6-rc-up-tree/scripts/s6-rc +++ b/pkgs/s6-rc-up-tree/scripts/s6-rc @@ -8,6 +8,7 @@ if [ "$1" = "-da" ]; then echo wattle # controlled echo wombat # controlled echo turmeric # uncontrolled + test -n "$ATZ" || echo atz # uncontrolled fi fi if [ "$1" = "-u" ]; then diff --git a/pkgs/s6-rc-up-tree/scripts/s6-rc-db b/pkgs/s6-rc-up-tree/scripts/s6-rc-db index 2b8a1c1..392e3a3 100755 --- a/pkgs/s6-rc-up-tree/scripts/s6-rc-db +++ b/pkgs/s6-rc-up-tree/scripts/s6-rc-db @@ -9,6 +9,12 @@ reverse_deps(){ enables-wan) echo wattle # controlled ;; + modeswitch) + reverse_deps atz + ;; + atz) + echo ifconfig + ;; esac } @@ -17,8 +23,12 @@ deps(){ case "$1" in rosemary) echo thyme;; - *) - ;; + wattle) + echo enables-wan;; + atz) + echo modeswitch;; + ifconfig) + deps atz;; esac }