chore: add private-safe controller startup diagnostics
Add fixed startup branch labels and numeric apply exit status without relaxing startup guards or exposing private values. Cover shared launch/ACK and wrapper branches plus failed apply cleanup. Diagnostics only; the ACK publication race remains unchanged. Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
de453ed2c8
commit
ade3b89137
6 files changed
+131
-7
No files matched your search
@@ -130,9 +130,13 @@ cleanup_session() {
|
||||
capture_monitor_session() {
|
||||
[ -z "$monitor_sid" ] || return 0
|
||||
if [ -e "$config_dir/monitor-ready" ]; then
|
||||
read -r candidate_sid < "$config_dir/monitor-ready" || return 78
|
||||
case "$candidate_sid" in ''|*[!0-9]*) return 78 ;; esac
|
||||
[ "$candidate_sid" = "$monitor_pid" ] && [ "$candidate_sid" -gt 1 ] && [ "$candidate_sid" != "$$" ] || return 78
|
||||
{ read -r candidate_sid < "$config_dir/monitor-ready"; } 2>/dev/null || {
|
||||
echo 'controller-startup: ack=read_failed' >&2; return 78;
|
||||
}
|
||||
case "$candidate_sid" in ''|*[!0-9]*) echo 'controller-startup: ack=invalid_pid' >&2; return 78 ;; esac
|
||||
[ "$candidate_sid" = "$monitor_pid" ] && [ "$candidate_sid" -gt 1 ] && [ "$candidate_sid" != "$$" ] || {
|
||||
echo 'controller-startup: ack=identity_mismatch' >&2; return 78;
|
||||
}
|
||||
monitor_sid=$candidate_sid
|
||||
elif proc_identity "$monitor_pid" && [ "$proc_sid" = "$monitor_pid" ] && [ "$proc_sid" -gt 1 ]; then
|
||||
monitor_sid=$proc_sid
|
||||
@@ -339,12 +343,18 @@ launch_controller() {
|
||||
monitor_ack_deadline=$(($(date +%s) + 5))
|
||||
while [ ! -e "$config_dir/monitor-ready" ]; do
|
||||
if ! kill -0 "$monitor_pid" 2>/dev/null || [ "$(date +%s)" -ge "$monitor_ack_deadline" ]; then
|
||||
if ! kill -0 "$monitor_pid" 2>/dev/null; then
|
||||
echo 'controller-startup: launch=child_gone' >&2
|
||||
else
|
||||
echo 'controller-startup: launch=ack_timeout' >&2
|
||||
fi
|
||||
signal_tree "$monitor_pid" KILL
|
||||
return 78
|
||||
fi
|
||||
done
|
||||
capture_monitor_session || return 78
|
||||
if proc_identity "$monitor_pid" && [ "$proc_sid" != "$monitor_sid" ]; then
|
||||
echo 'controller-startup: launch=session_mismatch' >&2
|
||||
monitor_sid=
|
||||
return 78
|
||||
fi
|
||||
@@ -387,8 +397,9 @@ if [ "${ZAPRET_AUTOTUNE_RESOURCE_APPLY-0}" = 1 ]; then
|
||||
{ dns_alive && kill -0 "$server_pid" && kill -0 "$local_pid"; } || return 75
|
||||
apply_code=0
|
||||
wait "$monitor_pid" || apply_code=$?
|
||||
echo "controller-startup: apply_wait_exit=$apply_code" >&2
|
||||
monitor_pid=
|
||||
cleanup_session || return 78
|
||||
cleanup_session || { echo 'controller-startup: apply_cleanup=failed' >&2; return 78; }
|
||||
[ "$apply_code" -eq 0 ] || return 78
|
||||
fi
|
||||
# Idempotent apply may have only verified the already committed config.
|
||||
|
||||
Reference in new issue
Block a user