55 lines
2.5 KiB
Bash
Executable File
55 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# ╔══════════════════════════════════════════════════════════════════╗
|
|
# ║ WEVIA DIRECTOR CRON v1.0 — Autonomous Loop ║
|
|
# ║ Runs every 15 minutes via crontab ║
|
|
# ║ Calls Director Agent API → Observe → Plan → Act → Verify ║
|
|
# ╚══════════════════════════════════════════════════════════════════╝
|
|
|
|
LOGFILE="/var/log/wevia-director/cron.log"
|
|
LOCKFILE="/tmp/.wevia-director.lock"
|
|
API_URL="https://weval-consulting.com/api/wevia-director.php?run&force=0"
|
|
|
|
mkdir -p /var/log/wevia-director
|
|
|
|
# Prevent concurrent runs
|
|
if [ -f "$LOCKFILE" ]; then
|
|
PID=$(cat "$LOCKFILE")
|
|
if kill -0 "$PID" 2>/dev/null; then
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') SKIP: Previous cycle still running (PID $PID)" >> "$LOGFILE"
|
|
exit 0
|
|
fi
|
|
rm -f "$LOCKFILE"
|
|
fi
|
|
|
|
echo $$ > "$LOCKFILE"
|
|
trap "rm -f $LOCKFILE" EXIT
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') START: Director cycle" >> "$LOGFILE"
|
|
|
|
# Call director API
|
|
RESPONSE=$(curl -s --max-time 120 "$API_URL" 2>&1)
|
|
EXIT_CODE=$?
|
|
|
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') ERROR: curl failed (exit $EXIT_CODE)" >> "$LOGFILE"
|
|
exit 1
|
|
fi
|
|
|
|
# Extract key metrics
|
|
PHASE=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('phase','?'))" 2>/dev/null)
|
|
ACTIONS=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d.get('actions',[])))" 2>/dev/null)
|
|
ESCALATIONS=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d.get('escalations',[])))" 2>/dev/null)
|
|
REPORT=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('report','?')[:200])" 2>/dev/null)
|
|
SKIPPED=$(echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('skipped',''))" 2>/dev/null)
|
|
|
|
if [ "$SKIPPED" = "True" ]; then
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') SKIP: Rate limited" >> "$LOGFILE"
|
|
else
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') DONE: phase=$PHASE actions=$ACTIONS escalations=$ESCALATIONS | $REPORT" >> "$LOGFILE"
|
|
fi
|
|
|
|
# Rotate log if >10MB
|
|
if [ -f "$LOGFILE" ] && [ $(stat -f%z "$LOGFILE" 2>/dev/null || stat -c%s "$LOGFILE") -gt 10485760 ]; then
|
|
mv "$LOGFILE" "${LOGFILE}.old"
|
|
fi
|