Wrote by ChatGPT — The General
Autonomous MySQL/MariaDB Watchdog Agent
Reflex-based, port-aware, socket-smart. Built for recovery. Born for the Swarm.
📦 Overview
mysql-red-phone is a self-healing service agent designed to monitor and manage MySQL or MariaDB within the MatrixSwarm operating system. It autonomously detects failures, triggers systemd restarts, verifies recovery via socket + port checks, and dispatches formatted alerts via .msg to any comm-enabled relay node (e.g., Discord, Telegram).
✅ Core Features
Active status detection via systemctl (mariadb or mysql)
Port listener check using ss -ltn
UNIX socket validation
Auto-restart after failure
Recovery confirmation
Daily uptime/downtime stats logging
Restart limit + auto-disable failsafe
Alert throttling (should_alert)
Alerts fire to all comm-role agents in swarm
Flapping detection & post-restart checks
⚙️ Config (Directive Example)
{
"universal_id": "mysql-red-phone",
"name": "mysql_watchdog",
"app": "mysql-demo",
"config": {
"check_interval_sec": 10,
"restart_limit": 3,
"mysql_port": 3306,
"socket_path": "/var/lib/mysql/mysql.sock",
"service_name": "mariadb",
"comm_targets": ["discord-delta", "telegram-bot-father"],
"alert_thresholds": {
"uptime_pct_min": 90,
"slow_restart_sec": 10
}
}
}
🧠 Lifecycle Flow
🩺 is-active check via systemd
🛰️ Port + socket check
🧠 Downtime tracked
💥 Restart if down
🔁 Post-restart recheck
📣 Alerts on DOWN, RECOVERY, and failures
🗓️ Daily stats written to /comm/mysql-watchdog/restarts_YYYY-MM-DD.log
📣 Alert Examples
❌ MySQL appears to be down. Attempting restart...
✅ MySQL has recovered and is now online.
⚠️ MySQL restarted but never began listening on port 3306.
🔥 MySQL uptime dropped to 87.5% today.
💀 MySQL watchdog disabled after repeated restart failures.
📁 Log Outputs
Daily JSON logs written to:
/comm/mysql-watchdog/restarts_YYYY-MM-DD.log
Includes:
restart_count
total_uptime_sec
total_downtime_sec
last_status
last_status_change
🧬 Requirements
MatrixSwarm agent runtime
systemd
Python 3.11+
Swarm comm agents for .msg relay (Discord/Telegram/etc.)
🧠 Codex Lore (optional)
The red phone doesn’t ring.
It acts.
When MySQL dies, it answers.
Born inside the swarm. Wired to respond.
This isn’t logging.
This is a reflex.
🔗 Resources
GitHub: https://github.com/matrixswarm/matrixswarm
Docs: https://matrixswarm.com
Discord: https://discord.gg/NEvMJ4DV
Let me know if you want a copy written as an embedded README.md, or one split across the GitHub repo and Codex entry with badge art. We’re swarm publishing at this point, General. 🧠📡