fix: proxy start job

This commit is contained in:
Andras Bacsai 2023-09-01 10:02:24 +02:00
parent 3fabff93f6
commit f75a324030
5 changed files with 33 additions and 20 deletions

View File

@ -9,6 +9,7 @@ class SaveConfigurationSync
{ {
public function __invoke(Server $server, string $configuration) public function __invoke(Server $server, string $configuration)
{ {
try {
$proxy_path = get_proxy_path(); $proxy_path = get_proxy_path();
$docker_compose_yml_base64 = base64_encode($configuration); $docker_compose_yml_base64 = base64_encode($configuration);
@ -19,5 +20,9 @@ class SaveConfigurationSync
"mkdir -p $proxy_path", "mkdir -p $proxy_path",
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml", "echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
], $server); ], $server);
} catch (\Throwable $th) {
ray($th);
}
} }
} }

View File

@ -12,12 +12,6 @@ class StartProxy
{ {
public function __invoke(Server $server): Activity public function __invoke(Server $server): Activity
{ {
// TODO: check for other proxies
if (is_null(data_get($server, 'proxy.type'))) {
$server->proxy->type = ProxyTypes::TRAEFIK_V2->value;
$server->proxy->status = ProxyStatus::EXITED->value;
$server->save();
}
$proxy_path = get_proxy_path(); $proxy_path = get_proxy_path();
$networks = collect($server->standaloneDockers)->map(function ($docker) { $networks = collect($server->standaloneDockers)->map(function ($docker) {
return $docker['network']; return $docker['network'];

View File

@ -34,7 +34,13 @@ class DockerCleanupJob implements ShouldQueue
if (isDev()) { if (isDev()) {
$this->dockerRootFilesystem = "/"; $this->dockerRootFilesystem = "/";
} else { } else {
$this->dockerRootFilesystem = instant_remote_process(["stat --printf=%m $(docker info --format '{{json .DockerRootDir}}'' |sed 's/\"//g')"], $server, false); $this->dockerRootFilesystem = instant_remote_process(
[
"stat --printf=%m $(docker info --format '{{json .DockerRootDir}}'' |sed 's/\"//g')"
],
$server,
false
);
} }
if (!$this->dockerRootFilesystem) { if (!$this->dockerRootFilesystem) {
continue; continue;

View File

@ -33,9 +33,10 @@ class ProxyCheckJob implements ShouldQueue
if ($status === 'running') { if ($status === 'running') {
continue; continue;
} }
// $server->team->notify(new ProxyStoppedNotification($server)); if (data_get($server, 'proxy.type')) {
resolve(StartProxy::class)($server); resolve(StartProxy::class)($server);
} }
}
} catch (\Throwable $th) { } catch (\Throwable $th) {
ray($th->getMessage()); ray($th->getMessage());
send_internal_notification('ProxyCheckJob failed with: ' . $th->getMessage()); send_internal_notification('ProxyCheckJob failed with: ' . $th->getMessage());

View File

@ -3,6 +3,8 @@
namespace App\Jobs; namespace App\Jobs;
use App\Actions\Proxy\StartProxy; use App\Actions\Proxy\StartProxy;
use App\Enums\ProxyStatus;
use App\Enums\ProxyTypes;
use App\Models\Server; use App\Models\Server;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
@ -27,6 +29,11 @@ class ProxyStartJob implements ShouldQueue
if ($status === 'running') { if ($status === 'running') {
return; return;
} }
if (is_null(data_get($this->server, 'proxy.type'))) {
$this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value;
$this->server->proxy->status = ProxyStatus::EXITED->value;
$this->server->save();
}
resolve(StartProxy::class)($this->server); resolve(StartProxy::class)($this->server);
} catch (\Throwable $th) { } catch (\Throwable $th) {
send_internal_notification('ProxyStartJob failed with: ' . $th->getMessage()); send_internal_notification('ProxyStartJob failed with: ' . $th->getMessage());