fix: timezone not updated when systemd is missing
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Actions\Server\StartSentinel;
|
|||||||
use App\Actions\Server\StopSentinel;
|
use App\Actions\Server\StopSentinel;
|
||||||
use App\Jobs\PullSentinelImageJob;
|
use App\Jobs\PullSentinelImageJob;
|
||||||
use App\Models\Server;;
|
use App\Models\Server;;
|
||||||
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Form extends Component
|
class Form extends Component
|
||||||
@@ -80,7 +81,11 @@ class Form extends Component
|
|||||||
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
|
$this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;
|
||||||
|
|
||||||
if ($this->server->settings->server_timezone === '') {
|
if ($this->server->settings->server_timezone === '') {
|
||||||
|
ray($this->server->settings->server_timezone);
|
||||||
|
ray('Server timezone is empty. Setting default timezone.');
|
||||||
|
ray('Current timezone:', $this->server->settings->server_timezone);
|
||||||
$defaultTimezone = config('app.timezone');
|
$defaultTimezone = config('app.timezone');
|
||||||
|
ray('Default timezone:', $defaultTimezone);
|
||||||
$this->updateServerTimezone($defaultTimezone);
|
$this->updateServerTimezone($defaultTimezone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +132,6 @@ class Form extends Component
|
|||||||
}
|
}
|
||||||
if ($this->server->settings->isDirty('is_server_api_enabled') && $this->server->settings->is_server_api_enabled === true) {
|
if ($this->server->settings->isDirty('is_server_api_enabled') && $this->server->settings->is_server_api_enabled === true) {
|
||||||
ray('Starting sentinel');
|
ray('Starting sentinel');
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ray('Sentinel is not enabled');
|
ray('Sentinel is not enabled');
|
||||||
@@ -251,20 +255,22 @@ class Form extends Component
|
|||||||
$this->updateServerTimezone($value);
|
$this->updateServerTimezone($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateServerTimezone($value)
|
private function updateServerTimezone($desired_timezone)
|
||||||
{
|
{
|
||||||
ray('updateServerTimezone called with value:', $value);
|
ray('updateServerTimezone called with value:', $desired_timezone);
|
||||||
try {
|
try {
|
||||||
$commands = [
|
$commands = [
|
||||||
"date +%Z",
|
"if [ -f /etc/timezone ]; then",
|
||||||
"if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
|
" echo " . escapeshellarg($desired_timezone) . " > /etc/timezone",
|
||||||
"if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo '/etc/timezone update failed'; fi",
|
" ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
|
||||||
"if [ -L /etc/localtime ] || [ -f /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
|
"elif [ -f /etc/localtime ]; then",
|
||||||
"if command -v dpkg-reconfigure >/dev/null 2>&1; then dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo 'dpkg-reconfigure failed'; fi",
|
" ln -sf /usr/share/zoneinfo/" . escapeshellarg($desired_timezone) . " /etc/localtime",
|
||||||
"if command -v apk >/dev/null 2>&1; then apk add --no-cache tzdata 2>&1 && cp /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 && echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo 'Alpine timezone update failed'; fi",
|
"else",
|
||||||
"if [ -f /etc/sysconfig/clock ]; then sed -i 's/^ZONE=.*/ZONE=\"" . escapeshellarg($value) . "\"/' /etc/sysconfig/clock 2>&1 || echo '/etc/sysconfig/clock update failed'; fi",
|
" echo 'Unable to set timezone'",
|
||||||
"date +%Z",
|
" exit 1",
|
||||||
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
|
"fi",
|
||||||
|
"echo \"Timezone updated to: $desired_timezone\"",
|
||||||
|
"date"
|
||||||
];
|
];
|
||||||
|
|
||||||
ray('Commands to be executed:', $commands);
|
ray('Commands to be executed:', $commands);
|
||||||
@@ -273,17 +279,17 @@ class Form extends Component
|
|||||||
ray('Result of instant_remote_process:', $result);
|
ray('Result of instant_remote_process:', $result);
|
||||||
|
|
||||||
// Check if the timezone was actually changed
|
// Check if the timezone was actually changed
|
||||||
$newTimezone = trim(instant_remote_process(["date +%Z"], $this->server, false));
|
$newTimezone = trim(instant_remote_process(["cat /etc/timezone 2>/dev/null || readlink /etc/localtime | sed 's#/usr/share/zoneinfo/##'"], $this->server, false));
|
||||||
ray('New timezone after update:', $newTimezone);
|
ray('New timezone after update:', $newTimezone);
|
||||||
|
|
||||||
if ($newTimezone !== $value) {
|
if ($newTimezone !== $desired_timezone) {
|
||||||
ray('Timezone update failed. New timezone does not match requested value.');
|
ray('Timezone update failed. New timezone does not match requested value.');
|
||||||
$this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
|
$this->dispatch('error', 'Failed to update server timezone. The server reported a different timezone than requested.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ray('Updating server settings');
|
ray('Updating server settings');
|
||||||
$this->server->settings->server_timezone = $value;
|
$this->server->settings->server_timezone = $desired_timezone;
|
||||||
$this->server->settings->save();
|
$this->server->settings->save();
|
||||||
ray('Server settings updated');
|
ray('Server settings updated');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user