diff options
author | David Walser <luigiwalser@mageia.org> | 2013-11-17 19:00:07 +0000 |
---|---|---|
committer | Colin Guthrie <colin@mageia.org> | 2013-11-17 20:41:41 +0000 |
commit | d54857e5704e52bc93d810250732affc82e1d65f (patch) | |
tree | fbaccf45e44d72d4facdd803a1279baa66c14618 /perl-install | |
parent | 6298fe9b2ec4be3c8845a0ab39c90ad76ea7a49e (diff) | |
download | drakx-d54857e5704e52bc93d810250732affc82e1d65f.tar drakx-d54857e5704e52bc93d810250732affc82e1d65f.tar.gz drakx-d54857e5704e52bc93d810250732affc82e1d65f.tar.bz2 drakx-d54857e5704e52bc93d810250732affc82e1d65f.tar.xz drakx-d54857e5704e52bc93d810250732affc82e1d65f.zip |
Add chrony support to drakclock mga#11092
v2 (by Colin Guthrie)
* Fix external variable reference (my -> our + $ when using it)
* Drop systemd cgroup filesystem check as the path has changed now
(prefer "systemctl is-active foo.service" instead)
* Add iburst to chrony config server definitions (triggers sync at
startup)
* Don't use ntpdate with chrony - rather chronyc waitsync
* Don't bother checking for ntp in finish-install - just use chrony
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/NEWS | 2 | ||||
-rw-r--r-- | perl-install/install/steps.pm | 9 | ||||
-rw-r--r-- | perl-install/services.pm | 1 | ||||
-rwxr-xr-x | perl-install/standalone/drakclock | 43 | ||||
-rwxr-xr-x | perl-install/standalone/finish-install | 2 | ||||
-rw-r--r-- | perl-install/timezone.pm | 19 |
6 files changed, 49 insertions, 27 deletions
diff --git a/perl-install/NEWS b/perl-install/NEWS index 4736ff288..85f894eac 100644 --- a/perl-install/NEWS +++ b/perl-install/NEWS @@ -1,3 +1,5 @@ +- add chrony support to drakclock mga#11092 + Version 15.73 - 12 November 2013 - polkit: fix wrappers to properly escape arguments when calling the binary diff --git a/perl-install/install/steps.pm b/perl-install/install/steps.pm index 58236da2e..f51d50729 100644 --- a/perl-install/install/steps.pm +++ b/perl-install/install/steps.pm @@ -689,7 +689,14 @@ sub configureTimezone { my ($o) = @_; install::any::preConfigureTimezone($o); - $o->pkg_install('ntp') if $o->{timezone}{ntp}; + if ($o->{timezone}{ntp}) { + # We prefer chrony, but we'll deal with ntpd for the sake of upgrades + my $pkg = install::pkgs::packageByName($o->{packages}, 'chrony'); + unless ($pkg && $pkg->flag_installed) { + $pkg = install::pkgs::packageByName($o->{packages}, 'ntp'); + $o->pkg_install('chrony') unless ($pkg && $pkg->flag_installed); + } + } require timezone; timezone::write($o->{timezone}); diff --git a/perl-install/services.pm b/perl-install/services.pm index c7260d549..09f31ba20 100644 --- a/perl-install/services.pm +++ b/perl-install/services.pm @@ -23,6 +23,7 @@ It can also be used for shutting down the machine when the battery is low."), atd => N_("Runs commands scheduled by the at command at the time specified when at was run, and runs batch commands when the load average is low enough."), 'avahi-deamon' => N_("Avahi is a ZeroConf daemon which implements an mDNS stack"), +chronyd => N_("An NTP client/server"), cpufreq => N_("Set CPU frequency settings"), crond => N_("cron is a standard UNIX program that runs user-specified programs at periodic scheduled times. vixie cron adds a number of features to the basic diff --git a/perl-install/standalone/drakclock b/perl-install/standalone/drakclock index 0ca3c5b51..de60872f6 100755 --- a/perl-install/standalone/drakclock +++ b/perl-install/standalone/drakclock @@ -23,9 +23,8 @@ my $its_reset = 0; $ugtk2::wm_icon = "/usr/share/mcc/themes/default/time-mdk.png"; -my $ntpfile = '/etc/ntp.conf'; -my $ntpdlock = '/var/lock/subsys/ntpd'; -my $ntpdsystemdlock = '/sys/fs/cgroup/systemd/system/ntpd.service'; +my $ntpd = $timezone::ntp . 'd'; +my $ntpfile = '/etc/' . $timezone::ntp . '.conf'; my $my_win = ugtk2->new(N("Date, Clock & Time Zone Settings")); @@ -77,7 +76,7 @@ $my_win->{window}->add(gtknew('VBox', border_width => $::isEmbedded ? 0 : 5, chi 0, gtksignal_connect(gtkset_active($check_ntp = gtknew('CheckButton', text => N("Enable Network Time Protocol")), $mode), clicked => sub { $mode = !$mode; $hb_ntp->set_sensitive($mode); - if ($mode == 1 && !$in->do_pkgs->is_installed('ntp')) { + if ($mode == 1 && !$in->do_pkgs->is_installed('ntp') && !$in->do_pkgs->is_installed('chrony')) { install_ntp(); } }), @@ -116,15 +115,22 @@ $my_win->{window}->add(gtknew('VBox', border_width => $::isEmbedded ? 0 : 5, chi return; } timezone::set_ntp_server($choosed_serv); - system(qw(/sbin/chkconfig --level 35 ntpd on)); - # FIXME: Change to use systemctl when will not support old iniscript anymore - system(qw(service ntpd stop)); + system('systemctl', 'enable', "$ntpd.service"); + system('systemctl', 'stop', "$ntpd.service"); #verify that we have a valid hostname (thx sam) $choosed_serv =~ s/[^-a-zA-Z0-9.]//g; - if (!system("/usr/sbin/ntpdate", $choosed_serv)) { + my $sync_ok; + if ($ntpd == "chronyd") { + system('systemctl', 'start', "$ntpd.service"); + # Wait up to 30s for sync + $sync_ok = !system('chronyc', 'waitsync', '30', '0.1'); + system('systemctl', 'stop', "$ntpd.service") if (!$sync_ok); + } else { + $sync_ok = !system('/usr/sbin/ntpdate', $choosed_serv); + system('systemctl', 'start', "$ntpd.service") if ($sync_ok); + } + if ($sync_ok) { update_time(); #- get the new time before updating the hwclock - # FIXME: Change to use systemctl when will not support old iniscript anymore - system(qw(service ntpd start)); $need_date = 0; } else { $in->ask_from_no_check({ @@ -135,13 +141,9 @@ $my_win->{window}->add(gtknew('VBox', border_width => $::isEmbedded ? 0 : 5, chi }, []) or return; } } else { - if (-e $ntpdlock) { - system(qw(service ntpd stop)); - system(qw(/sbin/chkconfig --level 35 ntpd off)); - } - elsif (-e $ntpdsystemdlock) { - system(qw(systemctl stop ntpd.service)); - system(qw(systemctl disable ntpd.service)); + if (is_ntp_daemon_running()) { + system('systemctl', 'stop', "$ntpd.service"); + system('systemctl', 'disable', "$ntpd.service"); } } if ($need_date) { @@ -174,7 +176,7 @@ $time_box->set_direction('ltr'); my $servers = get_server(); $combo_ntpserver->set_popdown_strings(@$servers); -if (-e $ntpfile && (-e $ntpdsystemdlock || -e $ntpdlock)) { +if (-e $ntpfile && is_ntp_daemon_running()) { $ntp = timezone::ntp_server(); $ntp and ntp_widget_state(1); my $fullntp = $ntp; @@ -238,9 +240,12 @@ sub ntp_widget_state { } sub install_ntp() { $my_win->{window}->set_sensitive(0); - $in->do_pkgs->ensure_is_installed('ntp') or ntp_widget_state(0); + $in->do_pkgs->ensure_is_installed('chrony') or ntp_widget_state(0); $my_win->{window}->set_sensitive(1); } +sub is_ntp_daemon_running() { + !system("systemctl is-active $ntpd.service >/dev/null"); +} sub get_server() { my $servs = timezone::ntp_servers(); [ map { "$servs->{$_}: $_" } sort { $servs->{$a} cmp $servs->{$b} || $a cmp $b } keys %$servs ]; diff --git a/perl-install/standalone/finish-install b/perl-install/standalone/finish-install index 20b0a179f..16de321ea 100755 --- a/perl-install/standalone/finish-install +++ b/perl-install/standalone/finish-install @@ -75,7 +75,7 @@ sub ask_timezone() { $timezone->{timezone} = timezone::bestTimezone($locale->{country}) if $locale->{country}; any::configure_timezone($in, $timezone, 'ask_gmt', lc(get_conf('TIMEZONE')) eq 'simplified'); - $in->do_pkgs->ensure_is_installed('ntp') if $timezone->{ntp}; + $in->do_pkgs->ensure_is_installed('chrony') if $timezone->{ntp}; timezone::write($timezone); #- reload sys clock from hc once we know the real timezone diff --git a/perl-install/timezone.pm b/perl-install/timezone.pm index d9a5dc246..b4b4cfe89 100644 --- a/perl-install/timezone.pm +++ b/perl-install/timezone.pm @@ -24,15 +24,20 @@ sub read() { { timezone => $t{ZONE}, UTC => text2bool($t{UTC}) }; } -my $ntp_conf_file = "/etc/ntp.conf"; +our $ntp = "chrony"; +my $servername_config_suffix = " iburst"; +unless (-f $::prefix . "/etc/" . $ntp . ".conf") { + $ntp = "ntp"; + $servername_config_suffix = ""; +} sub ntp_server() { - find { $_ ne '127.127.1.0' } map { if_(/^\s*server\s+(\S*)/, $1) } cat_($::prefix . $ntp_conf_file); + find { $_ ne '127.127.1.0' } map { if_(/^\s*server\s+(\S*)/, $1) } cat_($::prefix . "/etc/" . $ntp . ".conf"); } sub set_ntp_server { my ($server) = @_; - my $f = $::prefix . $ntp_conf_file; + my $f = $::prefix . "/etc/" . $ntp . ".conf"; -f $f or return; my $pool_match = qr/\.pool\.ntp\.org$/; @@ -41,14 +46,16 @@ sub set_ntp_server { my $added = 0; substInFile { if (/^#?\s*server\s+(\S*)/ && $1 ne '127.127.1.0') { - $_ = $added ? $_ =~ $pool_match ? undef : "#server $1\n" : join('', map { "server $_\n" } @servers); + $_ = $added ? $_ =~ $pool_match ? undef : "#server $1\n" : join('', map { "server $_$servername_config_suffix\n" } @servers); $added = 1; } } $f; - output_p("$::prefix/etc/ntp/step-tickers", join('', map { "$_\n" } @servers)); + if ($ntp eq "ntp") { + output_p("$::prefix/etc/ntp/step-tickers", join('', map { "$_\n" } @servers)); + } require services; - services::set_status('ntpd', to_bool($server), $::isInstall); + services::set_status($ntp . 'd', to_bool($server), $::isInstall); } sub write { |