Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: add runRemoteCommandSync

Andras Bacsai47d3ac3ef546
diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php
index 2f1fece581..b3432d3ec3 100644
--- a/app/Jobs/ContainerStatusJob.php
+++ b/app/Jobs/ContainerStatusJob.php
@@ -32,10 +32,7 @@ class ContainerStatusJob implements ShouldQueue
$not_found_applications = $applications;
$containers = collect();
foreach ($servers as $server) {
- $private_key_location = savePrivateKey($server);
- $ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, 'docker ps -a -q --format \'{{json .}}\'');
- $process = Process::run($ssh_command);
- $output = trim($process->output());
+ $output = runRemoteCommandSync($server, ['docker ps -a -q --format \'{{json .}}\'']);
$containers = $containers->concat(formatDockerCmdOutputToJson($output));
}
foreach ($containers as $container) {
@@ -48,13 +45,13 @@ class ContainerStatusJob implements ShouldQueue
});
$found_application->status = $container['State'];
$found_application->save();
- Log::info('Found application: ' . $found_application->uuid . '.Set status to: ' . $found_application->status);
+ Log::info('Found application: ' . $found_application->uuid . '. Set status to: ' . $found_application->status);
}
}
foreach ($not_found_applications as $not_found_application) {
$not_found_application->status = 'exited';
$not_found_application->save();
- Log::info('Not found application: ' . $not_found_application->uuid . '.Set status to: ' . $not_found_application->status);
+ Log::info('Not found application: ' . $not_found_application->uuid . '. Set status to: ' . $not_found_application->status);
}
} catch (\Exception $e) {
Log::error($e->getMessage());
diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php
index dad1269630..b613cf1096 100644
--- a/bootstrap/helpers.php
+++ b/bootstrap/helpers.php
@@ -7,6 +7,7 @@ use App\Models\Server;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Contracts\Activity;
@@ -113,3 +114,18 @@ if (!function_exists('formatDockerLabelsToJson')) {
})[0];
}
}
+if (!function_exists('runRemoteCommandSync')) {
+ function runRemoteCommandSync($server, array $command) {
+ $command_string = implode("\n", $command);
+ $private_key_location = savePrivateKey($server);
+ $ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, $command_string);
+ $process = Process::run($ssh_command);
+ $output = trim($process->output());
+ $exitCode = $process->exitCode();
+ if ($exitCode !== 0) {
+ Log::error($output);
+ throw new \RuntimeException('There was an error running the command.');
+ }
+ return $output;
+ }
+}