Skip to content

Commit 6f648e4

Browse files
authored
Merge pull request #5416 from coollabsio/next
v4.0.0-beta.400
2 parents 6c17d45 + ebd9485 commit 6f648e4

32 files changed

+574
-325
lines changed

app/Actions/Database/StartMariadb.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function handle(StandaloneMariadb $database)
183183
$docker_compose = generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker_compose, $container_name, $this->database->destination->network);
184184
if ($this->database->enable_ssl) {
185185
$docker_compose['services'][$container_name]['command'] = [
186-
'mysqld',
186+
'mariadbd',
187187
'--ssl-cert=/etc/mysql/certs/server.crt',
188188
'--ssl-key=/etc/mysql/certs/server.key',
189189
'--ssl-ca=/etc/mysql/certs/coolify-ca.crt',

app/Actions/Proxy/CheckProxy.php

+32-14
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public function handle(Server $server, $fromUI = false): bool
3030
if (is_null($proxyType) || $proxyType === 'NONE' || $server->proxy->force_stop) {
3131
return false;
3232
}
33-
['uptime' => $uptime, 'error' => $error] = $server->validateConnection();
34-
if (! $uptime) {
35-
throw new \Exception($error);
36-
}
3733
if (! $server->isProxyShouldRun()) {
3834
if ($fromUI) {
3935
throw new \Exception('Proxy should not run. You selected the Custom Proxy.');
@@ -68,6 +64,38 @@ public function handle(Server $server, $fromUI = false): bool
6864

6965
$portsToCheck = ['80', '443'];
7066

67+
foreach ($portsToCheck as $port) {
68+
// Try multiple methods to check port availability
69+
$commands = [
70+
// Method 1: Check /proc/net/tcp directly (convert port to hex)
71+
"cat /proc/net/tcp | grep -q '00000000:".str_pad(dechex($port), 4, '0', STR_PAD_LEFT)."'",
72+
// Method 2: Use ss command (modern alternative to netstat)
73+
"ss -tuln | grep -q ':$port '",
74+
// Method 3: Use lsof if available
75+
"lsof -i :$port >/dev/null 2>&1",
76+
// Method 4: Use fuser if available
77+
"fuser $port/tcp >/dev/null 2>&1",
78+
];
79+
80+
$portInUse = false;
81+
foreach ($commands as $command) {
82+
try {
83+
instant_remote_process([$command], $server);
84+
$portInUse = true;
85+
break;
86+
} catch (\Throwable $e) {
87+
88+
continue;
89+
}
90+
}
91+
if ($portInUse) {
92+
if ($fromUI) {
93+
throw new \Exception("Port $port is in use.<br>You must stop the process using this port.<br><br>Docs: <a target='_blank' class='dark:text-white hover:underline' href='https://coolify.io/docs'>https://coolify.io/docs</a><br>Discord: <a target='_blank' class='dark:text-white hover:underline' href='https://coolify.io/discord'>https://coolify.io/discord</a>");
94+
} else {
95+
return false;
96+
}
97+
}
98+
}
7199
try {
72100
if ($server->proxyType() !== ProxyTypes::NONE->value) {
73101
$proxyCompose = CheckConfiguration::run($server);
@@ -94,16 +122,6 @@ public function handle(Server $server, $fromUI = false): bool
94122
if (count($portsToCheck) === 0) {
95123
return false;
96124
}
97-
foreach ($portsToCheck as $port) {
98-
$connection = @fsockopen($ip, $port);
99-
if (is_resource($connection) && fclose($connection)) {
100-
if ($fromUI) {
101-
throw new \Exception("Port $port is in use.<br>You must stop the process using this port.<br>Docs: <a target='_blank' href='https://coolify.io/docs'>https://coolify.io/docs</a><br>Discord: <a target='_blank' href='https://coollabs.io/discord'>https://coollabs.io/discord</a>");
102-
} else {
103-
return false;
104-
}
105-
}
106-
}
107125

108126
return true;
109127
}

app/Livewire/Project/Database/Dragonfly/General.php

+3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ class General extends Component
6060

6161
public function getListeners()
6262
{
63+
$userId = Auth::id();
6364
$teamId = Auth::user()->currentTeam()->id;
6465

6566
return [
6667
"echo-private:team.{$teamId},DatabaseProxyStopped" => 'databaseProxyStopped',
68+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
6769
];
6870
}
6971

@@ -226,6 +228,7 @@ public function regenerateSslCertificate()
226228
caKey: $caCert->ssl_private_key,
227229
configurationDir: $existingCert->configuration_dir,
228230
mountPath: $existingCert->mount_path,
231+
isPemKeyFileRequired: true,
229232
);
230233

231234
$this->dispatch('success', 'SSL certificates regenerated. Restart database to apply changes.');

app/Livewire/Project/Database/Heading.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function activityFinished()
3131
$this->database->update([
3232
'started_at' => now(),
3333
]);
34-
$this->dispatch('refresh');
3534
$this->check_status();
35+
3636
if (is_null($this->database->config_hash) || $this->database->isConfigurationChanged()) {
3737
$this->database->isConfigurationChanged(true);
3838
$this->dispatch('configurationChanged');
@@ -44,7 +44,7 @@ public function activityFinished()
4444
public function check_status($showNotification = false)
4545
{
4646
if ($this->database->destination->server->isFunctional()) {
47-
GetContainersStatus::dispatch($this->database->destination->server);
47+
GetContainersStatus::run($this->database->destination->server);
4848
}
4949

5050
if ($showNotification) {
@@ -63,6 +63,7 @@ public function stop()
6363
$this->database->status = 'exited';
6464
$this->database->save();
6565
$this->check_status();
66+
$this->dispatch('refresh');
6667
}
6768

6869
public function restart()

app/Livewire/Project/Database/Keydb/General.php

+4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ class General extends Component
6363

6464
public function getListeners()
6565
{
66+
$userId = Auth::id();
6667
$teamId = Auth::user()->currentTeam()->id;
6768

6869
return [
6970
"echo-private:team.{$teamId},DatabaseProxyStopped" => 'databaseProxyStopped',
71+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
72+
'refresh' => '$refresh',
7073
];
7174
}
7275

@@ -231,6 +234,7 @@ public function regenerateSslCertificate()
231234
caKey: $caCert->ssl_private_key,
232235
configurationDir: $existingCert->configuration_dir,
233236
mountPath: $existingCert->mount_path,
237+
isPemKeyFileRequired: true,
234238
);
235239

236240
$this->dispatch('success', 'SSL certificates regenerated. Restart database to apply changes.');

app/Livewire/Project/Database/Mariadb/General.php

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\StandaloneMariadb;
1111
use Carbon\Carbon;
1212
use Exception;
13+
use Illuminate\Support\Facades\Auth;
1314
use Livewire\Component;
1415

1516
class General extends Component
@@ -26,6 +27,16 @@ class General extends Component
2627

2728
public ?Carbon $certificateValidUntil = null;
2829

30+
public function getListeners()
31+
{
32+
$userId = Auth::id();
33+
34+
return [
35+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
36+
'refresh' => '$refresh',
37+
];
38+
}
39+
2940
protected $rules = [
3041
'database.name' => 'required',
3142
'database.description' => 'nullable',
@@ -173,6 +184,7 @@ public function regenerateSslCertificate()
173184
caKey: $caCert->ssl_private_key,
174185
configurationDir: $existingCert->configuration_dir,
175186
mountPath: $existingCert->mount_path,
187+
isPemKeyFileRequired: true,
176188
);
177189

178190
$this->dispatch('success', 'SSL certificates have been regenerated. Please restart the database for changes to take effect.');

app/Livewire/Project/Database/Mongodb/General.php

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\StandaloneMongodb;
1111
use Carbon\Carbon;
1212
use Exception;
13+
use Illuminate\Support\Facades\Auth;
1314
use Livewire\Component;
1415

1516
class General extends Component
@@ -26,6 +27,16 @@ class General extends Component
2627

2728
public ?Carbon $certificateValidUntil = null;
2829

30+
public function getListeners()
31+
{
32+
$userId = Auth::id();
33+
34+
return [
35+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
36+
'refresh' => '$refresh',
37+
];
38+
}
39+
2940
protected $rules = [
3041
'database.name' => 'required',
3142
'database.description' => 'nullable',
@@ -181,6 +192,7 @@ public function regenerateSslCertificate()
181192
caKey: $caCert->ssl_private_key,
182193
configurationDir: $existingCert->configuration_dir,
183194
mountPath: $existingCert->mount_path,
195+
isPemKeyFileRequired: true,
184196
);
185197

186198
$this->dispatch('success', 'SSL certificates have been regenerated. Please restart the database for changes to take effect.');

app/Livewire/Project/Database/Mysql/General.php

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\StandaloneMysql;
1111
use Carbon\Carbon;
1212
use Exception;
13+
use Illuminate\Support\Facades\Auth;
1314
use Livewire\Component;
1415

1516
class General extends Component
@@ -26,6 +27,16 @@ class General extends Component
2627

2728
public ?Carbon $certificateValidUntil = null;
2829

30+
public function getListeners()
31+
{
32+
$userId = Auth::id();
33+
34+
return [
35+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
36+
'refresh' => '$refresh',
37+
];
38+
}
39+
2940
protected $rules = [
3041
'database.name' => 'required',
3142
'database.description' => 'nullable',
@@ -180,6 +191,7 @@ public function regenerateSslCertificate()
180191
caKey: $caCert->ssl_private_key,
181192
configurationDir: $existingCert->configuration_dir,
182193
mountPath: $existingCert->mount_path,
194+
isPemKeyFileRequired: true,
183195
);
184196

185197
$this->dispatch('success', 'SSL certificates have been regenerated. Please restart the database for changes to take effect.');

app/Livewire/Project/Database/Postgresql/General.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\StandalonePostgresql;
1111
use Carbon\Carbon;
1212
use Exception;
13+
use Illuminate\Support\Facades\Auth;
1314
use Livewire\Component;
1415

1516
class General extends Component
@@ -30,8 +31,11 @@ class General extends Component
3031

3132
public function getListeners()
3233
{
34+
$userId = Auth::id();
35+
3336
return [
34-
'refresh',
37+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
38+
'refresh' => '$refresh',
3539
'save_init_script',
3640
'delete_init_script',
3741
];
@@ -144,6 +148,7 @@ public function regenerateSslCertificate()
144148
caKey: $caCert->ssl_private_key,
145149
configurationDir: $existingCert->configuration_dir,
146150
mountPath: $existingCert->mount_path,
151+
isPemKeyFileRequired: true,
147152
);
148153

149154
$this->dispatch('success', 'SSL certificates have been regenerated. Please restart the database for changes to take effect.');
@@ -204,7 +209,7 @@ public function save_init_script($script)
204209
$delete_command = "rm -f $old_file_path";
205210
try {
206211
instant_remote_process([$delete_command], $this->server);
207-
} catch (\Exception $e) {
212+
} catch (Exception $e) {
208213
$this->dispatch('error', 'Failed to remove old init script from server: '.$e->getMessage());
209214

210215
return;
@@ -245,7 +250,7 @@ public function delete_init_script($script)
245250
$command = "rm -f $file_path";
246251
try {
247252
instant_remote_process([$command], $this->server);
248-
} catch (\Exception $e) {
253+
} catch (Exception $e) {
249254
$this->dispatch('error', 'Failed to remove init script from server: '.$e->getMessage());
250255

251256
return;
@@ -262,16 +267,11 @@ public function delete_init_script($script)
262267

263268
$this->database->init_scripts = $updatedScripts;
264269
$this->database->save();
265-
$this->refresh();
270+
$this->dispatch('refresh')->self();
266271
$this->dispatch('success', 'Init script deleted from the database and the server.');
267272
}
268273
}
269274

270-
public function refresh(): void
271-
{
272-
$this->database->refresh();
273-
}
274-
275275
public function save_new_init_script()
276276
{
277277
$this->validate([

app/Livewire/Project/Database/Redis/General.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
use App\Models\StandaloneRedis;
1111
use Carbon\Carbon;
1212
use Exception;
13+
use Illuminate\Support\Facades\Auth;
1314
use Livewire\Component;
1415

1516
class General extends Component
1617
{
17-
protected $listeners = [
18-
'envsUpdated' => 'refresh',
19-
'refresh',
20-
];
21-
2218
public Server $server;
2319

2420
public StandaloneRedis $database;
@@ -35,6 +31,17 @@ class General extends Component
3531

3632
public ?Carbon $certificateValidUntil = null;
3733

34+
public function getListeners()
35+
{
36+
$userId = Auth::id();
37+
38+
return [
39+
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
40+
'envsUpdated' => 'refresh',
41+
'refresh',
42+
];
43+
}
44+
3845
protected $rules = [
3946
'database.name' => 'required',
4047
'database.description' => 'nullable',
@@ -181,6 +188,7 @@ public function regenerateSslCertificate()
181188
caKey: $caCert->ssl_private_key,
182189
configurationDir: $existingCert->configuration_dir,
183190
mountPath: $existingCert->mount_path,
191+
isPemKeyFileRequired: true,
184192
);
185193

186194
$this->dispatch('success', 'SSL certificates regenerated. Restart database to apply changes.');

app/Models/EmailNotificationSettings.php

-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ public function team()
7070

7171
public function isEnabled()
7272
{
73-
if (isCloud()) {
74-
return true;
75-
}
76-
7773
return $this->smtp_enabled || $this->resend_enabled || $this->use_instance_email_settings;
7874
}
7975
}

app/Models/StandaloneMongodb.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ protected function internalDbUrl(): Attribute
248248
$encodedPass = rawurlencode($this->mongo_initdb_root_password);
249249
$url = "mongodb://{$encodedUser}:{$encodedPass}@{$this->uuid}:27017/?directConnection=true";
250250
if ($this->enable_ssl) {
251-
$url .= '&tls=true';
251+
$url .= '&tls=true&tlsCAFile=/etc/mongo/certs/ca.pem';
252252
if (in_array($this->ssl_mode, ['verify-full'])) {
253-
$url .= '&tlsCAFile=/etc/ssl/certs/coolify-ca.crt';
253+
$url .= '&tlsCertificateKeyFile=/etc/mongo/certs/server.pem';
254254
}
255255
}
256256

@@ -268,9 +268,9 @@ protected function externalDbUrl(): Attribute
268268
$encodedPass = rawurlencode($this->mongo_initdb_root_password);
269269
$url = "mongodb://{$encodedUser}:{$encodedPass}@{$this->destination->server->getIp}:{$this->public_port}/?directConnection=true";
270270
if ($this->enable_ssl) {
271-
$url .= '&tls=true';
271+
$url .= '&tls=true&tlsCAFile=/etc/mongo/certs/ca.pem';
272272
if (in_array($this->ssl_mode, ['verify-full'])) {
273-
$url .= '&tlsCAFile=/etc/ssl/certs/coolify-ca.crt';
273+
$url .= '&tlsCertificateKeyFile=/etc/mongo/certs/server.pem';
274274
}
275275
}
276276

app/Notifications/Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function toTelegram(): array
8383
'buttons' => [
8484
[
8585
'text' => 'Go to your dashboard',
86-
'url' => base_url(),
86+
'url' => isDev() ? 'https://staging-but-dev.coolify.io' : base_url(),
8787
],
8888
],
8989
];

0 commit comments

Comments
 (0)