2023-07-14 11:38:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Actions\Proxy\StartProxy;
|
2023-09-01 08:02:24 +00:00
|
|
|
use App\Enums\ProxyStatus;
|
|
|
|
use App\Enums\ProxyTypes;
|
2023-07-14 11:38:24 +00:00
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
class ProxyStartJob implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
public function __construct(protected Server $server)
|
|
|
|
{
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-14 11:38:24 +00:00
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$container_name = 'coolify-proxy';
|
|
|
|
ray('Starting proxy for server: ' . $this->server->name);
|
2023-08-21 16:00:12 +00:00
|
|
|
$status = getContainerStatus(server: $this->server, container_id: $container_name);
|
2023-07-14 11:38:24 +00:00
|
|
|
if ($status === 'running') {
|
|
|
|
return;
|
|
|
|
}
|
2023-09-01 08:02:24 +00:00
|
|
|
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();
|
|
|
|
}
|
2023-07-14 11:38:24 +00:00
|
|
|
resolve(StartProxy::class)($this->server);
|
|
|
|
} catch (\Throwable $th) {
|
2023-08-24 14:14:09 +00:00
|
|
|
send_internal_notification('ProxyStartJob failed with: ' . $th->getMessage());
|
2023-07-14 11:38:24 +00:00
|
|
|
ray($th->getMessage());
|
2023-08-24 19:09:58 +00:00
|
|
|
throw $th;
|
2023-07-14 11:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|