diff --git a/app/Actions/Proxy/InstallProxy.php b/app/Actions/Proxy/StartProxy.php similarity index 99% rename from app/Actions/Proxy/InstallProxy.php rename to app/Actions/Proxy/StartProxy.php index 1e2369f8a..2050e2ca1 100644 --- a/app/Actions/Proxy/InstallProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -8,7 +8,7 @@ use App\Models\Server; use Spatie\Activitylog\Models\Activity; use Illuminate\Support\Str; -class InstallProxy +class StartProxy { public function __invoke(Server $server): Activity { diff --git a/app/Http/Controllers/MagicController.php b/app/Http/Controllers/MagicController.php index 66dcf5549..c4f77805a 100644 --- a/app/Http/Controllers/MagicController.php +++ b/app/Http/Controllers/MagicController.php @@ -13,7 +13,7 @@ class MagicController extends Controller public function servers() { return response()->json([ - 'servers' => Server::validated()->get() + 'servers' => Server::isUsable()->get() ]); } public function destinations() diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index e790e3565..5d3c1ebba 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -27,14 +27,16 @@ class Proxy extends Component } public function switchProxy() { - $this->server->proxy->type = null; + $this->server->proxy = null; $this->server->save(); + $this->emit('proxyStatusUpdated'); } public function setProxy(string $proxy_type) { $this->server->proxy->type = $proxy_type; $this->server->proxy->status = 'exited'; $this->server->save(); + $this->emit('proxyStatusUpdated'); } public function stopProxy() { diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.php index afb7202a4..c1ca4ab57 100644 --- a/app/Http/Livewire/Server/Proxy/Deploy.php +++ b/app/Http/Livewire/Server/Proxy/Deploy.php @@ -2,7 +2,7 @@ namespace App\Http\Livewire\Server\Proxy; -use App\Actions\Proxy\InstallProxy; +use App\Actions\Proxy\StartProxy; use App\Models\Server; use Livewire\Component; use Str; @@ -24,7 +24,7 @@ class Deploy extends Component ) { $this->saveConfiguration($this->server); } - $activity = resolve(InstallProxy::class)($this->server); + $activity = resolve(StartProxy::class)($this->server); $this->emit('newMonitorActivity', $activity->id); } public function stop() diff --git a/app/Http/Livewire/Settings/Configuration.php b/app/Http/Livewire/Settings/Configuration.php index a5c9ad335..98371d136 100644 --- a/app/Http/Livewire/Settings/Configuration.php +++ b/app/Http/Livewire/Settings/Configuration.php @@ -2,8 +2,7 @@ namespace App\Http\Livewire\Settings; -use App\Actions\Proxy\InstallProxy; -use App\Jobs\ProxyCheckJob; +use App\Jobs\ProxyStartJob; use App\Models\InstanceSettings as ModelsInstanceSettings; use App\Models\Server; use Livewire\Component; @@ -108,7 +107,7 @@ class Configuration extends Component ]; } $this->save_configuration_to_disk($traefik_dynamic_conf, $file); - dispatch(new ProxyCheckJob($this->server)); + dispatch(new ProxyStartJob($this->server)); } } private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index d9e080648..a800d7c2e 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -117,7 +117,7 @@ class ApplicationDeploymentJob implements ShouldQueue } else { $this->deploy(); } - if ($this->application->fqdn) dispatch(new ProxyCheckJob($this->server)); + if ($this->application->fqdn) dispatch(new ProxyStartJob($this->server)); $this->next(ApplicationDeploymentStatus::FINISHED->value); } catch (\Exception $e) { ray($e); diff --git a/app/Jobs/ProxyCheckJob.php b/app/Jobs/ProxyCheckJob.php index dbe785d96..ab04d3d07 100755 --- a/app/Jobs/ProxyCheckJob.php +++ b/app/Jobs/ProxyCheckJob.php @@ -2,7 +2,7 @@ namespace App\Jobs; -use App\Actions\Proxy\InstallProxy; +use App\Actions\Proxy\StartProxy; use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Bus\Queueable; @@ -15,30 +15,20 @@ class ProxyCheckJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public function __construct(protected Server|null $server = null) + public function __construct() { } public function handle() { try { $container_name = 'coolify-proxy'; - if ($this->server) { - ray('Checking proxy for server: ' . $this->server->name); - $status = get_container_status(server: $this->server, container_id: $container_name); + $servers = Server::isUsable()->whereNotNull('proxy')->get(); + foreach ($servers as $server) { + $status = get_container_status(server: $server, container_id: $container_name); if ($status === 'running') { - 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); + continue; } + resolve(StartProxy::class)($server); } } catch (\Throwable $th) { ray($th->getMessage()); diff --git a/app/Jobs/ProxyStartJob.php b/app/Jobs/ProxyStartJob.php new file mode 100755 index 000000000..074d21664 --- /dev/null +++ b/app/Jobs/ProxyStartJob.php @@ -0,0 +1,35 @@ +server->name); + $status = get_container_status(server: $this->server, container_id: $container_name); + if ($status === 'running') { + return; + } + resolve(StartProxy::class)($this->server); + } catch (\Throwable $th) { + ray($th->getMessage()); + //throw $th; + } + } +} diff --git a/app/Models/Server.php b/app/Models/Server.php index 0d21e80b0..31e2d1e5c 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -94,10 +94,14 @@ class Server extends BaseModel return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all())->orderBy('name'); } - static public function validated() + static public function isReachable() { return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true); } + static public function isUsable() + { + return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true)->whereRelation('settings', 'is_usable', true); + } static public function destinationsByServer(string $server_id) { @@ -106,4 +110,4 @@ class Server extends BaseModel $swarmDocker = collect($server->swarmDockers->all()); return $standaloneDocker->concat($swarmDocker); } -} \ No newline at end of file +} diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index e43092b12..82ab2552b 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use App\Actions\Proxy\InstallProxy; use App\Data\ServerMetadata; use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; diff --git a/database/seeders/ServerSettingSeeder.php b/database/seeders/ServerSettingSeeder.php index f2d8c9b49..fe366ba77 100644 --- a/database/seeders/ServerSettingSeeder.php +++ b/database/seeders/ServerSettingSeeder.php @@ -16,12 +16,14 @@ class ServerSettingSeeder extends Seeder $server_2 = Server::find(0)->load(['settings']); $server_2->settings->wildcard_domain = 'http://127.0.0.1.sslip.io'; $server_2->settings->is_build_server = true; + $server_2->settings->is_usable = true; $server_2->settings->is_reachable = true; $server_2->settings->save(); $server_3 = Server::find(1)->load(['settings']); $server_3->settings->is_part_of_swarm = false; + $server_2->settings->is_usable = false; $server_3->settings->is_reachable = false; $server_3->settings->save(); } -} \ No newline at end of file +} diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index 5fe9b0759..dcfd76dbb 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -26,11 +26,9 @@ ]) }}"> - @if ($server->settings->is_reachable) - @if (request()->routeIs('server.proxy')) -
-