mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
* added enum * add config for caddy * add svg icon * add caddy service class * wip * install caddy * create base Caddyfile with common snippets * Create a systemd service to run Caddy in the background. * create uninstall file * wip * create path * create vhost * get vhost * delete site * add php version change file * add custom ssl * create redirect file * add vhost for caddy site & load balancer * update svg * fix caddy icon * fix style * add systemctl reload method * Reload systemd after modifying the Caddy service file. * add caddy * added tests * format with pint * prevent multiple web server installations * added error log & access log
103 lines
2.3 KiB
PHP
103 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\SSH\Systemd;
|
|
|
|
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');
|
|
}
|
|
}
|