mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 17:02:34 +00:00
Plugins base (#613)
* wip * wip * cleanup * notification channels * phpstan * services * remove server types * refactoring * refactoring
This commit is contained in:
24
app/SSH/OS/Composer.php
Normal file
24
app/SSH/OS/Composer.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\OS;
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Models\Site;
|
||||
|
||||
class Composer
|
||||
{
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function installDependencies(Site $site): void
|
||||
{
|
||||
$site->server->ssh($site->user)->exec(
|
||||
view('ssh.composer.composer-install', [
|
||||
'path' => $site->path,
|
||||
'phpVersion' => $site->php_version,
|
||||
]),
|
||||
'composer-install',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
}
|
25
app/SSH/OS/Cron.php
Normal file
25
app/SSH/OS/Cron.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\OS;
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Models\Server;
|
||||
|
||||
class Cron
|
||||
{
|
||||
public function __construct(protected Server $server) {}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function update(string $user, string $cron): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
view('ssh.cron.update', [
|
||||
'cron' => $cron,
|
||||
'user' => $user,
|
||||
]),
|
||||
'update-cron'
|
||||
);
|
||||
}
|
||||
}
|
56
app/SSH/OS/Git.php
Normal file
56
app/SSH/OS/Git.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\OS;
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Models\Site;
|
||||
|
||||
class Git
|
||||
{
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function clone(Site $site): void
|
||||
{
|
||||
$site->server->ssh($site->user)->exec(
|
||||
view('ssh.git.clone', [
|
||||
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
|
||||
'repo' => $site->getFullRepositoryUrl(),
|
||||
'path' => $site->path,
|
||||
'branch' => $site->branch,
|
||||
'key' => $site->getSshKeyName(),
|
||||
]),
|
||||
'clone-repository',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function checkout(Site $site): void
|
||||
{
|
||||
$site->server->ssh($site->user)->exec(
|
||||
view('ssh.git.checkout', [
|
||||
'path' => $site->path,
|
||||
'branch' => $site->branch,
|
||||
]),
|
||||
'checkout-branch',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function fetchOrigin(Site $site): void
|
||||
{
|
||||
$site->server->ssh($site->user)->exec(
|
||||
view('ssh.git.fetch-origin', [
|
||||
'path' => $site->path,
|
||||
]),
|
||||
'fetch-origin',
|
||||
$site->id
|
||||
);
|
||||
}
|
||||
}
|
@ -225,7 +225,7 @@ public function tail(string $path, int $lines): string
|
||||
public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog
|
||||
{
|
||||
$ssh = $this->server->ssh($user);
|
||||
if ($serverLog instanceof \App\Models\ServerLog) {
|
||||
if ($serverLog instanceof ServerLog) {
|
||||
$ssh->setLog($serverLog);
|
||||
}
|
||||
$command = '';
|
||||
|
102
app/SSH/OS/Systemd.php
Normal file
102
app/SSH/OS/Systemd.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\OS;
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Models\Server;
|
||||
|
||||
class Systemd
|
||||
{
|
||||
public function __construct(protected Server $server) {}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function status(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function start(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl start $unit
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function stop(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl stop $unit
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function restart(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl restart $unit
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function enable(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl start $unit
|
||||
sudo systemctl enable $unit
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function disable(string $unit): string
|
||||
{
|
||||
$command = <<<EOD
|
||||
sudo systemctl stop $unit
|
||||
sudo systemctl disable $unit
|
||||
sudo systemctl status $unit | cat
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, sprintf('disable-%s', $unit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function reload(): string
|
||||
{
|
||||
$command = <<<'EOD'
|
||||
sudo systemctl daemon-reload
|
||||
EOD;
|
||||
|
||||
return $this->server->ssh()->exec($command, 'reload-systemctl');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user