aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2015-03-25 12:06:03 +0100
committerAngelo Naselli <anaselli@linux.it>2015-03-25 12:06:03 +0100
commit7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6 (patch)
treed2c504a1ad271a57c9fbce23eb84f9ea9820f0a2 /lib
parent031f000833f385de8bc5142c571aec73399b4a1a (diff)
downloadcolin-keep-7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6.tar
colin-keep-7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6.tar.gz
colin-keep-7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6.tar.bz2
colin-keep-7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6.tar.xz
colin-keep-7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6.zip
fixed ntp_program attribute initialization and added its test
Diffstat (limited to 'lib')
-rw-r--r--lib/ManaTools/Shared/TimeZone.pm41
1 files changed, 34 insertions, 7 deletions
diff --git a/lib/ManaTools/Shared/TimeZone.pm b/lib/ManaTools/Shared/TimeZone.pm
index 155de20..d481bf2 100644
--- a/lib/ManaTools/Shared/TimeZone.pm
+++ b/lib/ManaTools/Shared/TimeZone.pm
@@ -105,17 +105,16 @@ has 'timezone_prefix' => (
has 'ntp_configuration_file' => (
is => 'rw',
isa => 'Str',
+ lazy => 1,
builder => '_ntp_configuration_file_init',
);
sub _ntp_configuration_file_init {
my $self = shift;
- return "/etc/chrony.conf" if (-f "/etc/chrony.conf");
-
- return "/etc/ntp.conf" if (-f "/etc/ntp.conf");
+ my $curr = $self->ntp_program;
- return "/etc/systemd/timesyncd.conf";
+ return $self->getNTPServiceConfig($curr);
}
#=============================================================
@@ -163,11 +162,39 @@ has 'ntp_program' => (
sub _ntp_program_init {
my $self = shift;
- return "chronyd" if ($self->ntp_configuration_file() eq "/etc/chrony.conf");
+ # looks for a running service from the configured ones,
+ # if none is running chooses the first of the list
+ my $list = $self->ntpServiceList();
+ return $self->loc->N("No NTP services") if !$list;
- return "ntpd" if ($self->ntp_configuration_file() eq "/etc/ntp.conf");
+ my $ntpd;
+ my $isRunning = 0;
+ foreach $ntpd (@{$list}) {
+ $isRunning = $self->sh_services->is_service_running($ntpd);
+ last if $isRunning;
+ }
+
+ if (!$isRunning) {
+ # being sure systemd-timesyncd is not really running (or set to be)
+ if ($self->getEmbeddedNTP()) {
+ $ntpd = "systemd-timesyncd";
+ Sys::Syslog::syslog(
+ 'info|local1',
+ $self->loc->N("%s enabled but stopped - disabling it",
+ $ntpd
+ )
+ );
+ # enabled but stopped, disabling it
+ # NOTE this happens tipically on VM if not well configured
+ $self->setEmbeddedNTP(0);
+ }
+ else {
+ # coosing the first one of the list that is not running
+ $ntpd = $list->[0];
+ }
+ }
- return "systemd-timesyncd" if ($self->ntp_configuration_file() eq "/etc/systemd/timesyncd.conf");
+ return $ntpd;
}
#=============================================================