diff options
author | Alex Harpin <development@landsofshadow.co.uk> | 2015-02-28 10:32:29 +0000 |
---|---|---|
committer | Alex Harpin <development@landsofshadow.co.uk> | 2015-02-28 10:32:29 +0000 |
commit | 93afdd6e8d13450e5229ccb22474bdea86bf3d1d (patch) | |
tree | 527e0cc2296280090746ed460e7180ac4b10f069 | |
parent | 3cb22d19f5edf6e2968c54b8fe3cfc5c13f0bf67 (diff) | |
download | vyatta-cfg-system-93afdd6e8d13450e5229ccb22474bdea86bf3d1d.tar.gz vyatta-cfg-system-93afdd6e8d13450e5229ccb22474bdea86bf3d1d.zip |
vyatta-cfg-system: update new ntp updating routine to work with dhcp
Update the new NTP updating routines so they operate outside of
configuration mode (dhcp triggered updates). This also requires
changes to the vyatta-dhcp3 package (see Bug #500)
Bug #94 http://bugzilla.vyos.net/show_bug.cgi?id=94
-rwxr-xr-x | scripts/system/vyatta_update_ntp.pl | 30 | ||||
-rwxr-xr-x | scripts/system/vyatta_update_resolv.pl | 8 |
2 files changed, 30 insertions, 8 deletions
diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl index 2f9b29f1..f32a9407 100755 --- a/scripts/system/vyatta_update_ntp.pl +++ b/scripts/system/vyatta_update_ntp.pl @@ -22,8 +22,12 @@ use strict; use lib "/opt/vyatta/share/perl5"; use Vyatta::Config; use NetAddr::IP; +use Getopt::Long; -die "$0 expects no arguments\n" if (@ARGV); +my $dhclient_script = 0; + +GetOptions("dhclient-script=i" => \$dhclient_script, +); sub ntp_format { my ($cidr_or_host) = @_; @@ -72,22 +76,36 @@ foreach my $line (@ntp) { } } -if ($cfg->exists("server")) { +my @servers; +my @clients; + +if ($dhclient_script == 1) { + @servers = $cfg->listOrigNodes("server"); + @clients = $cfg->returnOrigValues("client address"); +} else { + @servers = $cfg->listNodes("server"); + @clients = $cfg->returnValues("client address"); +} + +if (scalar(@servers) > 0) { print $output "# Servers\n\n"; - foreach my $server ($cfg->listNodes("server")) { + foreach my $server (@servers) { my $server_addr = ntp_format($server); print $output "server $server_addr iburst"; for my $property (qw(dynamic noselect preempt prefer)) { - print $output " $property" if ($cfg->exists("server $server $property")); + if ($dhclient_script == 1) { + print $output " $property" if ($cfg->existsOrig("server $server $property")); + } else { + print $output " $property" if ($cfg->exists("server $server $property")); + } } print $output "\nrestrict $server_addr nomodify notrap nopeer noquery\n"; } print $output "\n"; } -if ($cfg->exists("client")) { +if (scalar(@clients) > 0) { print $output "# Clients\n\n"; - my @clients = $cfg->returnValues("client address"); foreach my $client (@clients) { my $address = ntp_format($client); print $output "restrict $address nomodify notrap nopeer\n"; diff --git a/scripts/system/vyatta_update_resolv.pl b/scripts/system/vyatta_update_resolv.pl index 5de1f789..51617fce 100755 --- a/scripts/system/vyatta_update_resolv.pl +++ b/scripts/system/vyatta_update_resolv.pl @@ -30,6 +30,8 @@ use Vyatta::Config; my $dhclient_script = 0; my $config_mode = 0; +my $ntp_config = 0; + GetOptions("dhclient-script=i" => \$dhclient_script, "config-mode=i" => \$config_mode, ); @@ -43,6 +45,7 @@ my $disable_dhcp_nameservers = undef; if ($config_mode == 1) { $disable_dhcp_nameservers = $vc->exists('disable-dhcp-nameservers'); + $ntp_config = $vc->exists('ntp server'); } else { $disable_dhcp_nameservers = $vc->existsOrig('disable-dhcp-nameservers'); } @@ -50,6 +53,7 @@ if ($config_mode == 1) { if ($dhclient_script == 1) { @search_domains = $vc->returnOrigValues('domain-search domain'); $domain_name = $vc->returnOrigValue('domain-name'); + $ntp_config = $vc->existsOrig('ntp server'); } else { @search_domains = $vc->returnValues('domain-search domain'); $domain_name = $vc->returnValue('domain-name'); @@ -227,8 +231,8 @@ if (($dhclient_script == 1) || ($config_mode == 1)) { } if ($restart_ntp == 1) { # this corresponds to what is done in name-server/node.def as a fix for bug 1300 - if ($vc->exists("system ntp server") || $vc->existsOrig("system ntp server")) { - system("sudo /opt/vyatta/sbin/vyatta_update_ntp.pl"); + if ($ntp_config == 1) { + system("sudo /opt/vyatta/sbin/vyatta_update_ntp.pl --dhclient-script $dhclient_script"); my $cmd_ntp_restart = "if [ -f /etc/ntp.conf ] && grep -q '^server' /etc/ntp.conf; then /usr/sbin/invoke-rc.d ntp restart >&/dev/null; fi &"; system($cmd_ntp_restart); } |