From d47ecbf8e2c9fe355f5afca77a2dd71f5e65f87f Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 13 Oct 2010 14:24:02 -0700 Subject: Migrate NTP server to services ntp Allows starting NTP server once at boot speeding up boot time and allows specifying some NTP server options --- Makefile.am | 3 +- cfg-version/system@3 | 0 cfg-version/system@4 | 0 scripts/system/vyatta_update_ntp.pl | 47 ++++++++++++++++++++++ templates/service/ntp/node.def | 18 +++++++++ templates/service/ntp/server/node.def | 3 ++ .../service/ntp/server/node.tag/dynamic/node.def | 2 + .../service/ntp/server/node.tag/noselect/node.def | 1 + .../service/ntp/server/node.tag/preempt/node.def | 1 + .../service/ntp/server/node.tag/prefer/node.def | 1 + templates/system/ntp-server/node.def | 18 --------- 11 files changed, 75 insertions(+), 19 deletions(-) delete mode 100644 cfg-version/system@3 create mode 100644 cfg-version/system@4 create mode 100644 scripts/system/vyatta_update_ntp.pl create mode 100644 templates/service/ntp/node.def create mode 100644 templates/service/ntp/server/node.def create mode 100644 templates/service/ntp/server/node.tag/dynamic/node.def create mode 100644 templates/service/ntp/server/node.tag/noselect/node.def create mode 100644 templates/service/ntp/server/node.tag/preempt/node.def create mode 100644 templates/service/ntp/server/node.tag/prefer/node.def delete mode 100644 templates/system/ntp-server/node.def diff --git a/Makefile.am b/Makefile.am index 86e2aec8..1e7b1fcc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ sbin_SCRIPTS += scripts/system/vyatta_update_login.pl sbin_SCRIPTS += scripts/system/vyatta_update_logrotate.pl sbin_SCRIPTS += scripts/system/vyatta_update_resolv.pl sbin_SCRIPTS += scripts/system/vyatta_update_syslog.pl +sbin_SCRIPTS += scripts/system/vyatta_update_ntp.pl sbin_SCRIPTS += scripts/system/vyatta_update_telnet sbin_SCRIPTS += scripts/snmp/vyatta-snmp.pl sbin_SCRIPTS += scripts/snmp/snmpd.init @@ -90,7 +91,7 @@ rsyslogdir = /etc/rsyslog.d rsyslog_DATA = sysconf/vyatta-log.conf curver_DATA = cfg-version/vrrp@1 -curver_DATA += cfg-version/system@3 +curver_DATA += cfg-version/system@4 cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/cfg-version/system@3 b/cfg-version/system@3 deleted file mode 100644 index e69de29b..00000000 diff --git a/cfg-version/system@4 b/cfg-version/system@4 new file mode 100644 index 00000000..e69de29b diff --git a/scripts/system/vyatta_update_ntp.pl b/scripts/system/vyatta_update_ntp.pl new file mode 100644 index 00000000..50af76fe --- /dev/null +++ b/scripts/system/vyatta_update_ntp.pl @@ -0,0 +1,47 @@ +#! /usr/bin/perl + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# All Rights Reserved. +# +# **** End License **** + +# Filter ntp.conf - remove old servers and add current ones + +use strict; +use lib "/opt/vyatta/share/perl5"; +use Vyatta::Config; + +die "$0 expects no arguments\n" if (@ARGV); + +# Weed existing servers from config +print grep {! /^server/ } ; + +my $cfg = new Vyatta::Config; +$cfg->setLevel("service ntp"); + +foreach my $server ($cfg->listNodes("server")) { + print "server $server iburst"; + for my $property qw(dynamic noselect preempt prefer) { + print " $property" if ($cfg->exists("$server $property")); + } + print "\n"; +} + +exit 0; + + + + + + diff --git a/templates/service/ntp/node.def b/templates/service/ntp/node.def new file mode 100644 index 00000000..c5d99724 --- /dev/null +++ b/templates/service/ntp/node.def @@ -0,0 +1,18 @@ +priority: 400 +help: Network Time Protocol (NTP) configuration + +end: + /opt/vyatta/sbin/vyatta_update_ntp.pl /tmp/ntp.conf + sudo cp -b /tmp/ntp.conf /etc/ntp.conf + if grep -q '^server' /etc/ntp.conf + then + if /usr/sbin/invoke-rc.d ntp status >/dev/null + then + sudo /usr/sbin/invoke-rc.d ntp force-reload + else + sudo /usr/sbin/invoke-rc.d ntp start + fi + else + sudo /usr/sbin/invoke-rc.d ntp stop + fi + rm -f /tmp/ntp.conf diff --git a/templates/service/ntp/server/node.def b/templates/service/ntp/server/node.def new file mode 100644 index 00000000..383bd992 --- /dev/null +++ b/templates/service/ntp/server/node.def @@ -0,0 +1,3 @@ +tag: +type: txt +help: Network Time Protocol (NTP) server diff --git a/templates/service/ntp/server/node.tag/dynamic/node.def b/templates/service/ntp/server/node.tag/dynamic/node.def new file mode 100644 index 00000000..0a7df0c0 --- /dev/null +++ b/templates/service/ntp/server/node.tag/dynamic/node.def @@ -0,0 +1,2 @@ +help: Allow server to be configured eve if not reachable + diff --git a/templates/service/ntp/server/node.tag/noselect/node.def b/templates/service/ntp/server/node.tag/noselect/node.def new file mode 100644 index 00000000..e2e061b5 --- /dev/null +++ b/templates/service/ntp/server/node.tag/noselect/node.def @@ -0,0 +1 @@ +help: Marks the server as unused diff --git a/templates/service/ntp/server/node.tag/preempt/node.def b/templates/service/ntp/server/node.tag/preempt/node.def new file mode 100644 index 00000000..ca89efa1 --- /dev/null +++ b/templates/service/ntp/server/node.tag/preempt/node.def @@ -0,0 +1 @@ +help: Specifies the association as preemptable rather than the default persistent diff --git a/templates/service/ntp/server/node.tag/prefer/node.def b/templates/service/ntp/server/node.tag/prefer/node.def new file mode 100644 index 00000000..4855fd41 --- /dev/null +++ b/templates/service/ntp/server/node.tag/prefer/node.def @@ -0,0 +1 @@ +help: Marks the server as preferred diff --git a/templates/system/ntp-server/node.def b/templates/system/ntp-server/node.def deleted file mode 100644 index e1596161..00000000 --- a/templates/system/ntp-server/node.def +++ /dev/null @@ -1,18 +0,0 @@ -multi: -priority: 400 -type: txt -help: Network Time Protocol (NTP) server -create: if ! grep -q '^server $VAR(@) ' /etc/ntp.conf - then sudo sh -c \ - "echo \"server $VAR(@) iburst\" >> /etc/ntp.conf; \ - /usr/sbin/invoke-rc.d ntp restart" - elif ! /usr/sbin/invoke-rc.d ntp status - then sudo /usr/sbin/invoke-rc.d ntp start - fi -delete: if grep -q '^server $VAR(@) ' /etc/ntp.conf - then sudo sed -i '/^server $VAR(@) /d' /etc/ntp.conf - if grep -q '^server ' /etc/ntp.conf - then sudo /usr/sbin/invoke-rc.d ntp restart - else sudo /usr/sbin/invoke-rc.d ntp stop - fi - fi -- cgit v1.2.3