From 85a5df22f5190cb6a31119a48c177e7667ffa27b Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Tue, 30 Nov 2021 12:44:58 -0500 Subject: [PATCH 1/4] Modified packimage to always include the local zoneinfo time zone file --- xCAT-server/lib/xcat/plugins/packimage.pm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index c39af98a2..6fda44cf9 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -75,6 +75,7 @@ sub process_request { my $callback = shift; my $doreq = shift; my $installroot = xCAT::TableUtils->getInstallDir(); + my @timezone = xCAT::TableUtils->get_site_attribute("timezone"); my $args; if (defined($request->{arg})) { @@ -343,6 +344,15 @@ sub process_request { } close($exlist); + # timedatectl requires /etc/localtime link to the zoneinfo in /usr/share/zoneinfo + if ($timezone[0]) { + unlink("$rootimg_dir/etc/localtime"); + symlink("../usr/share/zoneinfo/$timezone[0]", "$rootimg_dir/etc/localtime"); + + # Add the zoneinfo to the include list + $excludetext .= "+./usr/share/zoneinfo/$timezone[0]\n"; + } + #handle the #INLCUDE# tag recursively my $idir = dirname($exlistlocname); my $doneincludes = 0; @@ -645,7 +655,6 @@ sub copybootscript { my $arch = shift; my $profile = shift; my $callback = shift; - my @timezone = xCAT::TableUtils->get_site_attribute("timezone"); if (-f "$installroot/postscripts/xcatdsklspost") { @@ -653,15 +662,6 @@ sub copybootscript { mkpath("$rootimg_dir/opt/xcat"); copy("$installroot/postscripts/xcatdsklspost", "$rootimg_dir/opt/xcat/xcatdsklspost"); - if ($timezone[0]) { - unlink("$rootimg_dir/etc/localtime"); - # Copy timezone file to /etc and link 'localtime' to it - mkpath(dirname("$rootimg_dir/etc/$timezone[0]")); - copy("$rootimg_dir/usr/share/zoneinfo/$timezone[0]", "$rootimg_dir/etc/$timezone[0]"); - symlink("./$timezone[0]", "$rootimg_dir/etc/localtime"); - } - - chmod(0755, "$rootimg_dir/opt/xcat/xcatdsklspost"); } else { From d86b454bafc24ec136c81927b99dea68a26d443d Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Tue, 30 Nov 2021 13:13:02 -0500 Subject: [PATCH 2/4] Print informational message from packimage when site table timezone is not set --- xCAT-server/lib/xcat/plugins/packimage.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index 6fda44cf9..ef7c11ce2 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -351,6 +351,8 @@ sub process_request { # Add the zoneinfo to the include list $excludetext .= "+./usr/share/zoneinfo/$timezone[0]\n"; + } else { + $callback->({ info => ["No timezone defined in site table, skipping timezone configuration"] }); } #handle the #INLCUDE# tag recursively From 7e6303a85bbb44051fb1fc89003cc0e67d15d582 Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Wed, 1 Dec 2021 09:14:37 -0500 Subject: [PATCH 3/4] Print warning from packimage when timezone setup fails --- xCAT-server/lib/xcat/plugins/packimage.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index ef7c11ce2..f3eae9f45 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -351,6 +351,10 @@ sub process_request { # Add the zoneinfo to the include list $excludetext .= "+./usr/share/zoneinfo/$timezone[0]\n"; + + if (not stat "$rootimg_dir/etc/localtime") { + $callback->({ warning => ["Unable to set timezone to \'$timezone[0]\', check this is a valid timezone"] }); + } } else { $callback->({ info => ["No timezone defined in site table, skipping timezone configuration"] }); } From de7ba3928673a0a16959ada54301d4a088dc3fd4 Mon Sep 17 00:00:00 2001 From: besawn <38794505+besawn@users.noreply.github.com> Date: Wed, 8 Dec 2021 09:32:41 -0500 Subject: [PATCH 4/4] Modifed packimage timezone logic to preserve two levels of links --- xCAT-server/lib/xcat/plugins/packimage.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index f3eae9f45..3eb79ba23 100755 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -352,6 +352,15 @@ sub process_request { # Add the zoneinfo to the include list $excludetext .= "+./usr/share/zoneinfo/$timezone[0]\n"; + # /usr/share/zoneinfo can have many levels of links + # If the configured timezone is a link, also add the link target to the include list + # Note: this logic can only handle 2 levels of linking + my $realtimezonefile = Cwd::abs_path("$rootimg_dir/usr/share/zoneinfo/$timezone[0]"); + if ("$rootimg_dir/usr/share/zoneinfo/$timezone[0]" ne "$realtimezonefile") { + my $relativetzpath = substr($realtimezonefile, length($rootimg_dir)); + $excludetext .= "+.$relativetzpath\n"; + } + if (not stat "$rootimg_dir/etc/localtime") { $callback->({ warning => ["Unable to set timezone to \'$timezone[0]\', check this is a valid timezone"] }); }