aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2015-03-25 12:36:24 +0100
committerAngelo Naselli <anaselli@linux.it>2015-03-25 12:36:24 +0100
commit143675198e9c0fcef3335affa224c6b9799a9a6b (patch)
treec20c6367de27330fd30ade94edee7695b3b626df
parent7d4134a7fdc5651e90b7aefbda95c5a1998ec3c6 (diff)
downloadcolin-keep-143675198e9c0fcef3335affa224c6b9799a9a6b.tar
colin-keep-143675198e9c0fcef3335affa224c6b9799a9a6b.tar.gz
colin-keep-143675198e9c0fcef3335affa224c6b9799a9a6b.tar.bz2
colin-keep-143675198e9c0fcef3335affa224c6b9799a9a6b.tar.xz
colin-keep-143675198e9c0fcef3335affa224c6b9799a9a6b.zip
fixed isNTPRunning and its test
-rw-r--r--lib/ManaTools/Shared/TimeZone.pm48
-rw-r--r--t/04-Shared_TimeZone.t4
2 files changed, 14 insertions, 38 deletions
diff --git a/lib/ManaTools/Shared/TimeZone.pm b/lib/ManaTools/Shared/TimeZone.pm
index d481bf2..121a123 100644
--- a/lib/ManaTools/Shared/TimeZone.pm
+++ b/lib/ManaTools/Shared/TimeZone.pm
@@ -165,7 +165,7 @@ sub _ntp_program_init {
# 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 "" if !$list;
my $ntpd;
my $isRunning = 0;
@@ -891,43 +891,19 @@ sub isNTPRunning {
my $self = shift;
my $ntpd = $self->ntp_program;
- my $isRunning = $self->sh_services->is_service_running($ntpd);
+ my $isRunning = $ntpd ? $self->sh_services->is_service_running($ntpd) : 0;
if (!$isRunning) {
- my @ntp_service = ("chronyd", "ntpd");
- foreach ( @ntp_service ) {
- $ntpd = $_;
- $isRunning = $self->sh_services->is_service_running($ntpd);
- last if $isRunning;
- }
- if ($isRunning) {
- $self->ntp_program($ntpd);
- if ($ntpd eq "chronyd") {
- $self->ntp_configuration_file("/etc/chrony.conf");
- }
- elsif ($ntpd eq "ntpd") {
- $self->ntp_configuration_file("/etc/ntp.conf");
- }
- }
- else {
- # fallback systemd-timesyncd
-
- if ($self->getEmbeddedNTP()) {
- $ntpd = "systemd-timesyncd";
- $self->ntp_program($ntpd);
- $self->ntp_configuration_file("/etc/systemd/timesyncd.conf");
- $isRunning = $self->sh_services->is_service_running($ntpd);
- # if it is not started you cannot set time with NTP true
- if (!$isRunning) {
- Sys::Syslog::syslog(
- 'info|local1',
- $self->loc->N("%s enabled but stopped - disabling it",
- $ntpd
- )
- );
- $self->setEmbeddedNTP(0);
- }
- }
+ # NOTE fix systemd-timesyncd problem that prevents to set time
+ if ($self->getEmbeddedNTP()) {
+ $ntpd = "systemd-timesyncd";
+ Sys::Syslog::syslog(
+ 'info|local1',
+ $self->loc->N("%s enabled but stopped - disabling it",
+ $ntpd
+ )
+ );
+ $self->setEmbeddedNTP(0);
}
}
diff --git a/t/04-Shared_TimeZone.t b/t/04-Shared_TimeZone.t
index 21dd2e7..a88733b 100644
--- a/t/04-Shared_TimeZone.t
+++ b/t/04-Shared_TimeZone.t
@@ -16,10 +16,10 @@ BEGIN {
diag Dumper($h);
ok (my $currService = $tz->ntp_program(), 'ntp_program');
diag "ntp_program got: < " . $currService . " >";
+ ok (my $a = ($tz->isNTPRunning() ? "running" : "not running"), 'isNTPRunning');
+ diag "Check if " . $currService . " is running got: < " . $a . " >";
ok (my $s = $tz->ntpCurrentServer(), 'currentNTPServer');
diag "ntpCurrentServer got: < " . ($s ? $s : "none") . " >";
- ok (my $a = ($tz->isNTPRunning() ? "running" : "not running"), 'isNTPRunning');
- diag "isNTPRunning got: < " . $a . " >";
ok (my @pairs = $tz->ntpServiceConfigPairs(), 'ntpServiceConfigPairs');
diag Dumper(@pairs);
for my $pair (@pairs) {