Files
coolify/app/Actions/Server/RebootServer.php
T
Andras BacsaiandClaude Opus 5.5 3da85e2c07 feat(patches): mark security updates, reboot state, and risky packages
- Security updates: apt marks a package from a "-security" suite (Debian
  12 now reports oldstable-security). dnf reads `dnf updateinfo list
  --security` (dnf5 keeps updateinfo as an alias of advisory). zypper
  uses `zypper -x patch --dry-run --category security`, because
  `zypper -x list-patches` ignores --category and has no package names.
  pacman and apk cannot tell, so they show no security count.
  https://dnf5.readthedocs.io/en/latest/commands/advisory.8.html
  https://github.com/openSUSE/zypper/blob/master/doc/zypper.8.txt
- Reboot required: /var/run/reboot-required, `needrestart -b` (KSTA 2
  or 3), `dnf needs-restarting -r` (matched by text, because a missing
  plugin also exits 1), and `zypper needs-rebooting` (exit 102).
  https://github.com/liske/needrestart/blob/master/README.batch.md
  https://dnf-plugins-core.readthedocs.io/en/latest/needs_restarting.html
- An explicit risk list per package manager (Docker engine, kernels,
  libc/glibc/musl, systemd, dbus, openssh) replaces the "name contains
  docker/kernel" guess on the page and in every notification channel.
- The page shows security and reboot badges, a security count, and the
  risk of each package. "Reboot server" (with confirmation, update
  policy on the loaded server) schedules the reboot with systemd-run and
  checks the server again five minutes later. Archived (transferred)
  servers are never touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 10:39:51 +02:00

39 lines
1.4 KiB
PHP

<?php
namespace App\Actions\Server;
use App\Jobs\ServerPatchCheckJob;
use App\Models\Server;
use Lorisleiva\Actions\Concerns\AsAction;
class RebootServer
{
use AsAction;
/**
* Starts the reboot a few seconds later, so the SSH command returns before the connection drops.
* systemd-run runs the reboot outside of the SSH session; other systems use a detached `reboot`.
*/
public const COMMAND = <<<'SH'
sh -c 'if command -v systemd-run >/dev/null 2>&1; then systemd-run --on-active=5 --timer-property=AccuracySec=1s systemctl reboot >/dev/null 2>&1; else nohup sh -c "sleep 5; reboot" >/dev/null 2>&1 </dev/null & fi; echo REBOOT_SCHEDULED'
SH;
public function handle(Server $server): void
{
if ($server->isTransferredAway()) {
throw new \RuntimeException('This server is managed by another Coolify instance.');
}
if (! $server->isFunctional()) {
throw new \RuntimeException('Server is not reachable or not ready.');
}
$output = instant_remote_process([self::COMMAND], $server);
if (! str_contains((string) $output, 'REBOOT_SCHEDULED')) {
throw new \RuntimeException('The reboot could not be started.');
}
// Check again when the server is back, so the "Reboot required" state is cleared.
ServerPatchCheckJob::dispatch($server, true)->delay(now()->addMinutes(5));
}
}