mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
Autonomous systems: watchdog, smart deploy, site health, auto-heal, agent installer
- deploy/jarvis-watchdog.sh: self-healing watchdog (every 5 min) * monitors lsws/mysql/redis, restarts on failure * JARVIS HTTP self-check, restarts OLS on 5xx * disk/memory alerts inserted to DB * offline Proxmox VM agents restarted via qm guest exec * log rotation (1000 line cap) - deploy/jarvis-deploy.sh: smart deploy with PHP validation * php8.3 syntax check on every changed .php file * auto-reverts git commit + inserts critical alert on syntax error * reloads OLS after JARVIS deploys - api/endpoints/facts_collector.php: site health monitoring * curls all 7 managed sites every 3 min * stores up/down status in kb_facts - api/endpoints/alerts.php: auto-heal + site alerts * dispatches restart_service commands when services down on agents * generates alerts from kb_facts site health data - public_html/install-agent.sh: one-liner Linux agent installer * installs deps, downloads agent, registers with JARVIS, sets up systemd - public_html/webhook.php: fixed infra deploy path to /opt/infra
This commit is contained in:
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
# JARVIS Agent Installer — one-liner for any Linux host:
|
||||
# curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s <hostname> <agent_type>
|
||||
#
|
||||
# agent_type: linux | proxmox | homeassistant
|
||||
# Example: curl -sk https://jarvis.orbishosting.com/install-agent.sh | bash -s myserver linux
|
||||
|
||||
set -e
|
||||
|
||||
HOSTNAME="${1:-$(hostname -s)}"
|
||||
AGENT_TYPE="${2:-linux}"
|
||||
JARVIS_URL="https://165.22.1.228"
|
||||
JARVIS_HOST="jarvis.orbishosting.com"
|
||||
INSTALL_DIR="/opt/jarvis-agent"
|
||||
SERVICE_FILE="/etc/systemd/system/jarvis-agent.service"
|
||||
|
||||
echo "=== JARVIS Agent Installer ==="
|
||||
echo "Host: $HOSTNAME | Type: $AGENT_TYPE | Server: $JARVIS_URL"
|
||||
|
||||
# ── Dependencies ──────────────────────────────────────────────────────────────
|
||||
if command -v apt-get &>/dev/null; then
|
||||
apt-get install -yq python3 python3-pip curl 2>/dev/null
|
||||
elif command -v yum &>/dev/null; then
|
||||
yum install -yq python3 python3-pip curl 2>/dev/null
|
||||
fi
|
||||
pip3 install -q requests psutil 2>/dev/null || pip install -q requests psutil 2>/dev/null
|
||||
|
||||
# ── Download agent ─────────────────────────────────────────────────────────────
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
curl -sk -H "Host: $JARVIS_HOST" "$JARVIS_URL/agent/jarvis-agent.py" -o "$INSTALL_DIR/jarvis-agent.py"
|
||||
chmod +x "$INSTALL_DIR/jarvis-agent.py"
|
||||
|
||||
# ── Register with JARVIS to get API key ───────────────────────────────────────
|
||||
IP=$(hostname -I | awk '{print $1}')
|
||||
REG=$(curl -sk -H "Host: $JARVIS_HOST" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Registration-Key: f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518" \
|
||||
-X POST "$JARVIS_URL/api/agent/register" \
|
||||
-d "{\"hostname\":\"$HOSTNAME\",\"agent_type\":\"$AGENT_TYPE\",\"ip_address\":\"$IP\",\"capabilities\":[\"metrics\",\"commands\"]}")
|
||||
|
||||
AGENT_ID=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['agent_id'])" 2>/dev/null)
|
||||
API_KEY=$(echo "$REG" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['api_key'])" 2>/dev/null)
|
||||
|
||||
if [ -z "$API_KEY" ]; then
|
||||
echo "ERROR: Registration failed — $REG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Registered: agent_id=$AGENT_ID"
|
||||
|
||||
# ── Write config ───────────────────────────────────────────────────────────────
|
||||
cat > "$INSTALL_DIR/config.json" << EOF
|
||||
{
|
||||
"server_url": "$JARVIS_URL",
|
||||
"host_header": "$JARVIS_HOST",
|
||||
"agent_id": "$AGENT_ID",
|
||||
"api_key": "$API_KEY",
|
||||
"agent_type": "$AGENT_TYPE",
|
||||
"heartbeat_interval": 10,
|
||||
"metrics_interval": 30
|
||||
}
|
||||
EOF
|
||||
|
||||
# ── Systemd service ────────────────────────────────────────────────────────────
|
||||
cat > "$SERVICE_FILE" << EOF
|
||||
[Unit]
|
||||
Description=JARVIS Agent
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 $INSTALL_DIR/jarvis-agent.py
|
||||
WorkingDirectory=$INSTALL_DIR
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StartLimitInterval=60
|
||||
StartLimitBurst=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable jarvis-agent
|
||||
systemctl restart jarvis-agent
|
||||
|
||||
echo "=== JARVIS Agent installed and running ==="
|
||||
echo "Config: $INSTALL_DIR/config.json"
|
||||
echo "Logs: journalctl -u jarvis-agent -f"
|
||||
systemctl is-active jarvis-agent
|
||||
Reference in New Issue
Block a user