fix: add timeout for ssh commands
This commit is contained in:
parent
0924070a13
commit
1efb1235b4
@ -10,9 +10,6 @@
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
const TIMEOUT = 3600;
|
||||
const IDLE_TIMEOUT = 3600;
|
||||
|
||||
class RunRemoteProcess
|
||||
{
|
||||
public Activity $activity;
|
||||
@ -76,8 +73,7 @@ public function __invoke(): ProcessResult
|
||||
$this->time_start = hrtime(true);
|
||||
|
||||
$status = ProcessStatus::IN_PROGRESS;
|
||||
|
||||
$processResult = Process::timeout(TIMEOUT)->idleTimeout(IDLE_TIMEOUT)->run($this->getCommand(), $this->handleOutput(...));
|
||||
$processResult = Process::forever()->run($this->getCommand(), $this->handleOutput(...));
|
||||
|
||||
if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
|
||||
$status = ProcessStatus::ERROR;
|
||||
|
@ -56,7 +56,7 @@ public function validateServer()
|
||||
$this->uptime = $uptime;
|
||||
$this->emit('success', 'Server is reachable!');
|
||||
} else {
|
||||
$this->emit('error', 'Server is not rachable');
|
||||
$this->emit('error', 'Server is not reachable');
|
||||
return;
|
||||
}
|
||||
if ($dockerVersion) {
|
||||
|
@ -71,8 +71,12 @@ function save_private_key_for_server(Server $server)
|
||||
|
||||
function generate_ssh_command(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true)
|
||||
{
|
||||
$timeout = config('constants.ssh.command_timeout');
|
||||
$connectionTimeout = config('constants.ssh.connection_timeout');
|
||||
$serverInterval = config('constants.ssh.server_interval');
|
||||
|
||||
$delimiter = 'EOF-COOLIFY-SSH';
|
||||
$ssh_command = "ssh ";
|
||||
$ssh_command = "timeout $timeout ssh ";
|
||||
|
||||
if ($isMux && config('coolify.mux_enabled')) {
|
||||
$ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/ssh/mux/%h_%p_%r ';
|
||||
@ -81,8 +85,8 @@ function generate_ssh_command(string $private_key_location, string $server_ip, s
|
||||
$ssh_command .= "-i {$private_key_location} "
|
||||
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
|
||||
. '-o PasswordAuthentication=no '
|
||||
. '-o ConnectTimeout=3600 '
|
||||
. '-o ServerAliveInterval=20 '
|
||||
. "-o ConnectTimeout=$connectionTimeout "
|
||||
. "-o ServerAliveInterval=$serverInterval "
|
||||
. '-o RequestTTY=no '
|
||||
. '-o LogLevel=ERROR '
|
||||
. "-p {$port} "
|
||||
@ -90,7 +94,7 @@ function generate_ssh_command(string $private_key_location, string $server_ip, s
|
||||
. " 'bash -se' << \\$delimiter" . PHP_EOL
|
||||
. $command . PHP_EOL
|
||||
. $delimiter;
|
||||
|
||||
ray($ssh_command);
|
||||
return $ssh_command;
|
||||
}
|
||||
function instantCommand(string $command, $throwError = true) {
|
||||
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
return [
|
||||
'ssh' =>[
|
||||
'connection_timeout' => 10,
|
||||
'server_interval' => 20,
|
||||
'command_timeout' => 7200,
|
||||
],
|
||||
'waitlist' => [
|
||||
'expiration' => 10,
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user