vito/app/SSH/Systemd/Systemd.php
Saeed Vaziry cdbde063f0
use blade as conmmands template (#444)
* use blade as conmmands template

* fix lint

* fix ssl
2025-01-27 21:27:58 +01:00

91 lines
2.0 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));
}
}