Files
coolify/app/Actions/Service/StartService.php
2023-10-01 13:59:22 +02:00

34 lines
1.3 KiB
PHP

<?php
namespace App\Actions\Service;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Models\Service;
class StartService
{
use AsAction;
public function handle(Service $service)
{
$service->saveComposeConfigs();
$commands[] = "cd " . $service->workdir();
$commands[] = "echo '####### Saved configuration files to {$service->workdir()}.'";
if (is_null($service->destination)) {
$dockerNetwork = $service->uuid;
$commands[] = "echo '####### Creating Docker network.'";
$commands[] = "docker network create --attachable {$dockerNetwork} >/dev/null 2>/dev/null || true";
}
$commands[] = "echo '####### Starting service {$service->name} on {$service->server->name}.'";
$commands[] = "echo '####### Pulling images.'";
$commands[] = "docker compose pull";
$commands[] = "echo '####### Starting containers.'";
$commands[] = "docker compose up -d --remove-orphans --force-recreate";
if (is_null($service->destination)) {
$commands[] = "echo '####### Connecting to proxy network.'";
$commands[] = "docker network connect coolify-proxy {$dockerNetwork} 2>/dev/null || true";
}
$activity = remote_process($commands, $service->server);
return $activity;
}
}