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.

fix(service): graceful shutdown of old container (#5731)

Jérémyab37d4e51048
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 7c34271a7c..d79e09151f 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -2249,28 +2249,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
private function graceful_shutdown_container(string $containerName, int $timeout = 300)
{
try {
- $process = Process::timeout($timeout)->start("docker stop --time=$timeout $containerName");
-
- $startTime = time();
- while ($process->running()) {
- if (time() - $startTime >= $timeout) {
- $this->execute_remote_command(
- ["docker kill $containerName", 'hidden' => true, 'ignore_errors' => true]
- );
- break;
- }
- usleep(100000);
- }
-
- $isRunning = $this->execute_remote_command(
- ["docker inspect -f '{{.State.Running}}' $containerName", 'hidden' => true, 'ignore_errors' => true]
- ) === 'true';
-
- if ($isRunning) {
- $this->execute_remote_command(
- ["docker kill $containerName", 'hidden' => true, 'ignore_errors' => true]
- );
- }
+ $this->execute_remote_command(
+ ["docker stop --time=$timeout $containerName", 'hidden' => true, 'ignore_errors' => true],
+ );
} catch (\Exception $error) {
$this->application_deployment_queue->addLogEntry("Error stopping container $containerName: ".$error->getMessage(), 'stderr');
}