aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2016-10-09 21:39:05 +0200
committerAngelo Naselli <anaselli@linux.it>2016-10-09 21:39:05 +0200
commit4b91d04b4228043cc2c77bf171683d10fa735f0c (patch)
tree05f65edeed079afcde7d1c0e3edbe7281099d1bd
parentb0da9bf7734c0d0a9c2ec4464e0bb41dcbb4cc7f (diff)
downloadmanatools-4b91d04b4228043cc2c77bf171683d10fa735f0c.tar
manatools-4b91d04b4228043cc2c77bf171683d10fa735f0c.tar.gz
manatools-4b91d04b4228043cc2c77bf171683d10fa735f0c.tar.bz2
manatools-4b91d04b4228043cc2c77bf171683d10fa735f0c.tar.xz
manatools-4b91d04b4228043cc2c77bf171683d10fa735f0c.zip
First attempt to fix chrony pool configuration
-rw-r--r--lib/ManaTools/Module/Clock.pm7
-rw-r--r--lib/ManaTools/Shared/TimeZone.pm29
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/ManaTools/Module/Clock.pm b/lib/ManaTools/Module/Clock.pm
index 81661a86..85e8ecb3 100644
--- a/lib/ManaTools/Module/Clock.pm
+++ b/lib/ManaTools/Module/Clock.pm
@@ -319,7 +319,11 @@ sub _adminClockPanel {
$self->sh_tz->ntp_program($selectedService->label());
}
if (!$sameConfig) {
- eval { $self->sh_tz->setNTPConfiguration($info->{ntp_servers}) };
+ my $ntpsrv = {
+ servers => $info->{ntp_servers},
+ pool => $info->{pool},
+ };
+ eval { $self->sh_tz->setNTPConfiguration($ntpsrv) };
my $errors = $@;
if ($errors) {
$self->sh_gui->warningMsgBox({
@@ -468,6 +472,7 @@ sub _adminClockPanel {
my $pool_match = qr/\.pool\.ntp\.org$/;
my $server = $item;
$info->{ntp_servers} = [ $server =~ $pool_match ? (map { "$_.$server" } 0 .. 2) : $server ];
+ $info->{pool} = $server;
$ntpLabel->setValue(join (',', @{$info->{ntp_servers}}));
}
# fixing elapsed time (dialog is modal)
diff --git a/lib/ManaTools/Shared/TimeZone.pm b/lib/ManaTools/Shared/TimeZone.pm
index cebf3d96..343c5e9f 100644
--- a/lib/ManaTools/Shared/TimeZone.pm
+++ b/lib/ManaTools/Shared/TimeZone.pm
@@ -836,7 +836,7 @@ sub ntpServers {
=head3 OUTPUT
- @servers: arrey of configured server
+ @servers: array of configured server
=head3 DESCRIPTION
@@ -856,6 +856,10 @@ sub ntpCurrentServers {
}
else {
@serv = map { MDK::Common::Func::if_(/^\s*server\s+(\S*)/, $1) } MDK::Common::File::cat_($configFile);
+ if (! scalar @serv) {
+ ## TODO manage as servers and pool
+ @serv = map { MDK::Common::Func::if_(/^\s*pool\s+(\S*)/, $1) } MDK::Common::File::cat_($configFile);
+ }
}
my @s = ();
@@ -927,7 +931,9 @@ sub isNTPRunning {
=head3 INPUT
- $servers: Array reference containing NTP server addresses
+ $NTP_servers: HASH reference containing:
+ servers => Array reference containing NTP server addresses
+ pool => ntp pool address if any
=head3 DESCRIPTION
@@ -939,11 +945,14 @@ sub isNTPRunning {
#=============================================================
sub setNTPConfiguration {
- my ($self, $servers) = @_;
+ my ($self, $NTP_servers) = @_;
- my $f = $self->ntp_configuration_file || $self->getNTPServiceConfig($self->ntp_program);;
+ my $f = $self->ntp_configuration_file || $self->getNTPServiceConfig($self->ntp_program);
-f $f or return;
+ my $servers = $NTP_servers->{servers};
+ my $pool = [ $NTP_servers->{pool} ];
+
die $self->loc->N("user does not have the rights to change configuration file, skipped")
if (!(-w $f));
@@ -955,10 +964,6 @@ sub setNTPConfiguration {
$added = 1;
}
} $f;
- if ($self->ntp_program eq "ntpd") {
- my $ntp_prefix = $self->ntp_conf_dir;
- MDK::Common::File::output_p("$ntp_prefix/step-tickers", join('', map { "$_\n" } @{$servers}));
- }
}
else {
my $added = 0;
@@ -969,6 +974,14 @@ sub setNTPConfiguration {
$added = 1;
}
} $f;
+ if ($pool) {
+ MDK::Common::File::substInFile {
+ if (/^#?\s*pool\s+(\S*)/ && $1 ne '127.127.1.0') {
+ $_ = $added ? "#pool $1\n" : join('', map { "pool $_$servername_config_suffix\n" } @{$pool});
+ $added = 1;
+ }
+ } $f;
+ }
if ($self->ntp_program eq "ntpd") {
my $ntp_prefix = $self->ntp_conf_dir;
MDK::Common::File::output_p("$ntp_prefix/step-tickers", join('', map { "$_\n" } @{$servers}));