21 lines
484 B
PHP
21 lines
484 B
PHP
<?php
|
|
|
|
namespace App\Services\Operations;
|
|
|
|
use App\Models\Server;
|
|
use RuntimeException;
|
|
|
|
class SshRemoteCommandRunner implements RemoteCommandRunner
|
|
{
|
|
public function run(Server $server, string $script): string
|
|
{
|
|
$result = $server->sshClient()->execute($script);
|
|
|
|
if (! $result->isSuccessful()) {
|
|
throw new RuntimeException(trim($result->getErrorOutput()) ?: 'Remote command failed.');
|
|
}
|
|
|
|
return trim($result->getOutput());
|
|
}
|
|
}
|