From 32721433e01f18dd83a295ed4e3579ad40537354 Mon Sep 17 00:00:00 2001 From: John Klug Date: Mon, 19 Dec 2016 19:27:22 -0600 Subject: add features to busybox to debug ntp and set nice to -20 for ntp --- recipes-support/ntp/files/ntpd-init.patch | 11 +++++++++++ recipes-support/ntp/ntp_4.2.6p5.bbappend | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 recipes-support/ntp/files/ntpd-init.patch create mode 100644 recipes-support/ntp/ntp_4.2.6p5.bbappend (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntpd-init.patch b/recipes-support/ntp/files/ntpd-init.patch new file mode 100644 index 0000000..fc388f8 --- /dev/null +++ b/recipes-support/ntp/files/ntpd-init.patch @@ -0,0 +1,11 @@ +--- old/ntpd 2016-12-19 18:11:58.022663976 -0600 ++++ new/ntpd 2016-12-19 18:12:56.618663852 -0600 +@@ -23,7 +23,7 @@ + # this. If ntpd seems to disappear after a while assume TICKADJ + # above is set to a totally incorrect value. + echo -n "Starting ntpd: " +- start-stop-daemon --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" ++ start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" + echo "done" + } + stopdaemon(){ diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend new file mode 100644 index 0000000..528c6c9 --- /dev/null +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -0,0 +1,11 @@ +PR .= ".mlinux1" + +SRC_URI += " file://ntpd-init.patch;patchdir=.. \ + " +FILESEXTRAPATHS_prepend := "${THISDIR}/files" + +python do_patch_prepend () { + import os + cwd = os.getcwd() + bb.note("Hello %s",cwd) +} -- cgit v1.2.3 From 29d9d49e75f3371413efce6b67a850d1a54b3bea Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 20 Dec 2016 17:26:54 -0600 Subject: Add GPS specific configuration, add empty files/directories with permissions --- recipes-support/ntp/files/ntp.conf.patch | 51 ++++++++++++++++++++++++++++++++ recipes-support/ntp/ntp_4.2.6p5.bbappend | 15 ++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 recipes-support/ntp/files/ntp.conf.patch (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntp.conf.patch b/recipes-support/ntp/files/ntp.conf.patch new file mode 100644 index 0000000..0700553 --- /dev/null +++ b/recipes-support/ntp/files/ntp.conf.patch @@ -0,0 +1,51 @@ +diff -u old/ntp.conf new/ntp.conf +--- old/ntp.conf 2016-12-20 15:41:04.992738081 -0600 ++++ new/ntp.conf 2016-12-20 16:07:40.632709506 -0600 +@@ -1,7 +1,19 @@ +-# This is the most basic ntp configuration file + # The driftfile must remain in a place specific to this + # machine - it records the machine specific clock error + driftfile /etc/ntp.drift ++ ++# The following code is for evaluating the timeserver. ++# Remove the # to activate the statistics ++# statistics loopstats ++# statistics peerstats ++# statsdir /var/log/ntpstats ++# filegen peerstats file peerstats type day link enable ++# filegen loopstats file loopstats type day link enable ++ ++# This is the US timeserver pool. You should use a pool ++# close to your location. ++#pool us.pool.ntp.org iburst ++ + # This should be a server that is close (in IP terms) + # to the machine. Add other servers as required. + # Unless you un-comment the line below ntpd will sync +@@ -9,8 +21,26 @@ + # + # server time.server.example.com + # ++ ++logfile /var/log/ntp.log ++ ++restrict default kod nomodify notrap nopeer noquery ++restrict -6 default kod nomodify notrap nopeer noquery ++restrict 127.0.0.1 mask 255.255.255.0 ++restrict -6 ::1 ++ ++# GPS Serial data reference (NTP0) ++server 127.127.28.0 ++fudge 127.127.28.0 time1 0.080 refid GPS ++ ++# GPS PPS reference (NTP2) ++server 127.127.28.2 prefer ++fudge 127.127.28.2 time1 0.000 refid PPS ++ + # Using local hardware clock as fallback + # Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself ++# The stratum should be a high value so this does not get chosen ++# except in dire circumstances. + server 127.127.1.0 + fudge 127.127.1.0 stratum 14 + # Defining a default security setting diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend index 528c6c9..9c6419e 100644 --- a/recipes-support/ntp/ntp_4.2.6p5.bbappend +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -1,11 +1,22 @@ PR .= ".mlinux1" SRC_URI += " file://ntpd-init.patch;patchdir=.. \ + file://ntp.conf.patch;patchdir=.. \ " FILESEXTRAPATHS_prepend := "${THISDIR}/files" python do_patch_prepend () { import os - cwd = os.getcwd() - bb.note("Hello %s",cwd) } +pkg_postinst_${PN} () { + touch /etc/ntp.drift + chown ntp:ntp /etc/ntp.drift + chmod 664 /etc/ntp.drift + if ! [[ -d /var/log/ntpstats ]] ; then + mkdir -p /var/log/ntpstats + fi + + chown ntp:ntp /var/log/ntpstats + chmod 775 /var/log/ntpstats +} + -- cgit v1.2.3 From 2ba73a35c4907336858320b31ce515a6aa10698f Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 21 Dec 2016 08:46:44 -0600 Subject: ntp.drift must be in a directory writable by ntp --- recipes-support/ntp/files/ntp.conf.patch | 12 +++++++----- recipes-support/ntp/ntp_4.2.6p5.bbappend | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntp.conf.patch b/recipes-support/ntp/files/ntp.conf.patch index 0700553..499dac5 100644 --- a/recipes-support/ntp/files/ntp.conf.patch +++ b/recipes-support/ntp/files/ntp.conf.patch @@ -1,11 +1,13 @@ diff -u old/ntp.conf new/ntp.conf ---- old/ntp.conf 2016-12-20 15:41:04.992738081 -0600 -+++ new/ntp.conf 2016-12-20 16:07:40.632709506 -0600 -@@ -1,7 +1,19 @@ +--- old/ntp.conf 2016-12-21 08:36:33.887646960 -0600 ++++ new/ntp.conf 2016-12-21 08:37:41.115645756 -0600 +@@ -1,7 +1,20 @@ -# This is the most basic ntp configuration file # The driftfile must remain in a place specific to this # machine - it records the machine specific clock error - driftfile /etc/ntp.drift +-driftfile /etc/ntp.drift ++# Driftfile must be in a directory owned by ntp ++driftfile /var/lib/ntp/ntp.drift + +# The following code is for evaluating the timeserver. +# Remove the # to activate the statistics @@ -22,7 +24,7 @@ diff -u old/ntp.conf new/ntp.conf # This should be a server that is close (in IP terms) # to the machine. Add other servers as required. # Unless you un-comment the line below ntpd will sync -@@ -9,8 +21,26 @@ +@@ -9,8 +22,26 @@ # # server time.server.example.com # diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend index 9c6419e..4651611 100644 --- a/recipes-support/ntp/ntp_4.2.6p5.bbappend +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -9,14 +9,18 @@ python do_patch_prepend () { import os } pkg_postinst_${PN} () { - touch /etc/ntp.drift - chown ntp:ntp /etc/ntp.drift - chmod 664 /etc/ntp.drift if ! [[ -d /var/log/ntpstats ]] ; then mkdir -p /var/log/ntpstats fi - chown ntp:ntp /var/log/ntpstats chmod 775 /var/log/ntpstats + + if ! [[ -d /var/lib/ntp ]] ; then + mkdir -p /var/lib/ntp + fi + drfile="/var/lib/ntp/ntp.drift" + touch ${drfile} + chown ntp:ntp ${drfile} + chmod 664 ${drfile} } -- cgit v1.2.3 From 0f6b23997881f6e683f425cb8529434248a50577 Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 21 Dec 2016 12:18:39 -0600 Subject: Fix up stats directory permissions. --- recipes-support/ntp/ntp_4.2.6p5.bbappend | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend index 4651611..7928608 100644 --- a/recipes-support/ntp/ntp_4.2.6p5.bbappend +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -9,18 +9,20 @@ python do_patch_prepend () { import os } pkg_postinst_${PN} () { - if ! [[ -d /var/log/ntpstats ]] ; then - mkdir -p /var/log/ntpstats + sdir=/var/log/ntpstats + if ! [[ -d ${sdir} ]] ; then + mkdir -p ${sdir} fi - chown ntp:ntp /var/log/ntpstats - chmod 775 /var/log/ntpstats + chown ntp:ntp ${sdir} + chmod 775 ${sdir} - if ! [[ -d /var/lib/ntp ]] ; then - mkdir -p /var/lib/ntp + drdir=/var/lib/ntp + if ! [[ -d ${drdir} ]] ; then + mkdir -p ${drdir} fi - drfile="/var/lib/ntp/ntp.drift" + drfile="${drdir}/ntp.drift" touch ${drfile} - chown ntp:ntp ${drfile} chmod 664 ${drfile} + chown -R ntp:ntp ${drdir} } -- cgit v1.2.3 From ff32f2719b24a05c160a7110fd08745b348a23c3 Mon Sep 17 00:00:00 2001 From: John Klug Date: Thu, 12 Jan 2017 18:19:32 -0600 Subject: Delay ntp start when dependent on gpsd. --- recipes-support/ntp/files/ntpd-init.patch | 57 ++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntpd-init.patch b/recipes-support/ntp/files/ntpd-init.patch index fc388f8..05a6a8e 100644 --- a/recipes-support/ntp/files/ntpd-init.patch +++ b/recipes-support/ntp/files/ntpd-init.patch @@ -1,11 +1,52 @@ ---- old/ntpd 2016-12-19 18:11:58.022663976 -0600 -+++ new/ntpd 2016-12-19 18:12:56.618663852 -0600 -@@ -23,7 +23,7 @@ - # this. If ntpd seems to disappear after a while assume TICKADJ - # above is set to a totally incorrect value. - echo -n "Starting ntpd: " +--- old/ntpd 2017-01-12 18:10:40.208157197 -0600 ++++ new/ntpd 2017-01-12 18:14:27.952154318 -0600 +@@ -1,6 +1,8 @@ +-#! /bin/sh ++#! /bin/bash + # ++. /etc/default/ntpd + PATH=/sbin:/bin:/usr/bin:/usr/sbin ++GNSSRST=/sys/devices/platform/mts-io/gnss-reset + + # ntpd init.d script for ntpdc from ntp.isc.org + test -x /usr/sbin/ntpd -a -r /etc/ntp.conf || exit 0 +@@ -18,13 +20,32 @@ + } + } + startdaemon(){ +- # The -g option allows ntpd to step the time to correct it just +- # once. The daemon will exit if the clock drifts too much after +- # this. If ntpd seems to disappear after a while assume TICKADJ +- # above is set to a totally incorrect value. +- echo -n "Starting ntpd: " - start-stop-daemon --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" -+ start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" - echo "done" +- echo "done" ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd --test -- -u ntp:ntp -p /var/run/ntp.pid "$@" \ ++ || return 1 ++ if ((GPSD_REQUIRED == 1)) && [[ -L /dev/gps0 ]] && [[ -f "${GNSSRST}" ]]; then ++ . /etc/default/gpsd ++ # Could not get ntpd -gq to work with the GPS. ++ # So read the GPS time directly and set the system ++ # clock. ++ if ((SET_SYSTEM_CLOCK == 1)) && /usr/sbin/gpsd_ubx_settime ; then ++ # System time set by the GPS. ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" ++ else ++ # Need a GPS fix before startint ntp. ++ /usr/sbin/start-stop-daemon -b -n z1e9d3qb -N -20 --start -x /bin/bash -- -c "sleep $GPSD_WAIT_TIME;/etc/init.d/ntpd start" ++ fi ++ else ++ if ((SET_SYSTEM_CLOCK == 1)) ; then ++ ntpd -gq ++ shift ++ fi ++ ++ # The -g option allows ntpd to step the time to correct it just ++ # once. The daemon will exit if the clock drifts too much after ++ # this. If ntpd seems to disappear after a while assume TICKADJ ++ # above is set to a totally incorrect value. ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" ++ fi } stopdaemon(){ + echo -n "Stopping ntpd: " -- cgit v1.2.3 From 823edc2d6be48e9dc2dffda2f44c8dea5b7fc1e6 Mon Sep 17 00:00:00 2001 From: John Klug Date: Fri, 13 Jan 2017 18:48:22 -0600 Subject: Add /etc/default/ntpd to the ntp configuration. --- recipes-support/ntp/files/ntpd-default | 26 ++++++++++++++++++++++++++ recipes-support/ntp/ntp_4.2.6p5.bbappend | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 recipes-support/ntp/files/ntpd-default (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntpd-default b/recipes-support/ntp/files/ntpd-default new file mode 100644 index 0000000..85b8041 --- /dev/null +++ b/recipes-support/ntp/files/ntpd-default @@ -0,0 +1,26 @@ +# The GPSD_* parameters in this file are ignored +# if the uBlox GPS is not present. + +# Require a GPS lock/fix before starting NTP +# This is needed if we are not using NTP servers. +# NTP will not work with the GPS if the GPS is not +# locked before starting. +GPSD_REQUIRED=1 + +# Number of seconds to wait before checking if +# the GPS has a lock. +GPSD_WAIT_TIME=120 + +# Since the HW Clock could be off by a second or +# so, our GPS might get marked as a false ticker +# if we do not set the system clock to the GPS +# first. The current correct way to do this +# according to the GPS doc is ntpd -gq +# which must be done before ntpd is started. +# ntpd -gq apparently does not work with the GPS +# when tested with the clock one day off and no +# ntpd. +# If there is a uBlox GPS present, the time is +# read from the GPS to initialize the system time. +SET_SYSTEM_CLOCK=1 + diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend index 7928608..b656256 100644 --- a/recipes-support/ntp/ntp_4.2.6p5.bbappend +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -2,6 +2,7 @@ PR .= ".mlinux1" SRC_URI += " file://ntpd-init.patch;patchdir=.. \ file://ntp.conf.patch;patchdir=.. \ + file://ntpd-default \ " FILESEXTRAPATHS_prepend := "${THISDIR}/files" @@ -26,3 +27,20 @@ pkg_postinst_${PN} () { chown -R ntp:ntp ${drdir} } + +do_install_prepend() { + echo JAK In do_install_append in directory $(pwd), and D is ${D} + echo JAK In do_install_append sysconfdir is ${sysconfdir} + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/ntpd-default ${D}${sysconfdir}/default/ntpd.default + echo JAK In do_install_append default is $(ls ${D}cd${sysconfdir}/default/ntpd.default) +} +pkg_postinst_${PN}() { + update-alternatives --install ${sysconfdir}/default/ntpd ntpd-defaults ${sysconfdir}/default/ntpd.default 10 +} + +pkg_postrm_${PN}() { + update-alternatives --remove ntpd-defaults ${sysconfdir}/default/ntpd.default +} +FILES_${PN} += "${sysconfdir}/default/ntpd.default" +CONFFILES_${PN} += "${sysconfdir}/default/ntpd.default" -- cgit v1.2.3 From a439b62e1e91fbb6822e0e4a5b3714bd2e28b969 Mon Sep 17 00:00:00 2001 From: John Klug Date: Fri, 13 Jan 2017 19:24:21 -0600 Subject: Enhance the documentation for /etc/default/ntpd --- recipes-support/ntp/files/ntpd-default | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntpd-default b/recipes-support/ntp/files/ntpd-default index 85b8041..4811f46 100644 --- a/recipes-support/ntp/files/ntpd-default +++ b/recipes-support/ntp/files/ntpd-default @@ -5,22 +5,27 @@ # This is needed if we are not using NTP servers. # NTP will not work with the GPS if the GPS is not # locked before starting. +# See /etc/default/gpsd for the states required. GPSD_REQUIRED=1 -# Number of seconds to wait before checking if -# the GPS has a lock. +# Number of seconds between testing for a GPS +# lock prior to calling ntpd. GPSD_WAIT_TIME=120 # Since the HW Clock could be off by a second or # so, our GPS might get marked as a false ticker # if we do not set the system clock to the GPS # first. The current correct way to do this -# according to the GPS doc is ntpd -gq +# according to the ntp doc is ntpd -gq -c conffile # which must be done before ntpd is started. +# conffile should exclude the local clock, so it is +# ignored while doing the initial sync. # ntpd -gq apparently does not work with the GPS -# when tested with the clock one day off and no -# ntpd. +# when tested with the clock more than one day off +# and no ntpd. The gps shared memory is never polled. +# # If there is a uBlox GPS present, the time is -# read from the GPS to initialize the system time. +# read from the GPS to initialize the system time +# before NTP is started. SET_SYSTEM_CLOCK=1 -- cgit v1.2.3 From 3959907c3a6a8d78368de3c624155260a2d418fe Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 17 Jan 2017 12:06:49 -0600 Subject: Remove incorrect comments, and use syslog for logging --- recipes-support/ntp/files/ntp.conf.patch | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'recipes-support/ntp') diff --git a/recipes-support/ntp/files/ntp.conf.patch b/recipes-support/ntp/files/ntp.conf.patch index 499dac5..691d039 100644 --- a/recipes-support/ntp/files/ntp.conf.patch +++ b/recipes-support/ntp/files/ntp.conf.patch @@ -1,7 +1,7 @@ -diff -u old/ntp.conf new/ntp.conf ---- old/ntp.conf 2016-12-21 08:36:33.887646960 -0600 -+++ new/ntp.conf 2016-12-21 08:37:41.115645756 -0600 -@@ -1,7 +1,20 @@ +diff -Naur old/ntp.conf new/ntp.conf +--- old/ntp.conf 2017-01-17 12:00:15.560426583 -0600 ++++ new/ntp.conf 2017-01-17 12:02:11.968426337 -0600 +@@ -1,16 +1,44 @@ -# This is the most basic ntp configuration file # The driftfile must remain in a place specific to this # machine - it records the machine specific clock error @@ -23,20 +23,19 @@ diff -u old/ntp.conf new/ntp.conf + # This should be a server that is close (in IP terms) # to the machine. Add other servers as required. - # Unless you un-comment the line below ntpd will sync -@@ -9,8 +22,26 @@ +-# Unless you un-comment the line below ntpd will sync +-# only against the local system clock. # # server time.server.example.com # + -+logfile /var/log/ntp.log -+ +restrict default kod nomodify notrap nopeer noquery +restrict -6 default kod nomodify notrap nopeer noquery +restrict 127.0.0.1 mask 255.255.255.0 +restrict -6 ::1 + +# GPS Serial data reference (NTP0) ++# This sets the GPS 80 milliseconds slower than the PPS. +server 127.127.28.0 +fudge 127.127.28.0 time1 0.080 refid GPS + -- cgit v1.2.3