vito/app/Jobs/Installation/InstallUfw.php
2024-02-05 00:23:44 +01:00

36 lines
884 B
PHP
Executable File

<?php
namespace App\Jobs\Installation;
use App\Enums\ServiceStatus;
use App\Exceptions\InstallationFailed;
use App\Models\Service;
use App\SSHCommands\Firewall\InstallUfwCommand;
use App\SSHCommands\Service\ServiceStatusCommand;
use Throwable;
class InstallUfw extends InstallationJob
{
protected Service $service;
public function __construct(Service $service)
{
$this->service = $service;
}
/**
* @throws InstallationFailed
* @throws Throwable
*/
public function handle(): void
{
$ssh = $this->service->server->ssh();
$ssh->exec(new InstallUfwCommand(), 'install-ufw');
$status = $ssh->exec(new ServiceStatusCommand($this->service->unit), 'ufw-status');
$this->service->validateInstall($status);
$this->service->update([
'status' => ServiceStatus::READY,
]);
}
}