1
0
Fork 0

a6-rc-up-tree: handle blocked deps, exit 1 if nothing started

This commit is contained in:
Daniel Barlow 2024-07-08 21:13:49 +01:00
parent f0f6cc80d7
commit 7f9971512d
4 changed files with 49 additions and 13 deletions

View File

@ -46,9 +46,19 @@ stdenv.mkDerivation {
# started controlled rdepends are running, so starting them is harmless # 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 # 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"
''; '';
} }

View File

@ -38,16 +38,31 @@
(with-popen [h (.. "s6-rc -b -u change " name)] (with-popen [h (.. "s6-rc -b -u change " name)]
(print (h:read "*a")))) (print (h:read "*a"))))
(fn keys [t]
(icollect [_ v (pairs t)] v))
(fn run [dir] (fn run [dir]
(let [service (. arg 1) (let [service (. arg 1)
blocks (stopped-controlled-services (or dir "/run/services/controlled"))] blocks (doto
(print :service service :blocks (view blocks)) (stopped-controlled-services (or dir "/run/services/controlled"))
(each [_ s (ipairs (reverse-dependencies service))] (tset service nil))
(print :dep s) rdepends (reverse-dependencies service)
(when starts
(accumulate [start true (icollect [_ s (ipairs rdepends)]
_ dep (ipairs (dependencies s))] (when
(and start (or (= s service) (not (. blocks dep))))) (accumulate [start true
(start-service s))))) _ 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 } { : run }

View File

@ -8,6 +8,7 @@ if [ "$1" = "-da" ]; then
echo wattle # controlled echo wattle # controlled
echo wombat # controlled echo wombat # controlled
echo turmeric # uncontrolled echo turmeric # uncontrolled
test -n "$ATZ" || echo atz # uncontrolled
fi fi
fi fi
if [ "$1" = "-u" ]; then if [ "$1" = "-u" ]; then

View File

@ -9,6 +9,12 @@ reverse_deps(){
enables-wan) enables-wan)
echo wattle # controlled echo wattle # controlled
;; ;;
modeswitch)
reverse_deps atz
;;
atz)
echo ifconfig
;;
esac esac
} }
@ -17,8 +23,12 @@ deps(){
case "$1" in case "$1" in
rosemary) rosemary)
echo thyme;; echo thyme;;
*) wattle)
;; echo enables-wan;;
atz)
echo modeswitch;;
ifconfig)
deps atz;;
esac esac
} }