Show a launched job's progress, stop a refused rerun from overwriting the live record, and label deployed containers so Unraid owns them

This commit is contained in:
Gmer4Lfe
2026-08-17 04:26:32 -04:00
parent cce1e25c2b
commit 2cbc06a683
5 changed files with 152 additions and 6 deletions
+22
View File
@@ -138,6 +138,28 @@ if [[ "$MANUAL" == false && -f "$MANUAL_TS_FILE" ]]; then
rm -f "$MANUAL_TS_FILE"
fi
# Refuse to start when this job is already running, and leave its record untouched.
#
# The wrapped scripts take their own locks, so a second invocation was already refused — but it
# was refused *after* run_job.sh had overwritten the stat file with its own pid, and it then wrote
# its instant exit-1 over the live run's record. The job kept working while every status reader
# showed it failed. Observed for real: an onboard mid-way through deploying containers reported
# {"status":"warn","exit":1} because the operator, seeing no progress, had clicked twice.
#
# api/run.php has always had this guard; run_job.sh did not, and cron and the remote phase-2
# trigger both reach run_job.sh directly without passing through it.
if [[ -f "$STAT_FILE" ]]; then
_prev_status=$(sed -n 's/.*"status":"\([^"]*\)".*/\1/p' "$STAT_FILE" 2>/dev/null)
_prev_pid=$(sed -n 's/.*"pid":\([0-9]*\).*/\1/p' "$STAT_FILE" 2>/dev/null)
if [[ "$_prev_status" == "running" && -n "$_prev_pid" && -d "/proc/$_prev_pid" ]]; then
printf '\n── %s [REFUSED — already running as PID %s] ────────\n' \
"$(date '+%Y-%m-%d %H:%M:%S')" "$_prev_pid" >> "$LOG_FILE"
echo "$JOB_ID already running (PID $_prev_pid) — not starting a second run" >&2
exit 0
fi
unset _prev_status _prev_pid
fi
START=$(date +%s)
printf '{"id":"%s","status":"running","start":%s,"pid":%s}\n' \
"$JOB_ID" "$START" "$$" > "$STAT_FILE"