2026-03-29 03:03:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Service;
|
|
|
|
|
|
2026-08-15 09:46:49 +00:00
|
|
|
use App\Events\ServiceStatusChanged;
|
2026-03-29 03:03:47 +00:00
|
|
|
use App\Models\ServiceApplication;
|
2026-07-15 10:29:58 +00:00
|
|
|
use App\Models\ServiceDatabase;
|
2026-03-29 03:03:47 +00:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
|
|
class StopServiceApplication
|
|
|
|
|
{
|
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
|
|
public string $jobQueue = 'high';
|
|
|
|
|
|
2026-08-31 11:13:26 +00:00
|
|
|
public function handle(ServiceApplication|ServiceDatabase $serviceApplication, bool $resetRestartCount = true, bool $removeContainer = false): void
|
2026-03-29 03:03:47 +00:00
|
|
|
{
|
|
|
|
|
$service = $serviceApplication->service;
|
|
|
|
|
$server = $service->destination->server;
|
2026-07-07 13:10:24 +00:00
|
|
|
$containerName = escapeshellarg($serviceApplication->name.'-'.$service->uuid);
|
2026-03-29 03:03:47 +00:00
|
|
|
|
2026-08-31 11:13:26 +00:00
|
|
|
if ($removeContainer) {
|
|
|
|
|
$commands = ["docker rm -f {$containerName}"];
|
|
|
|
|
} else {
|
|
|
|
|
$commands = [
|
|
|
|
|
"docker update --restart=no {$containerName}",
|
|
|
|
|
"docker stop {$containerName}",
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
instant_remote_process($commands, $server, throwError: ! $removeContainer);
|
2026-08-15 09:46:49 +00:00
|
|
|
|
|
|
|
|
$serviceApplication->update(['status' => 'exited']);
|
2026-08-31 11:13:26 +00:00
|
|
|
if ($resetRestartCount) {
|
|
|
|
|
$serviceApplication->resetRestartLimit();
|
|
|
|
|
}
|
2026-08-15 09:46:49 +00:00
|
|
|
ServiceStatusChanged::dispatch($service->environment->project->team->id);
|
2026-03-29 03:03:47 +00:00
|
|
|
}
|
|
|
|
|
}
|