- Added --no-color flag to all PM2 commands - Self-process guard: abiba-zulip is READ-ONLY, never restarted - Corrected column indices (PID=6, restarts=8, status=9) - Added pm2-self-heal.sh shell script implementation
2.6 KiB
2.6 KiB
kind, name, description
| kind | name | description |
|---|---|---|
| responsibility | pm2-self-heal | Monitors critical PM2 processes (abiba-zulip, abiba-telegram) and auto-restarts any that are stopped or errored. Logs every action to the knowledge graph and alerts the owner via Zulip DM on failures. CRITICAL: Never restart abiba-zulip — it runs this contract. |
Maintains
- abiba-zulip: { status: "online", uptime: string, restarts: number }
- abiba-telegram: { status: "online", uptime: string, restarts: number }
- last_check: timestamp
Continuity
- Self-driven: check every 300 seconds (5 min)
- Also wakes on user request (
prose run pm2-self-heal)
Remediation Rules
Rule 1: Process Stopped or Errored
- Detect:
pm2 statusshows "stopped" or "errored" for a named process - Fix:
pm2 restart <name> - Verify: Re-check status after 5 seconds
- Escalate: If still failed after 2 retries, send Zulip DM to owner
Rule 2: Process Restarting Too Often
- Detect:
pm2 statusshows restarts > 5 in the last hour - Fix:
pm2 delete <name> && pm2 start <ecosystem> --only <name> - Escalate: Always — alert owner with restart count
Execution
- Check PM2 status — Run
pm2 status --no-colorand parse the table (5th data column = PID, 8th = restarts, 9th = status) - Check abiba-telegram:
- If status is "online" → pass
- If status is "stopped" or "errored" → apply Rule 1
- If restarts > 5 → alert owner
- Check abiba-zulip (self-process, read-only):
- If status is "online" → pass, log restarts count
- If status is "stopped" or "errored" → DO NOT RESTART — alert owner immediately
- If restarts > 5 in last hour → alert owner with full diagnostics
- Log results — Create
[LEARN]node in knowledge graph for any actions taken - Alert — Send Zulip DM to owner if escalation needed (do NOT run pm2 commands during alerting)
- Wait 5 min → repeat from step 1
Example Output (when healthy)
{
"run_id": "pm2-heal-001",
"checked_at": "2026-06-26T15:00:00Z",
"processes": {
"abiba-zulip": { "status": "online", "uptime": "2h", "restarts": 0 },
"abiba-telegram": { "status": "online", "uptime": "48h", "restarts": 0 }
},
"actions_taken": [],
"overall": "healthy"
}
Example Output (when fixed)
{
"processes": {
"abiba-telegram": { "status": "errored → restarted → online" },
"abiba-zulip": { "status": "online", "uptime": "2h", "restarts": 0 }
},
"actions_taken": [
{ "target": "abiba-telegram", "action": "pm2 restart", "result": "online" }
],
"overall": "fixed"
}