fix(upgrade): refuse a pre-#385 library Console unit before units stop (#385)

This commit is contained in:
jason.woltje committed 2026-11-02 12:19:07 -06:00
1 parent d0ddfa8de2
commit 484aef7e2a
6 files changed
+153 -15

No files matched your search

+29 -1
View File
@@ -120,7 +120,8 @@ logl "start rc=0 argv:$(printf ' %q' "$0" "${ARGV[@]}")"
# --- The args file and the stack's user ---
# I2's file: one case2-unit.sh argument per line, owned by root with no group or other write. Sets
# ARGS (the lines), S_USER, S_HOME, BUSINESS, NODE and ARGS_COPY, and the paths derived from them.
# ARGS (the lines), S_USER, S_HOME, BUSINESS, NODE, ARGS_COPY and ARGS_PROFILE, and the paths derived
# from them.
# #385 R2-F1: base case2-unit.sh required --send for the library profile (its default, and the last
# --profile wins, as there), and the current one refuses it. A2 would stop both units, and A4 and
# render-old would both fail on the same args, so a library file holding --send after -- refuses
@@ -148,6 +149,7 @@ read_args() {
esac
done
[ "$copies" = 1 ] || refuse args-unreadable "$f needs exactly one --copy before --, not $copies"
ARGS_PROFILE="$profile"
if [ "$profile" = library ]; then
for ((i = i + 1; i < ${#ARGS[@]}; i++)); do
[ "${ARGS[i]}" != --send ] ||
@@ -165,6 +167,30 @@ read_args() {
AS_USER=("$SUDO" -u "$S_USER" -H env "PATH=$(dirname "$NODE"):/usr/local/bin:/usr/bin:/bin")
}
# #385 R3-F1: base case2-unit.sh also put --send in the library Console unit's ExecStart. The current
# one checks an installed unit's ExecStart against its own read-only command, so A4 and render-old
# would both refuse that unit after A2 stopped both. No reviewed migration exists, so a library host
# whose installed Console unit has a --send token after serve refuses here, before anything runs. A
# missing unit is read_old's to refuse.
legacy_console() {
local f="$UNIT_DIR/$CON_UNIT" line t past
local -a lines words
[ "$ARGS_PROFILE" = library ] && [ -f "$f" ] && [ ! -L "$f" ] || return 0
mapfile -t lines < "$f" || refuse units-unreadable "cannot read $f"
for line in "${lines[@]}"; do
[[ "$line" =~ ^[[:space:]]*ExecStart[[:space:]]*=(.*)$ ]] || continue
read -r -a words <<< "${BASH_REMATCH[1]}"
past=""
for t in "${words[@]}"; do
if [ -n "$past" ]; then
[ "$t" != --send ] ||
refuse console-unit-legacy "$f runs serve with --send, so it was rendered before #385, and stack-upgrade.sh cannot migrate it to the read-only library Console: the units are left running; stop and report (docs/guides/host-run-sheet.md section 7)"
elif [ "$t" = serve ]; then past=1
fi
done
done
}
# RENDER_ARGS: the args file's lines with copy $1 in place of --copy's value.
args_with() {
local i past=""
@@ -296,6 +322,7 @@ run_steps() {
do_upgrade() {
read_args
legacy_console
# Before A1: the bundle into the stack's user's clone, then the copy from it (I1).
step fetch "${AS_USER[@]}" git -C "$CLONE" fetch -q "$BUNDLE" refs/heads/refactor:refs/remotes/origin/refactor ||
refuse fetch-failed "the stack's user could not fetch $BUNDLE into $CLONE"
@@ -342,6 +369,7 @@ rehearse() {
# check: the target is an older copy than this checkout, and no rehearsal.
do_rollback() {
read_args
legacy_console
[ -x "$COPIES_DIR/$TO/scripts/mosaic" ] || refuse copy-missing "no $COPIES_DIR/$TO/scripts/mosaic"
hostcheck
read_old