fix: proxy status
fix: start proxy in case any dns set somewhere
This commit is contained in:
@@ -12,6 +12,7 @@ class InstallProxy
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use Livewire\Component;
|
||||
|
||||
class Status extends Component
|
||||
{
|
||||
public Application $application;
|
||||
|
||||
public function applicationStatusChanged()
|
||||
{
|
||||
$this->application->refresh();
|
||||
$this->emit('applicationStatusChanged');
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class Form extends Component
|
||||
} else {
|
||||
$this->server->settings->is_usable = true;
|
||||
$this->server->settings->save();
|
||||
$this->emit('serverValidated');
|
||||
$this->emit('proxyStatusUpdated');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->server->settings->is_reachable = false;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Http\Livewire\Server;
|
||||
|
||||
use App\Actions\Proxy\CheckProxySettingsInSync;
|
||||
use App\Actions\Proxy\InstallProxy;
|
||||
use App\Enums\ProxyTypes;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Server;
|
||||
@@ -17,12 +16,12 @@ class Proxy extends Component
|
||||
public $proxy_settings = null;
|
||||
public string|null $redirect_url = null;
|
||||
|
||||
protected $listeners = ['serverValidated', 'saveConfiguration'];
|
||||
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration'];
|
||||
public function mount()
|
||||
{
|
||||
$this->redirect_url = $this->server->proxy->redirect_url;
|
||||
}
|
||||
public function serverValidated()
|
||||
public function proxyStatusUpdated()
|
||||
{
|
||||
$this->server->refresh();
|
||||
}
|
||||
@@ -44,7 +43,7 @@ class Proxy extends Component
|
||||
], $this->server);
|
||||
$this->server->proxy->status = 'exited';
|
||||
$this->server->save();
|
||||
$this->server->refresh();
|
||||
$this->emit('proxyStatusUpdated');
|
||||
}
|
||||
public function saveConfiguration()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ class Deploy extends Component
|
||||
{
|
||||
public Server $server;
|
||||
public $proxy_settings = null;
|
||||
protected $listeners = ['proxyStatusUpdated', 'serverValidated' => 'proxyStatusUpdated'];
|
||||
protected $listeners = ['proxyStatusUpdated'];
|
||||
public function proxyStatusUpdated()
|
||||
{
|
||||
$this->server->refresh();
|
||||
|
||||
@@ -9,7 +9,7 @@ use Livewire\Component;
|
||||
class Status extends Component
|
||||
{
|
||||
public Server $server;
|
||||
protected $listeners = ['proxyStatusUpdated', 'serverValidated' => 'proxyStatusUpdated'];
|
||||
protected $listeners = ['proxyStatusUpdated'];
|
||||
public function proxyStatusUpdated()
|
||||
{
|
||||
$this->server->refresh();
|
||||
@@ -17,7 +17,7 @@ class Status extends Component
|
||||
public function proxyStatus()
|
||||
{
|
||||
try {
|
||||
dispatch(new ProxyContainerStatusJob(
|
||||
dispatch_sync(new ProxyContainerStatusJob(
|
||||
server: $this->server
|
||||
));
|
||||
$this->emit('proxyStatusUpdated');
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Livewire\Settings;
|
||||
|
||||
use App\Actions\Proxy\InstallProxy;
|
||||
use App\Jobs\ProxyCheckJob;
|
||||
use App\Models\InstanceSettings as ModelsInstanceSettings;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Component;
|
||||
use Spatie\Url\Url;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
@@ -108,6 +108,7 @@ class Configuration extends Component
|
||||
];
|
||||
}
|
||||
$this->save_configuration_to_disk($traefik_dynamic_conf, $file);
|
||||
dispatch(new ProxyCheckJob($this->server));
|
||||
}
|
||||
}
|
||||
private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file)
|
||||
@@ -137,12 +138,8 @@ class Configuration extends Component
|
||||
}
|
||||
$this->validate();
|
||||
$this->settings->save();
|
||||
|
||||
$this->server = Server::findOrFail(0);
|
||||
$this->setup_instance_fqdn();
|
||||
if ($this->settings->fqdn) {
|
||||
dispatch(new ProxyCheckJob());
|
||||
}
|
||||
$this->emit('success', 'Instance settings updated successfully!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class ApplicationDeploymentJob implements ShouldQueue
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
ray()->measure();
|
||||
// ray()->measure();
|
||||
$this->application_deployment_queue->update([
|
||||
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
|
||||
]);
|
||||
@@ -117,6 +117,7 @@ class ApplicationDeploymentJob implements ShouldQueue
|
||||
} else {
|
||||
$this->deploy();
|
||||
}
|
||||
if ($this->application->fqdn) dispatch(new ProxyCheckJob($this->server));
|
||||
$this->next(ApplicationDeploymentStatus::FINISHED->value);
|
||||
} catch (\Exception $e) {
|
||||
ray($e);
|
||||
@@ -131,7 +132,7 @@ class ApplicationDeploymentJob implements ShouldQueue
|
||||
"hidden" => true,
|
||||
]
|
||||
);
|
||||
ray()->measure();
|
||||
// ray()->measure();
|
||||
}
|
||||
}
|
||||
public function failed(Throwable $exception): void
|
||||
@@ -647,4 +648,4 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
||||
);
|
||||
$this->commit = $this->saved_outputs->get('git_commit_sha');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,30 +15,33 @@ class ProxyCheckJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(protected Server|null $server)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$container_name = 'coolify-proxy';
|
||||
$servers = Server::whereRelation('settings', 'is_usable', true)->where('proxy->type', ProxyTypes::TRAEFIK_V2)->get();
|
||||
|
||||
foreach ($servers as $server) {
|
||||
$status = get_container_status(server: $server, container_id: $container_name);
|
||||
if ($this->server) {
|
||||
ray('Checking proxy for server: ' . $this->server->name);
|
||||
$status = get_container_status(server: $this->server, container_id: $container_name);
|
||||
if ($status === 'running') {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
resolve(InstallProxy::class)($this->server);
|
||||
} else {
|
||||
$servers = Server::whereRelation('settings', 'is_usable', true)->get();
|
||||
|
||||
foreach ($servers as $server) {
|
||||
$status = get_container_status(server: $server, container_id: $container_name);
|
||||
if ($status === 'running') {
|
||||
continue;
|
||||
}
|
||||
resolve(InstallProxy::class)($server);
|
||||
}
|
||||
resolve(InstallProxy::class)($server);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
ray($th->getMessage());
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique
|
||||
$this->server->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
ray($e->getMessage());
|
||||
if ($e->getCode() === 1) {
|
||||
$this->server->proxy->status = 'exited';
|
||||
$this->server->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user