35 lines
1001 B
PHP
35 lines
1001 B
PHP
<?php
|
|
/**
|
|
* Server Supervisor Cron - Run every 5 minutes
|
|
* Checks all active servers for issues and auto-terminates burned ones
|
|
*/
|
|
$startTime = microtime(true);
|
|
echo date('Y-m-d H:i:s') . " - Starting server supervision...\n";
|
|
|
|
// Call the supervisor API
|
|
$ch = curl_init('http://localhost:5821/api/server-supervisor.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => 'action=check_all',
|
|
CURLOPT_TIMEOUT => 120
|
|
]);
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$result = json_decode($response, true);
|
|
|
|
$elapsed = round(microtime(true) - $startTime, 2);
|
|
echo date('Y-m-d H:i:s') . " - Checked {$result['checked']} servers in {$elapsed}s\n";
|
|
|
|
// Log any actions taken
|
|
if (!empty($result['results'])) {
|
|
foreach ($result['results'] as $r) {
|
|
if (!empty($r['actions'])) {
|
|
echo " - {$r['ip']}: " . json_encode($r['actions']) . "\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . " - Supervision complete\n";
|