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 restart counter persistence and add crash loop example

Andras Bacsai01308dede5a4
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 6b13d2cb7a..d6a4e129f4 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -3980,6 +3980,15 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
*/
private function handleSuccessfulDeployment(): void
{
+ // Reset restart count after successful deployment
+ // This is done here (not in Livewire) to avoid race conditions
+ // with GetContainersStatus reading old container restart counts
+ $this->application->update([
+ 'restart_count' => 0,
+ 'last_restart_at' => null,
+ 'last_restart_type' => null,
+ ]);
+
event(new ApplicationConfigurationChanged($this->application->team()->id));
if (! $this->only_this_server) {
diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php
index fc63c7f4bc..ec6b64492b 100644
--- a/app/Livewire/Project/Application/Heading.php
+++ b/app/Livewire/Project/Application/Heading.php
@@ -106,13 +106,6 @@ class Heading extends Component
return;
}
- // Reset restart count on successful deployment
- $this->application->update([
- 'restart_count' => 0,
- 'last_restart_at' => null,
- 'last_restart_type' => null,
- ]);
-
return $this->redirectRoute('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
@@ -157,13 +150,6 @@ class Heading extends Component
return;
}
- // Reset restart count on manual restart
- $this->application->update([
- 'restart_count' => 0,
- 'last_restart_at' => now(),
- 'last_restart_type' => 'manual',
- ]);
-
return $this->redirectRoute('project.application.deployment.show', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php
index f012c1534a..ef5b4869d5 100644
--- a/database/seeders/ApplicationSeeder.php
+++ b/database/seeders/ApplicationSeeder.php
@@ -75,6 +75,22 @@ class ApplicationSeeder extends Seeder
'dockerfile' => 'FROM nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+',
+ ]);
+ Application::create([
+ 'name' => 'Crash Loop Example',
+ 'git_repository' => 'coollabsio/coolify',
+ 'git_branch' => 'v4.x',
+ 'git_commit_sha' => 'HEAD',
+ 'build_pack' => 'dockerfile',
+ 'ports_exposes' => '80',
+ 'environment_id' => 1,
+ 'destination_id' => 0,
+ 'destination_type' => StandaloneDocker::class,
+ 'source_id' => 0,
+ 'source_type' => GithubApp::class,
+ 'dockerfile' => 'FROM alpine
+CMD ["sh", "-c", "echo Crashing in 5 seconds... && sleep 5 && exit 1"]
',
]);
}