8f3b659c33
redirector.sh and the coming roster.sh needed the same five rules, each
of which cost something to learn:
* resolve /proc/PID/exe; never match a command line. `pkill -f` /
`pgrep -f` match any shell whose ARGUMENTS mention the name, including
the shell running the command. That has killed this session's own
shell twice, and is now banned in migration tooling -- the helper
contains no `-f` matching and the header says why.
* `readlink`, not `readlink -f`. After a rebuild the link reads
"<path> (deleted)" and -f resolves it to nothing, so the orphan check
goes blind to exactly the long-lived processes it exists to find. Two
orphans hid there, one serving the wrong certificate.
* stop PROVES the process is gone and the port free.
* an ambiguous binary is an error for start/verify but NOT for
stop/status: rollback must never be blocked by a question about the
build tree.
* verify the RUNNING process's commit, not the artifact on disk, which
a rebuild can silently advance past.
Copying those into a second script would have been the same mistake as
copying the TLS setup. Instead scripts/host-lifecycle.sh owns them and a
service supplies four facts: name, crate, executable, port variable.
redirector.sh goes from 178 lines to 26 and roster.sh is 24, with no
behaviour change -- the refactored redirector.sh still sees the live
armed process (pid 830736, port 42227) and still refuses correctly
because HEAD has moved past it.
Paths are unchanged (rundir, pidfile, portfile, commit stamp, log), so
the currently running redirector stays manageable across this refactor.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
27 lines
1.2 KiB
Bash
Executable File
27 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Lifecycle for the Rust redirector host.
|
|
#
|
|
# redirector.sh start | stop | status | verify | verify-running
|
|
#
|
|
# A thin wrapper: the rules this project paid for — resolve /proc/PID/exe
|
|
# rather than matching command lines, tolerate the "(deleted)" suffix after a
|
|
# rebuild, prove a stop rather than assume it, refuse an ambiguous binary, and
|
|
# check the RUNNING process's commit rather than the one on disk — all live in
|
|
# scripts/host-lifecycle.sh so there is one implementation of them.
|
|
#
|
|
# Environment:
|
|
# OPENFUT_REDIRECTOR_HOST_PORT required; no default, so this can never
|
|
# collide with the Python redirector
|
|
# OPENFUT_REDIRECTOR_CERT/KEY MUST be the same pair every other
|
|
# FIFA-facing service presents
|
|
# OPENFUT_REDIRECTOR_BIN explicit binary, if debug and release disagree
|
|
HL_NAME="redirector"
|
|
HL_CRATE="openfut-redirector-host"
|
|
HL_BINNAME="openfut-redirector-host"
|
|
HL_PORT_VAR="OPENFUT_REDIRECTOR_HOST_PORT"
|
|
|
|
# shellcheck source=../scripts/host-lifecycle.sh
|
|
source "$(cd "$(dirname "$(readlink -f "$0")")/.." && pwd)/scripts/host-lifecycle.sh"
|
|
|
|
hl_dispatch "${1:-}"
|