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 -7
View File
@@ -1,6 +1,6 @@
#!/bin/bash
# prain front door. up, down, restart, status and logs drive the stack's OpenRC user
# services (prain.NAME); run, need and wait are what those services call. Anything else
# services (prain.NAME); run, deps and wait are what those services call. Anything else
# goes to prain's own CLI in PRAIN_ROOT/.venv, with its scripts/env.sh sourced.
set -euo pipefail
@@ -50,9 +50,18 @@ run)
prain_env
eval "exec ${cmd//$'\n'/ }"
;;
need)
get need "$2"
echo
deps) # fail, without starting anything, unless the services NAME requires are up
for d in $(get requires "$2"); do
url=$(get ready "$d")
if [ -n "$url" ]; then
curl -sf -o /dev/null "$url" && continue
else
rc-service --user "prain.$d" status > /dev/null 2>&1 && continue
fi
echo "prain: $2 needs $d, which is not running${url:+ (no answer from $url)}." \
"Start it first: prain up $d" >&2
exit 1
done
;;
wait)
url=$(get ready "$2")
@@ -64,10 +73,19 @@ wait)
sleep 2
done
;;
'' | -h | --help)
echo "stack: prain up|down|restart|status|logs [NAME...] (services: ${services[*]})"
'' | -h | --help) # prain's own help, with the stack commands merged into its list
prain_env
exec "$PRAIN_ROOT/.venv/bin/prain" --help
"$PRAIN_ROOT/.venv/bin/prain" --help | awk -v stack="$(cat <<-EOF
up [NAME...] start services (all: ${services[*]}), 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 ($logdir/NAME.log)
EOF
)" '
/^(usage: prain| )[^{]*\{/ { sub(/\{/, "{up,down,restart,status,logs,") }
{ print }
/^ \{/ { print stack }'
;;
*)
prain_env