coolify/app/Console/Commands/CleanupUnreachableServers.php

29 lines
930 B
PHP
Raw Normal View History

2024-01-30 10:50:54 +01:00
<?php
namespace App\Console\Commands;
use App\Models\Server;
use Illuminate\Console\Command;
class CleanupUnreachableServers extends Command
{
protected $signature = 'cleanup:unreachable-servers';
2024-06-10 22:43:34 +02:00
2024-02-23 21:51:43 +01:00
protected $description = 'Cleanup Unreachable Servers (7 days)';
2024-01-30 10:50:54 +01:00
public function handle()
{
echo "Running unreachable server cleanup...\n";
2024-02-23 21:51:43 +01:00
$servers = Server::where('unreachable_count', 3)->where('unreachable_notification_sent', true)->where('updated_at', '<', now()->subDays(7))->get();
2024-01-30 10:50:54 +01:00
if ($servers->count() > 0) {
foreach ($servers as $server) {
echo "Cleanup unreachable server ($server->id) with name $server->name";
// send_internal_notification("Server $server->name is unreachable for 7 days. Cleaning up...");
$server->update([
2024-06-10 22:43:34 +02:00
'ip' => '1.2.3.4',
]);
2024-01-30 10:50:54 +01:00
}
}
}
}