mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
49
app/Jobs/Server/CheckConnection.php
Normal file
49
app/Jobs/Server/CheckConnection.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Server;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Server;
|
||||
use Throwable;
|
||||
|
||||
class CheckConnection extends Job
|
||||
{
|
||||
protected Server $server;
|
||||
|
||||
public function __construct(Server $server)
|
||||
{
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$status = $this->server->status;
|
||||
$this->server->ssh()->connect();
|
||||
$this->server->refresh();
|
||||
if ($status == 'disconnected') {
|
||||
$this->server->status = 'ready';
|
||||
$this->server->save();
|
||||
}
|
||||
event(
|
||||
new Broadcast('server-status-finished', [
|
||||
'server' => $this->server,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function failed(): void
|
||||
{
|
||||
$this->server->status = 'disconnected';
|
||||
$this->server->save();
|
||||
/** @todo notify */
|
||||
event(
|
||||
new Broadcast('server-status-failed', [
|
||||
'server' => $this->server,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
45
app/Jobs/Server/RebootServer.php
Normal file
45
app/Jobs/Server/RebootServer.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Server;
|
||||
|
||||
use App\Events\Broadcast;
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Server;
|
||||
use App\SSHCommands\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,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user