mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-16 01:32:39 -04:00
- A Compose bind volume with a Coolify `content:` block could make Coolify write any host file (for example /root/.ssh/authorized_keys) when the file was loaded. Content sources must now be inside the resource directory (./ paths); other sources get a clear validation error for services and applications (UI, API, load, deployment), and every content write is confined again on the server. Bind mounts without content are unchanged. All 94 template content volumes use ./ paths and still work. - Quote container names in scheduled tasks and in the stop actions for applications, previews, and services. - Fix a development-only crash when a preview with a bind mount was parsed (the preview suffix returned a plain string). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
2.9 KiB
PHP
84 lines
2.9 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, bool $resetRestartCount = true, bool $removeContainers = true): ?string
|
|
{
|
|
$containerPresent = ! $removeContainers;
|
|
$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()) {
|
|
$containerPresent = false;
|
|
instant_remote_process(['docker stack rm '.escapeshellarg($application->uuid)], $server);
|
|
|
|
continue;
|
|
}
|
|
|
|
$containers = $previewDeployments
|
|
? getCurrentApplicationContainerStatus($server, $application->id, includePullrequests: true)
|
|
: getCurrentApplicationContainerStatus($server, $application->id, 0);
|
|
|
|
$containersToStop = $containers->pluck('Names')->toArray();
|
|
$timeout = $application->settings->stopGracePeriodSeconds();
|
|
|
|
foreach ($containersToStop as $containerName) {
|
|
$escapedContainerName = escapeshellarg($containerName);
|
|
$commands = [dockerStopCommand($timeout, $escapedContainerName, $server)];
|
|
if ($removeContainers) {
|
|
$commands[] = "docker rm -f {$escapedContainerName}";
|
|
}
|
|
|
|
instant_remote_process(command: $commands, server: $server, throwError: false);
|
|
}
|
|
|
|
if ($removeContainers && $application->build_pack === 'dockercompose') {
|
|
$application->deleteConnectedNetworks();
|
|
}
|
|
|
|
if ($dockerCleanup) {
|
|
CleanupDocker::dispatch($server, false, false);
|
|
}
|
|
} catch (\Exception $e) {
|
|
return $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$status = [
|
|
'status' => 'exited',
|
|
'container_present' => $containerPresent,
|
|
];
|
|
if ($resetRestartCount) {
|
|
$status = array_merge($status, [
|
|
'restart_count' => 0,
|
|
'last_restart_at' => null,
|
|
'last_restart_type' => null,
|
|
'restart_limit_reached' => false,
|
|
]);
|
|
}
|
|
$application->update($status);
|
|
|
|
ServiceStatusChanged::dispatch($application->environment->project->team->id);
|
|
|
|
return null;
|
|
}
|
|
}
|