diff --git a/app/Data/ServerMetadata.php b/app/Data/ServerMetadata.php index af4340b38..06f11f206 100644 --- a/app/Data/ServerMetadata.php +++ b/app/Data/ServerMetadata.php @@ -2,12 +2,15 @@ namespace App\Data; +use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; use Spatie\LaravelData\Data; class ServerMetadata extends Data { public function __construct( - public ?ProxyTypes $proxy, - ) {} + public ?ProxyTypes $proxy_type, + public ?ProxyStatus $proxy_status + ) { + } } diff --git a/app/Enums/ProxyTypes.php b/app/Enums/ProxyTypes.php index f664e8006..e94792188 100644 --- a/app/Enums/ProxyTypes.php +++ b/app/Enums/ProxyTypes.php @@ -8,3 +8,8 @@ enum ProxyTypes: string case NGINX = 'NGINX'; case CADDY = 'CADDY'; } +enum ProxyStatus: string +{ + case EXITED = 'exited'; + case RUNNING = 'running'; +} diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.php index 9dfd6b40c..ef6c969b6 100644 --- a/app/Http/Livewire/PrivateKey/Create.php +++ b/app/Http/Livewire/PrivateKey/Create.php @@ -8,27 +8,26 @@ use Livewire\Component; class Create extends Component { + protected string|null $from = null; public string $name; public string|null $description = null; public string $value; - public string $currentRoute; - public function mount() - { - $this->currentRoute = Route::current()->uri(); - } public function createPrivateKey() { $this->value = trim($this->value); if (!str_ends_with($this->value, "\n")) { $this->value .= "\n"; } - $new_private_key = PrivateKey::create([ + $private_key = PrivateKey::create([ 'name' => $this->name, 'description' => $this->description, 'private_key' => $this->value, 'team_id' => session('currentTeam')->id ]); - redirect()->route('server.new'); + if ($this->from === 'server') { + return redirect()->route('server.new'); + } + return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]); } } diff --git a/app/Http/Livewire/Server/PrivateKey.php b/app/Http/Livewire/Server/PrivateKey.php index dbc0474e8..e9d6cf072 100644 --- a/app/Http/Livewire/Server/PrivateKey.php +++ b/app/Http/Livewire/Server/PrivateKey.php @@ -5,6 +5,7 @@ namespace App\Http\Livewire\Server; use App\Models\PrivateKey as ModelsPrivateKey; use App\Models\Server; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\Storage; use Livewire\Component; class PrivateKey extends Component @@ -13,9 +14,13 @@ class PrivateKey extends Component public $parameters; public function setPrivateKey($private_key_id) { - Server::where('uuid', $this->parameters['server_uuid'])->update([ + $server = Server::where('uuid', $this->parameters['server_uuid']); + $server->update([ 'private_key_id' => $private_key_id ]); + // Delete the old ssh mux file to force a new one to be created + Storage::disk('local')->delete(".ssh/ssh_mux_{$server->first()->ip}_{$server->first()->port}_{$server->first()->user}"); + return redirect()->route('server.show', $this->parameters['server_uuid']); } public function mount() diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index f248325c7..078597382 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -17,13 +17,22 @@ class Proxy extends Component public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2; public $proxy_settings = null; + public function mount() + { + $this->proxyStatus(); + } public function serverValidated() { $this->server->settings->refresh(); } public function installProxy() { - $this->saveConfiguration($this->server); + if ( + $this->server->extra_attributes->last_applied_proxy_settings && + $this->server->extra_attributes->last_saved_proxy_settings !== $this->server->extra_attributes->last_applied_proxy_settings + ) { + $this->saveConfiguration($this->server); + } $activity = resolve(InstallProxy::class)($this->server); $this->emit('newMonitorActivity', $activity->id); } @@ -32,6 +41,7 @@ class Proxy extends Component { $this->server->extra_attributes->proxy_status = checkContainerStatus(server: $this->server, container_id: 'coolify-proxy'); $this->server->save(); + $this->server->refresh(); } public function setProxy() { diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 9a304dd69..5d26fc05b 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -95,7 +95,7 @@ if (!function_exists('savePrivateKeyForServer')) { function savePrivateKeyForServer(Server $server) { $temp_file = "id.root@{$server->ip}"; - Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key, 'private'); + Storage::disk('ssh-keys')->put($temp_file, $server->privateKey->private_key); return '/var/www/html/storage/app/ssh-keys/' . $temp_file; } } @@ -103,9 +103,11 @@ if (!function_exists('savePrivateKeyForServer')) { if (!function_exists('generateSshCommand')) { function generateSshCommand(string $private_key_location, string $server_ip, string $user, string $port, string $command, bool $isMux = true) { - $delimiter = 'EOF-COOLIFY-SSH'; Storage::disk('local')->makeDirectory('.ssh'); + + $delimiter = 'EOF-COOLIFY-SSH'; $ssh_command = "ssh "; + if ($isMux && config('coolify.mux_enabled')) { $ssh_command .= '-o ControlMaster=auto -o ControlPersist=1m -o ControlPath=/var/www/html/storage/app/.ssh/ssh_mux_%h_%p_%r '; } @@ -159,7 +161,6 @@ if (!function_exists('instantRemoteProcess')) { { $command_string = implode("\n", $command); $private_key_location = savePrivateKeyForServer($server); - $ssh_command = generateSshCommand($private_key_location, $server->ip, $server->user, $server->port, $command_string); $process = Process::run($ssh_command); $output = trim($process->output()); diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index 8041d5a4f..423c259f2 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Data\ServerMetadata; +use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; use App\Models\PrivateKey; use App\Models\Server; @@ -26,7 +27,8 @@ class ServerSeeder extends Seeder 'team_id' => $root_team->id, 'private_key_id' => $private_key_1->id, 'extra_attributes' => ServerMetadata::from([ - 'proxy_type' => ProxyTypes::TRAEFIK_V2->value + 'proxy_type' => ProxyTypes::TRAEFIK_V2->value, + 'proxy_status' => ProxyStatus::EXITED->value ]), ]); Server::create([ diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index af5e205cc..47cbf8b8d 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -39,7 +39,6 @@
Connection: OK
Uptime: {{ $uptime }}
@endisset @isset($dockerVersion) diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.php index 537e23ba1..399e9c151 100644 --- a/resources/views/livewire/server/proxy.blade.php +++ b/resources/views/livewire/server/proxy.blade.php @@ -1,27 +1,25 @@Server is not validated. Validate first.
diff --git a/resources/views/server/new.blade.php b/resources/views/server/new.blade.php index 5566b3afe..f4aa9188e 100644 --- a/resources/views/server/new.blade.php +++ b/resources/views/server/new.blade.php @@ -2,7 +2,7 @@ @if ($private_keys->count() === 0)