mirror of
https://github.com/coollabsio/coolify.git
synced 2025-12-28 05:34:50 +00:00
When a database or application was in a restart loop, the restart count persisted even after the user manually stopped the resource. This caused the UI to continue showing "(Xx restarts)" after user intervention. Now resets restart_count, last_restart_at, and last_restart_type when: - User stops a database (StopDatabase action) - User stops an application (StopApplication action) The existing reset in GetContainersStatus is still needed for containers that exit on their own (crash without recovery, Docker giving up). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Application;
|
|
|
|
use App\Actions\Server\CleanupDocker;
|
|
use App\Events\ServiceStatusChanged;
|
|
use App\Models\Application;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class StopApplication
|
|
{
|
|
use AsAction;
|
|
|
|
public string $jobQueue = 'high';
|
|
|
|
public function handle(Application $application, bool $previewDeployments = false, bool $dockerCleanup = true)
|
|
{
|
|
$servers = collect([$application->destination->server]);
|
|
if ($application?->additional_servers?->count() > 0) {
|
|
$servers = $servers->merge($application->additional_servers);
|
|
}
|
|
foreach ($servers as $server) {
|
|
try {
|
|
if (! $server->isFunctional()) {
|
|
return 'Server is not functional';
|
|
}
|
|
|
|
if ($server->isSwarm()) {
|
|
instant_remote_process(["docker stack rm {$application->uuid}"], $server);
|
|
|
|
return;
|
|
}
|
|
|
|
$containers = $previewDeployments
|
|
? getCurrentApplicationContainerStatus($server, $application->id, includePullrequests: true)
|
|
: getCurrentApplicationContainerStatus($server, $application->id, 0);
|
|
|
|
$containersToStop = $containers->pluck('Names')->toArray();
|
|
|
|
foreach ($containersToStop as $containerName) {
|
|
instant_remote_process(command: [
|
|
"docker stop -t 30 $containerName",
|
|
"docker rm -f $containerName",
|
|
], server: $server, throwError: false);
|
|
}
|
|
|
|
if ($application->build_pack === 'dockercompose') {
|
|
$application->deleteConnectedNetworks();
|
|
}
|
|
|
|
if ($dockerCleanup) {
|
|
CleanupDocker::dispatch($server, false, false);
|
|
}
|
|
} catch (\Exception $e) {
|
|
return $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Reset restart tracking when application is manually stopped
|
|
$application->update([
|
|
'restart_count' => 0,
|
|
'last_restart_at' => null,
|
|
'last_restart_type' => null,
|
|
]);
|
|
|
|
ServiceStatusChanged::dispatch($application->environment->project->team->id);
|
|
}
|
|
}
|