Drop restart-limit fields and enforcement from database resources, clear cached Traefik version data when proxies change, and show missing service environment variables from disabled deploy actions.
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
use App\Events\ServiceStatusChanged;
|
|
use App\Models\ServiceApplication;
|
|
use App\Models\ServiceDatabase;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class StopServiceApplication
|
|
{
|
|
use AsAction;
|
|
|
|
public string $jobQueue = 'high';
|
|
|
|
public function handle(ServiceApplication|ServiceDatabase $serviceApplication, bool $resetRestartCount = true, bool $removeContainer = false): void
|
|
{
|
|
$service = $serviceApplication->service;
|
|
$server = $service->destination->server;
|
|
$containerName = escapeshellarg($serviceApplication->name.'-'.$service->uuid);
|
|
|
|
if ($removeContainer) {
|
|
$commands = ["docker rm -f {$containerName}"];
|
|
} else {
|
|
$commands = [
|
|
"docker update --restart=no {$containerName}",
|
|
"docker stop {$containerName}",
|
|
];
|
|
}
|
|
instant_remote_process($commands, $server, throwError: ! $removeContainer);
|
|
|
|
$serviceApplication->update(['status' => 'exited']);
|
|
if ($resetRestartCount && $serviceApplication instanceof ServiceApplication) {
|
|
$serviceApplication->resetRestartLimit();
|
|
}
|
|
ServiceStatusChanged::dispatch($service->environment->project->team->id);
|
|
}
|
|
}
|