An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Merge branch 'next' into set-server-timzone-setting
Andras Bacsaib8ff0540e26c
diff --cc app/Console/Kernel.phpindex 3140de52cf,fd4c508a0f..17ef4397cc--- a/app/Console/Kernel.php+++ b/app/Console/Kernel.php@@@ -43,9 -43,9 +43,9 @@@ class Kernel extends ConsoleKerne} else {// Instance Jobs$schedule->command('horizon:snapshot')->everyFiveMinutes();- $schedule->command('cleanup:unreachable-servers')->daily();+ $schedule->command('cleanup:unreachable-servers')->daily()->onOneServer();- $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();- $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->onOneServer();+ $schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();+ $schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();$schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();$this->schedule_updates($schedule);@@@ -66,15 -66,16 +66,19 @@@$servers = $this->all_servers->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');foreach ($servers as $server) {if ($server->isSentinelEnabled()) {- $schedule->job(new PullSentinelImageJob($server))- ->cron($settings->update_check_frequency)- ->timezone($settings->instance_timezone)- ->onOneServer();+ $schedule->job(function () use ($server) {+ $sentinel_found = instant_remote_process(['docker inspect coolify-sentinel'], $server, false);+ $sentinel_found = json_decode($sentinel_found, true);+ $status = data_get($sentinel_found, '0.State.Status', 'exited');+ if ($status !== 'running') {+ PullSentinelImageJob::dispatch($server);+ }- })->cron($settings->update_check_frequency)->onOneServer();++ })->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();}- $schedule->job(new PullHelperImageJob($server))->cron($settings->update_check_frequency)->onOneServer();+ $schedule->job(new PullHelperImageJob($server))+ ->cron($settings->update_check_frequency)+ ->timezone($settings->instance_timezone)+ ->onOneServer();}}@@@ -108,11 -103,15 +112,12 @@@}foreach ($servers as $server) {$schedule->job(new ServerCheckJob($server))->everyMinute()->onOneServer();- //The lines below need to be added as soon as timzone is merged!!- //$serverTimezone = $server->settings->server_timezone;- //$schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();+ $serverTimezone = $server->settings->server_timezone;- $schedule->job(new DockerCleanupJob($server))- ->everyTenMinutes() //will be changed in the second PR- ->timezone($serverTimezone)- ->onOneServer();+ if ($server->settings->force_docker_cleanup) {- $schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->onOneServer();++ $schedule->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();+ } else {- $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();++ $schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->timezone($serverTimezone)->onOneServer();+ }-}}diff --cc app/Livewire/Project/Database/BackupExecutions.phpindex 79c1fcffc7,c9db7f5fcb..5d56ea53df--- a/app/Livewire/Project/Database/BackupExecutions.php+++ b/app/Livewire/Project/Database/BackupExecutions.php@@@ -57,53 -58,7 +57,53 @@@ class BackupExecutions extends Componenpublic function refreshBackupExecutions(): void{if ($this->backup) {- $this->executions = $this->backup->executions()->get()->sortBy('created_at');+ $this->executions = $this->backup->executions()->get();}}++ public function mount(ScheduledDatabaseBackup $backup)+ {+ $this->backup = $backup;+ $this->database = $backup->database;+ $this->refreshBackupExecutions();+ }++ public function server()+ {+ if ($this->database) {+ $server = null;++ if ($this->database instanceof \App\Models\ServiceDatabase) {+ $server = $this->database->service->destination->server;+ } elseif ($this->database->destination && $this->database->destination->server) {+ $server = $this->database->destination->server;+ }+ if ($server) {+ return $server;+ }+ }+ return null;+ }++ public function getServerTimezone()+ {+ $server = $this->server();+ if (!$server) {+ return 'UTC';+ }+ $serverTimezone = $server->settings->server_timezone;+ return $serverTimezone;+ }++ public function formatDateInServerTimezone($date)+ {+ $serverTimezone = $this->getServerTimezone();+ $dateObj = new \DateTime($date);+ try {+ $dateObj->setTimezone(new \DateTimeZone($serverTimezone));+ } catch (\Exception $e) {+ $dateObj->setTimezone(new \DateTimeZone('UTC'));+ }+ return $dateObj->format('Y-m-d H:i:s T');+ }}diff --cc app/Livewire/Server/Form.phpindex 08054bd782,1ab70c004e..106d3d7613--- a/app/Livewire/Server/Form.php+++ b/app/Livewire/Server/Form.php@@@ -47,7 -43,9 +44,10 @@@ class Form extends Componen'server.settings.metrics_history_days' => 'required|integer|min:1','wildcard_domain' => 'nullable|url','server.settings.is_server_api_enabled' => 'required|boolean',+ 'server.settings.server_timezone' => 'required|string|timezone',+ 'server.settings.force_docker_cleanup' => 'required|boolean',+ 'server.settings.docker_cleanup_frequency' => 'required_if:server.settings.force_docker_cleanup,true|string',+ 'server.settings.docker_cleanup_threshold' => 'required_if:server.settings.force_docker_cleanup,false|integer|min:1|max:100',];protected $validationAttributes = [@@@ -68,17 -66,24 +68,29 @@@'server.settings.metrics_refresh_rate_seconds' => 'Metrics Interval','server.settings.metrics_history_days' => 'Metrics History','server.settings.is_server_api_enabled' => 'Server API',+ 'server.settings.server_timezone' => 'Server Timezone',];- public function mount()+ public $timezones;++ public function mount(Server $server){+ $this->server = $server;+ $this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();$this->wildcard_domain = $this->server->settings->wildcard_domain;- $this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;+ $this->server->settings->docker_cleanup_threshold = $this->server->settings->docker_cleanup_threshold;+ $this->server->settings->docker_cleanup_frequency = $this->server->settings->docker_cleanup_frequency;+ }++ public function updated($field)+ {+ if ($field === 'server.settings.docker_cleanup_frequency') {+ $frequency = $this->server->settings->docker_cleanup_frequency;+ if (empty($frequency) || ! validate_cron_expression($frequency)) {+ $this->dispatch('error', 'Invalid Cron / Human expression for Docker Cleanup Frequency. Resetting to default 10 minutes.');+ $this->server->settings->docker_cleanup_frequency = '*/10 * * * *';+ }+ }}public function serverInstalled()@@@ -178,131 -183,35 +190,138 @@@public function submit(){- if (isCloud() && !isDev()) {- $this->validate();- $this->validate([- 'server.ip' => 'required',- ]);- } else {- $this->validate();- }- $uniqueIPs = Server::all()->reject(function (Server $server) {- return $server->id === $this->server->id;- })->pluck('ip')->toArray();- if (in_array($this->server->ip, $uniqueIPs)) {- $this->dispatch('error', 'IP address is already in use by another team.');- return;- }- refresh_server_connection($this->server->privateKey);- $this->server->settings->wildcard_domain = $this->wildcard_domain;- $this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;+ try {+ if (isCloud() && ! isDev()) {+ $this->validate();+ $this->validate([+ 'server.ip' => 'required',+ ]);+ } else {+ $this->validate();+ }+ $uniqueIPs = Server::all()->reject(function (Server $server) {+ return $server->id === $this->server->id;+ })->pluck('ip')->toArray();+ if (in_array($this->server->ip, $uniqueIPs)) {+ $this->dispatch('error', 'IP address is already in use by another team.');- $currentTimezone = $this->server->settings->getOriginal('server_timezone');+ return;+ }+ refresh_server_connection($this->server->privateKey);+ $this->server->settings->wildcard_domain = $this->wildcard_domain;+ if ($this->server->settings->force_docker_cleanup) {+ $this->server->settings->docker_cleanup_frequency = $this->server->settings->docker_cleanup_frequency;+ } else {+ $this->server->settings->docker_cleanup_threshold = $this->server->settings->docker_cleanup_threshold;+ }++ $currentTimezone = $this->server->settings->getOriginal('server_timezone');+ $newTimezone = $this->server->settings->server_timezone;-- if ($currentTimezone !== $newTimezone || $currentTimezone === '') {++ if ($currentTimezone !== $newTimezone || $currentTimezone === '') {+ try {+ $timezoneUpdated = $this->updateServerTimezone($newTimezone);+ if ($timezoneUpdated) {+ $this->server->settings->server_timezone = $newTimezone;+ $this->server->settings->save();+ } else {+ return;+ }+ } catch (\Exception $e) {+ $this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());+ return;+ }+ }+- $this->server->settings->save();- $this->server->save();- $this->dispatch('success', 'Server updated.');+ $this->server->settings->save();+ $this->server->save();+ $this->dispatch('success', 'Server updated.');+ } catch (\Throwable $e) {+ return handleError($e, $this);+ }}++ public function updatedServerTimezone($value)+ {+ if (!is_string($value) || !in_array($value, timezone_identifiers_list())) {+ $this->addError('server.settings.server_timezone', 'Invalid timezone.');+ return;+ }+ $this->server->settings->server_timezone = $value;+ $this->updateServerTimezone($value);+ }++ private function updateServerTimezone($desired_timezone)+ {+ try {+ $commands = [+ "if command -v timedatectl > /dev/null 2>&1 && pidof systemd > /dev/null; then",+ " timedatectl set-timezone " . escapeshellarg($desired_timezone),+ "elif [ -f /etc/timezone ]; then",+ " echo " . escapeshellarg($desired_timezone) . " > /etc/timezone",+ " rm -f /etc/localtime",+ " ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",+ "elif [ -f /etc/localtime ]; then",+ " rm -f /etc/localtime",+ " ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",+ "else",+ " echo 'Unable to set timezone'",+ " exit 1",+ "fi",+ "if command -v dpkg-reconfigure > /dev/null 2>&1; then",+ " dpkg-reconfigure -f noninteractive tzdata",+ "elif command -v tzdata-update > /dev/null 2>&1; then",+ " tzdata-update",+ "elif [ -f /etc/sysconfig/clock ]; then",+ " sed -i 's/^ZONE=.*/ZONE=\"" . $desired_timezone . "\"/' /etc/sysconfig/clock",+ " source /etc/sysconfig/clock",+ "fi",+ "if command -v systemctl > /dev/null 2>&1 && pidof systemd > /dev/null; then",+ " systemctl try-restart systemd-timesyncd.service || true",+ "elif command -v service > /dev/null 2>&1; then",+ " service ntpd restart || service ntp restart || true",+ "fi",+ "echo \"Timezone updated to: $desired_timezone\"",+ "date"+ ];++ instant_remote_process($commands, $this->server);++ $verificationCommands = [+ "readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'",+ "date +'%Z %:z'"+ ];+ $verificationResult = instant_remote_process($verificationCommands, $this->server, false);+ $verificationLines = explode("\n", trim($verificationResult));++ if (count($verificationLines) !== 2) {+ $this->dispatch('error', 'Failed to verify timezone update. Unexpected server response.');+ return false;+ }++ $actualTimezone = trim($verificationLines[0]);+ [$abbreviation, $offset] = explode(' ', trim($verificationLines[1]));++ $desiredTz = new \DateTimeZone($desired_timezone);+ $desiredAbbr = (new \DateTime('now', $desiredTz))->format('T');+ $desiredOffset = $this->formatOffset($desiredTz->getOffset(new \DateTime('now', $desiredTz)));++ if ($actualTimezone === $desired_timezone && $abbreviation === $desiredAbbr && $offset === $desiredOffset) {+ $this->server->settings->server_timezone = $desired_timezone;+ $this->server->settings->save();+ return true;+ } else {+ $this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');+ return false;+ }+ } catch (\Exception $e) {+ $this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());+ return false;+ }+ }++ private function formatOffset($offsetSeconds)+ {+ $hours = abs($offsetSeconds) / 3600;+ $minutes = (abs($offsetSeconds) % 3600) / 60;+ return sprintf('%s%02d:%02d', $offsetSeconds >= 0 ? '+' : '-', $hours, $minutes);+ }}diff --cc app/Models/ScheduledTask.phpindex 4641c2a854,afff4ef11e..7b1c0d2755--- a/app/Models/ScheduledTask.php+++ b/app/Models/ScheduledTask.php@@@ -28,27 -26,6 +28,27 @@@ class ScheduledTask extends BaseModepublic function executions(): HasMany{- return $this->hasMany(ScheduledTaskExecution::class);+ return $this->hasMany(ScheduledTaskExecution::class)->orderBy('created_at', 'desc');}++ public function server()+ {+ if ($this->application) {+ if ($this->application->destination && $this->application->destination->server) {+ $server = $this->application->destination->server;+ return $server;+ }+ } elseif ($this->service) {+ if ($this->service->destination && $this->service->destination->server) {+ $server = $this->service->destination->server;+ return $server;+ }+ } elseif ($this->database) {+ if ($this->database->destination && $this->database->destination->server) {+ $server = $this->database->destination->server;+ return $server;+ }+ }+ return null;+ }}diff --cc resources/views/livewire/server/form.blade.phpindex 30c0f7fdf6,474521c9cd..a3722cb44c--- a/resources/views/livewire/server/form.blade.php+++ b/resources/views/livewire/server/form.blade.php@@@ -176,42 -141,39 +176,50 @@@</div>@if ($server->isFunctional())- <h3 class="pt-4">Settings</h3>- <div class="flex flex-col gap-2">- <div class="flex flex-col flex-wrap gap-2 sm:flex-nowrap">- @if ($server->settings->is_force_cleanup_enabled)- <div class="w-64">- <x-forms.checkbox- helper="This will cleanup build caches / unused images / etc every 10 minutes."- instantSave id="server.settings.is_force_cleanup_enabled"- label="Force Cleanup Docker Engine" />+ <h3 class="pt-4">Settings</h3>+ <div class="flex flex-col gap-2">+ <div class="flex flex-col flex-wrap gap-2 sm:flex-nowrap">+ <div class="w-64">+ <x-forms.checkbox+ helper="Enable force Docker Cleanup. This will cleanup build caches / unused images / etc."+ instantSave id="server.settings.force_docker_cleanup" label="Force Docker Cleanup" />+ </div>+ @if ($server->settings->force_docker_cleanup)+ <x-forms.input placeholder="*/10 * * * *" id="server.settings.docker_cleanup_frequency"+ label="Docker cleanup frequency" required+ helper="Cron expression for Docker Cleanup.<br>You can use every_minute, hourly, daily, weekly, monthly, yearly.<br><br>Default is every 10 minutes." />+ @else+ <x-forms.input id="server.settings.docker_cleanup_threshold"+ label="Docker cleanup threshold (%)" required+ helper="The Docker cleanup tasks will run when the disk usage exceeds this threshold." />+ @endif</div>- <div class="flex flex-wrap gap-2 sm:flex-nowrap">- <x-forms.input id="server.settings.concurrent_builds" label="Number of concurrent builds" required- helper="You can specify the number of simultaneous build processes/deployments that should run concurrently." />- <x-forms.input id="server.settings.dynamic_timeout" label="Deployment timeout (seconds)" required- helper="You can define the maximum duration for a deployment to run before timing it out." />+ @else+ <x-forms.input id="cleanup_after_percentage" label="Disk cleanup threshold (%)" required+ helper="The disk cleanup task will run when the disk usage exceeds this threshold." />+ <div class="w-64">+ <x-forms.checkbox+ helper="This will cleanup build caches / unused images / etc every 10 minutes."+ instantSave id="server.settings.is_force_cleanup_enabled"+ label="Force Cleanup Docker Engine" /></div>+ @endif</div>- <div class="flex items-center gap-2 pt-4 pb-2">- <h3>Sentinel</h3>- {{-- @if ($server->isSentinelEnabled()) --}}- {{-- <x-forms.button wire:click='restartSentinel'>Restart</x-forms.button> --}}- {{-- @endif --}}+ <div class="flex flex-wrap gap-2 sm:flex-nowrap">+ <x-forms.input id="server.settings.concurrent_builds" label="Number of concurrent builds" required+ helper="You can specify the number of simultaneous build processes/deployments that should run concurrently." />+ <x-forms.input id="server.settings.dynamic_timeout" label="Deployment timeout (seconds)" required+ helper="You can define the maximum duration for a deployment to run before timing it out." /></div>- <div>Metrics are disabled until a few bugs are fixed.</div>- {{-- <div class="w-64">+ </div>+ <div class="flex items-center gap-2 pt-4 pb-2">+ <h3>Sentinel</h3>+ {{-- @if ($server->isSentinelEnabled()) --}}+ {{-- <x-forms.button wire:click='restartSentinel'>Restart</x-forms.button> --}}+ {{-- @endif --}}+ </div>+ <div>Metrics are disabled until a few bugs are fixed.</div>+ {{-- <div class="w-64"><x-forms.checkbox instantSave id="server.settings.is_metrics_enabled" label="Enable Metrics" /></div><div class="pt-4">diff --cc resources/views/livewire/settings/index.blade.phpindex fe395fa6d1,c0ba76d00b..7ef2d2b2a1--- a/resources/views/livewire/settings/index.blade.php+++ b/resources/views/livewire/settings/index.blade.php@@@ -15,39 -15,8 +15,39 @@@<div class="flex flex-col gap-2"><div class="flex flex-wrap items-end gap-2"><h4 class="pt-6">Instance Settings</h4>- <x-forms.input id="settings.fqdn" label="Instance's Domain" placeholder="https://coolify.io" />+ <x-forms.input id="settings.fqdn" label="Instance's Domain" helper="Enter the full domain name (FQDN) of the instance, including 'https://' if you want to secure the dashboard with HTTPS. Setting this will make the dashboard accessible via this domain, secured by HTTPS, instead of just the IP address." placeholder="https://coolify.yourdomain.com" /><x-forms.input id="settings.instance_name" label="Instance's Name" placeholder="Coolify" />+ <div class="w-full" x-data="{+ open: false,+ search: '{{ $settings->instance_timezone }}',+ timezones: @js($timezones),+ placeholder: 'Select Instance Timezone'+ }">+ <label for="settings.instance_timezone" class="dark:text-white flex items-center">+ Instance Timezone+ <x-helper class="ml-2" helper="Timezone for the Coolify instance (this does NOT change your server's timezone in /etc/timezone, /etc/localtime, etc.). This is used for the update check and automatic update frequency." />+ </label>+ <div class="relative">+ <input+ x-model="search"+ @focus="open = true"+ @click.away="open = false"+ @input="open = true"+ class="w-full input"+ :placeholder="placeholder"+ wire:model.debounce.300ms="settings.instance_timezone"+ >+ <div x-show="open" class="absolute z-50 w-full mt-1 bg-white dark:bg-coolgray-100 border border-gray-300 dark:border-white rounded-md shadow-lg max-h-60 overflow-auto">+ <template x-for="timezone in timezones.filter(tz => tz.toLowerCase().includes(search.toLowerCase()))" :key="timezone">+ <div+ @click="search = timezone; open = false; $wire.set('settings.instance_timezone', timezone)"+ class="px-4 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 text-gray-800 dark:text-gray-200"+ x-text="timezone"+ ></div>+ </template>+ </div>+ </div>+ </div><h4 class="w-full pt-6">DNS Validation</h4><div class="md:w-96"><x-forms.checkbox instantSave id="is_dns_validation_enabled" label="Enabled" />