prain stack: requires_NAME refuses to start without its services, merged --help

This commit is contained in:
2026-11-06 15:50:33 +01:00
parent 8c58c43b1b
commit dfc38db6f8
6 changed files with 80 additions and 29 deletions
+25 -4
View File
@@ -10,7 +10,15 @@ cat > "$t/root/scripts/env.sh" <<EOF
export FROM_ENV_SH=yes
PATH=$t/root/.venv/bin:\$PATH
EOF
printf '#!/bin/sh\necho "prain $* env=$FROM_ENV_SH cwd=$PWD"\n' > "$t/root/.venv/bin/prain"
cat > "$t/root/.venv/bin/prain" <<'EOF'
#!/bin/sh
if [ "$1" = --help ]; then
printf 'usage: prain [-h] {check,web} ...\n\npositional arguments:\n {check,web}\n'
printf ' check validate\n'
exit 0
fi
echo "prain $* env=$FROM_ENV_SH cwd=$PWD"
EOF
printf '#!/bin/sh\necho "$*"\n' > "$t/bin/rc-service"
chmod +x "$t/root/.venv/bin/prain" "$t/bin/rc-service"
cat > "$t/prain.conf" <<EOF
@@ -19,10 +27,12 @@ PRAIN_SERVICES="a b"
cmd_a='echo a: \$FROM_ENV_SH
in \$PWD'
cmd_b='prain web --port 1'
need_b=a
ready_b=http://127.0.0.1:9/never
requires_b=a
requires_x=b
EOF
export PRAIN_CONF=$t/prain.conf PRAIN_READY_TIMEOUT=1 PATH=$t/bin:$PATH
unset XDG_STATE_HOME
fail=0
check() { # name expected actual
if [ "$2" = "$3" ]; then echo "ok $1"; else echo "FAIL $1: expected [$2], got [$3]"; fail=1; fi
@@ -32,8 +42,6 @@ check passthrough "prain check x.toml env=yes cwd=/" "$("$p" check x.toml)"
check run-joins-lines-in-root "a: yes in $t/root" "$("$p" run a)"
check run-uses-venv-prain "prain web --port 1 env=yes cwd=$t/root" "$("$p" run b)"
check run-unknown-fails 1 "$("$p" run zzz 2>/dev/null; echo $?)"
check need "a" "$("$p" need b)"
check need-none "" "$("$p" need a)"
check wait-without-url 0 "$("$p" wait a; echo $?)"
check wait-times-out 1 "$("$p" wait b 2>/dev/null; echo $?)"
check up-in-order "--user prain.a start
@@ -41,4 +49,17 @@ check up-in-order "--user prain.a start
check down-in-reverse "--user prain.b stop
--user prain.a stop" "$("$p" down)"
check status-one "--user prain.b status" "$("$p" status b)"
check deps-ok-when-running 0 "$("$p" deps b; echo $?)"
check deps-fail-without-starting-them "prain: x needs b, which is not running (no answer from http://127.0.0.1:9/never). Start it first: prain up b
1" "$("$p" deps x 2>&1; echo $?)"
check help-merges-stack-commands "usage: prain [-h] {up,down,restart,status,logs,check,web} ...
positional arguments:
{up,down,restart,status,logs,check,web}
up [NAME...] start services (all: a b), each waits until ready
down [NAME...] stop services, in reverse order
restart [NAME...] restart services
status [NAME...] show whether services run
logs [NAME...] follow service logs ($HOME/.local/state/prain/NAME.log)
check validate" "$("$p" --help)"
exit $fail