fix: refresh public ips on start

This commit is contained in:
Andras Bacsai 2024-04-25 13:52:52 +02:00
parent d7b359e432
commit 911e29f2ea
3 changed files with 39 additions and 21 deletions

View File

@ -20,6 +20,7 @@ class Init extends Command
public function handle() public function handle()
{ {
$this->alive(); $this->alive();
get_public_ips();
$full_cleanup = $this->option('full-cleanup'); $full_cleanup = $this->option('full-cleanup');
$cleanup_deployments = $this->option('cleanup-deployments'); $cleanup_deployments = $this->option('cleanup-deployments');
if ($cleanup_deployments) { if ($cleanup_deployments) {
@ -56,6 +57,7 @@ public function handle()
$this->cleanup_stucked_helper_containers(); $this->cleanup_stucked_helper_containers();
$this->call('cleanup:stucked-resources'); $this->call('cleanup:stucked-resources');
} }
private function restore_coolify_db_backup() private function restore_coolify_db_backup()
{ {
try { try {

View File

@ -29,11 +29,13 @@
use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Mail\Message; use Illuminate\Mail\Message;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Process\Pool;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -2011,3 +2013,37 @@ function parseLineForSudo(string $command, Server $server): string
return $command; return $command;
} }
function get_public_ips()
{
try {
echo "Refreshing public ips!\n";
$settings = InstanceSettings::get();
[$first, $second] = Process::concurrently(function (Pool $pool) {
$pool->path(__DIR__)->command('curl -4s https://ifconfig.io');
$pool->path(__DIR__)->command('curl -6s https://ifconfig.io');
});
$ipv4 = $first->output();
if ($ipv4) {
$ipv4 = trim($ipv4);
$validate_ipv4 = filter_var($ipv4, FILTER_VALIDATE_IP);
if ($validate_ipv4 == false) {
echo "Invalid ipv4: $ipv4\n";
return;
}
$settings->update(['public_ipv4' => $ipv4]);
}
$ipv6 = $second->output();
if ($ipv6) {
$ipv6 = trim($ipv6);
$validate_ipv6 = filter_var($ipv6, FILTER_VALIDATE_IP);
if ($validate_ipv6 == false) {
echo "Invalid ipv6: $ipv6\n";
return;
}
$settings->update(['public_ipv6' => $ipv6]);
}
} catch (\Throwable $e) {
echo "Error: {$e->getMessage()}\n";
}
}

View File

@ -177,27 +177,7 @@ public function run(): void
} }
} }
try { get_public_ips();
$settings = InstanceSettings::get();
if (is_null($settings->public_ipv4)) {
$ipv4 = Process::run('curl -4s https://ifconfig.io')->output();
if ($ipv4) {
$ipv4 = trim($ipv4);
$ipv4 = filter_var($ipv4, FILTER_VALIDATE_IP);
$settings->update(['public_ipv4' => $ipv4]);
}
}
if (is_null($settings->public_ipv6)) {
$ipv6 = Process::run('curl -6s https://ifconfig.io')->output();
if ($ipv6) {
$ipv6 = trim($ipv6);
$ipv6 = filter_var($ipv6, FILTER_VALIDATE_IP);
$settings->update(['public_ipv6' => $ipv6]);
}
}
} catch (\Throwable $e) {
echo "Error: {$e->getMessage()}\n";
}
$oauth_settings_seeder = new OauthSettingSeeder(); $oauth_settings_seeder = new OauthSettingSeeder();
$oauth_settings_seeder->run(); $oauth_settings_seeder->run();