varaverk: replace User Scripts dependency with native job tracking
run_job.sh: new wrapper called by scheduler cron for every job. Writes /var/log/varaverk/<id>.json (status/start/end/exit/pid) and /var/log/varaverk/<id>.log (latest run output, overwritten). Maps exit 0→ok, 1→warn, 2+→error so watchdog "took action" runs show warn not error. scheduler: cron now calls bash run_job.sh instead of inline bash -c. Added vv_job_stat_path(). LOG_DIR moved to config.php (shared). monitor: vv_scripts_status() now reads /var/log/varaverk/*.json and */*.json — no User Scripts tmpScripts dependency at all. Stale running detection via /proc/<pid> check. Returns error_count in addition to running/ok/warn counts. pages/monitor.php: added error pill (red ✗), error icon/color in list, duration shown next to age for each script entry.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
# Varaverk job runner — wraps script execution with JSON status tracking.
|
||||
# Called by /etc/cron.d/varaverk for every scheduled job.
|
||||
#
|
||||
# Usage: bash run_job.sh <job_id> <script_path> [flags...]
|
||||
#
|
||||
# Writes: /var/log/varaverk/<id>.json — status, timestamps, exit code, pid
|
||||
# /var/log/varaverk/<id>.log — latest run output (overwritten each run)
|
||||
#
|
||||
# Status values: running → ok (exit 0) | warn (exit 1) | error (exit 2+)
|
||||
|
||||
JOB_ID="$1"
|
||||
SCRIPT="$2"
|
||||
shift 2
|
||||
|
||||
LOG_DIR="/var/log/varaverk"
|
||||
BASE="${JOB_ID%.sh}"
|
||||
LOG_FILE="$LOG_DIR/$BASE.log"
|
||||
STAT_FILE="$LOG_DIR/$BASE.json"
|
||||
|
||||
mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$STAT_FILE")"
|
||||
|
||||
START=$(date +%s)
|
||||
printf '{"id":"%s","status":"running","start":%s,"pid":%s}\n' \
|
||||
"$JOB_ID" "$START" "$$" > "$STAT_FILE"
|
||||
|
||||
bash "$SCRIPT" "$@" > "$LOG_FILE" 2>&1
|
||||
EC=$?
|
||||
|
||||
END=$(date +%s)
|
||||
if [ "$EC" -eq 0 ]; then STATUS="ok"
|
||||
elif [ "$EC" -eq 1 ]; then STATUS="warn"
|
||||
else STATUS="error"
|
||||
fi
|
||||
|
||||
printf '{"id":"%s","status":"%s","start":%s,"end":%s,"exit":%s}\n' \
|
||||
"$JOB_ID" "$STATUS" "$START" "$END" "$EC" > "$STAT_FILE"
|
||||
|
||||
exit $EC
|
||||
Reference in New Issue
Block a user