51 lines
1.8 KiB
PHP
51 lines
1.8 KiB
PHP
<?php
|
|
// WEVIA DOCKER AUTO-FIX v1.0
|
|
// Called by wevia-autonomous.php and Director cron
|
|
// Detects crashed Docker containers and auto-restarts them
|
|
|
|
function wevia_docker_autofix() {
|
|
$count = intval(trim(shell_exec("docker ps -q 2>/dev/null | wc -l")));
|
|
if ($count >= 14) return null; // 16 containers = normal (Authentik disabled)
|
|
|
|
$fixed = [];
|
|
|
|
// Check for exited containers (NOT Authentik — intentionally disabled)
|
|
$exited = trim(shell_exec("docker ps -a --filter status=exited --format '{{.Names}}' 2>/dev/null"));
|
|
if (!empty($exited)) {
|
|
shell_exec("docker ps -a --filter status=exited --format '{{.Names}}' | xargs -r docker start 2>/dev/null");
|
|
$fixed[] = "restarted: $exited";
|
|
}
|
|
|
|
// Check critical services
|
|
$critical = ['n8n', 'qdrant', 'searxng', 'uptime-kuma', 'vaultwarden', 'prometheus'];
|
|
foreach ($critical as $svc) {
|
|
$running = trim(shell_exec("docker ps --filter name=$svc --format '{{.Names}}' 2>/dev/null"));
|
|
if (empty($running)) {
|
|
shell_exec("docker start $svc 2>/dev/null");
|
|
$fixed[] = "started: $svc";
|
|
}
|
|
}
|
|
|
|
if (empty($fixed)) return null;
|
|
|
|
return [
|
|
'fixed' => true,
|
|
'was_running' => $count,
|
|
'exited_containers' => $exited ?: 'none',
|
|
'actions' => $fixed,
|
|
'timestamp' => date('c'),
|
|
];
|
|
}
|
|
|
|
// If called directly: run and report
|
|
if (basename($_SERVER['SCRIPT_FILENAME'] ?? '') === 'wevia-docker-autofix.php') {
|
|
header("Content-Type: application/json");
|
|
$result = wevia_docker_autofix();
|
|
if ($result) {
|
|
echo json_encode($result, JSON_PRETTY_PRINT);
|
|
} else {
|
|
$count = intval(trim(shell_exec("docker ps -q 2>/dev/null | wc -l")));
|
|
echo json_encode(["status" => "ok", "containers" => $count]);
|
|
}
|
|
}
|