mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 02:11:36 +00:00
46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Server;
|
|
|
|
use App\Events\Broadcast;
|
|
use App\Jobs\Job;
|
|
use App\Models\Server;
|
|
use App\SSHCommands\System\RebootCommand;
|
|
use Throwable;
|
|
|
|
class RebootServer extends Job
|
|
{
|
|
protected Server $server;
|
|
|
|
public function __construct(Server $server)
|
|
{
|
|
$this->server = $server;
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$this->server->ssh()->exec(new RebootCommand(), 'reboot');
|
|
event(
|
|
new Broadcast('reboot-server-finished', [
|
|
'message' => __('The server is being rebooted. It can take several minutes to boot up'),
|
|
'id' => $this->server->id,
|
|
])
|
|
);
|
|
}
|
|
|
|
public function failed(): void
|
|
{
|
|
$this->server->status = 'ready';
|
|
$this->server->save();
|
|
event(
|
|
new Broadcast('reboot-server-failed', [
|
|
'message' => __('Failed to reboot the server'),
|
|
'server' => $this->server,
|
|
])
|
|
);
|
|
}
|
|
}
|