Message ID | 1539964343-10526-1-git-send-email-oscargomezf@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | [1/1] ntp: added S48ntpdate script | expand |
Oscar, On Fri, Oct 19, 2018 at 4:52 PM Oscar Gomez Fuente <oscargomezf@gmail.com> wrote: > > Signed-off-by: Oscar Gomez Fuente <oscargomezf@gmail.com> > --- > package/ntp/S48ntpdate | 30 ++++++++++++++++++++++++++++++ > package/ntp/S49ntp | 42 +++++++++++++++++++++--------------------- > package/ntp/ntp.mk | 7 +++++++ > 3 files changed, 58 insertions(+), 21 deletions(-) > create mode 100755 package/ntp/S48ntpdate > > diff --git a/package/ntp/S48ntpdate b/package/ntp/S48ntpdate > new file mode 100755 > index 0000000..a8d4d70 > --- /dev/null > +++ b/package/ntp/S48ntpdate > @@ -0,0 +1,30 @@ > +#! /bin/sh > + > +NAME=ntpdate > +NTP_SERVERS="0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org" > + > +start() { > + printf "Starting $NAME: " > + for ntpserver in $NTP_SERVERS > + do > + CURRENT_UNIX_TIME="$(date +%s)" > + if [ $CURRENT_UNIX_TIME -lt 1000000000 ]; then > + /usr/bin/ntpdate $ntpserver > /dev/null 2>&1 > + else > + break > + fi > + done > + [ $? = 0 ] && echo "OK" || echo "FAIL" > +} > + > +case $1 in > + start) > + start > + ;; > + *) > + echo "Usage: $0 {start}" >&2 > + exit 1 > + ;; > +esac > + > +exit 0 > diff --git a/package/ntp/S49ntp b/package/ntp/S49ntp > index 35e5874..0e90f29 100755 > --- a/package/ntp/S49ntp > +++ b/package/ntp/S49ntp > @@ -5,30 +5,30 @@ NAME=ntpd > # Read config file if it is present. > if [ -r /etc/default/$NAME ] > then > - . /etc/default/$NAME > + . /etc/default/$NAME > fi > > case "$1" in > - start) > - printf "Starting $NAME: " > - start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g > - [ $? = 0 ] && echo "OK" || echo "FAIL" > - ;; > - stop) > - printf "Stopping $NAME: " > - start-stop-daemon -K -q -n $NAME > - [ $? = 0 ] && echo "OK" || echo "FAIL" > - ;; > - restart|reload) > - echo "Restarting $NAME: " > - $0 stop > - sleep 1 > - $0 start > - ;; > - *) > - echo "Usage: $0 {start|stop|restart|reload}" >&2 > - exit 1 > - ;; > + start) > + printf "Starting $NAME: " I went back through the discussion so far and wanted to bring back up "ntpd -q ". I think it would simplify and future proof what you're wanting to accomplish. - ntpdate is deprecated and will eventually not be part of the ntp package so we shouldn't add a seperate startup script. Other examples have kept it self contained in ntpd's. - ntpd -q uses the ntpd configs and there isn't any custom script logic or layer of new configs. I'd suggest testing but the 1970's check may not need to occur. ntpd -q may handle that sort of a check/fall-through. Something like the following. CURRENT_DATE=$(date | grep "1970") if [ "$CURRENT_DATE" != "" ]; then # ntpd -q (equivalent to ntpdate) and expanded slew -x /usr/sbin/ntpd -q -x > /dev/null 2>&1 # I don't believe it outputs anything so the redirects could be dropped when tested [ $? != 0 ] && echo -n "(No initial time set)" fi > + start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g > + [ $? = 0 ] && echo "OK" || echo "FAIL" > + ;; > + stop) > + printf "Stopping $NAME: " > + start-stop-daemon -K -q -n $NAME > + [ $? = 0 ] && echo "OK" || echo "FAIL" > + ;; > + restart|reload) > + echo "Restarting $NAME: " > + $0 stop > + sleep 1 > + $0 start > + ;; > + *) > + echo "Usage: $0 {start|stop|restart|reload}" >&2 > + exit 1 > + ;; > esac > > exit 0 > diff --git a/package/ntp/ntp.mk b/package/ntp/ntp.mk > index af3c1aa..c2c910d 100644 > --- a/package/ntp/ntp.mk > +++ b/package/ntp/ntp.mk > @@ -93,9 +93,16 @@ define NTP_INSTALL_TARGET_CMDS > $(INSTALL) -m 644 package/ntp/ntpd.etc.conf $(TARGET_DIR)/etc/ntp.conf > endef > > +ifeq ($(BR2_PACKAGE_NTP_NTPDATE),y) > +define NTP_INSTALL_INIT_SYSV_NTPDATE > + $(INSTALL) -D -m 755 package/ntp/S48ntpdate $(TARGET_DIR)/etc/init.d/S48ntpdate > +endef > +endif > + > ifeq ($(BR2_PACKAGE_NTP_NTPD),y) > define NTP_INSTALL_INIT_SYSV > $(INSTALL) -D -m 755 package/ntp/S49ntp $(TARGET_DIR)/etc/init.d/S49ntp > + $(NTP_INSTALL_INIT_SYSV_NTPDATE) > endef > > define NTP_INSTALL_INIT_SYSTEMD > -- > 1.9.1 > -- Matthew L Weber / Pr Software Engineer Airborne Information Systems / RC Linux Secure Platforms MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA www.rockwellcollins.com Note: Any Export License Required Information and License Restricted Third Party Intellectual Property (TPIP) content must be encrypted and sent to matthew.weber@corp.rockwellcollins.com.
Hi Matthew, Thank you very much for your help. I was checking If the script is working fine: -----> #! /bin/sh NAME=ntpd # Read config file if it is present. if [ -r /etc/default/$NAME ] then . /etc/default/$NAME fi case "$1" in start) printf "Starting $NAME: " CURRENT_DATE=$(date | grep "1970") if [ "$CURRENT_DATE" != "" ]; then /usr/sbin/ntpd -q -x [ $? != 0 ] && echo -n "(No initial time set) - " fi start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g [ $? = 0 ] && echo "OK" || echo "FAIL" ;; stop) printf "Stopping $NAME: " start-stop-daemon -K -q -n $NAME [ $? = 0 ] && echo "OK" || echo "FAIL" ;; restart|reload) echo "Restarting $NAME: " $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0 -----> But it seems to be that the command "/usr/sbin/ntpd -q -x" is not working properly: # date --set "1970-01-10 10:10:00" Sat Jan 10 10:10:00 UTC 1970 # /etc/init.d/S49ntp restart Restarting ntpd: Stopping ntpd: OK Starting ntpd: 10 Jan 10:10:04 ntpd[1859]: ntpd 4.2.8p12@1.3728-o Thu Oct 18 16:16:56 UTC 2018 (1): Starting 10 Jan 10:10:04 ntpd[1859]: Command line: /usr/sbin/ntpd -q -x 10 Jan 10:10:04 ntpd[1859]: proto: precision = 1.718 usec (-19) 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 0 v6wildcard [::]:123 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 1 v4wildcard 0.0.0.0:123 10 Jan 10:10:04 ntpd[1859]: Listen normally on 2 lo 127.0.0.1:123 10 Jan 10:10:04 ntpd[1859]: Listen normally on 3 eth0 192.168.20.226:123 10 Jan 10:10:04 ntpd[1859]: Listen normally on 4 ppp0 172.21.39.120:123 10 Jan 10:10:04 ntpd[1859]: Listen normally on 5 lo [::1]:123 10 Jan 10:10:04 ntpd[1859]: Listen normally on 6 eth0 [xxxx::xxxx:xxxx:xxxx:xxxx%2]:123 10 Jan 10:10:04 ntpd[1859]: Listening on routing socket on fd #23 for interface updates (No initial time set) - OK Notice that I checking the script forcing the date to 1970 with this command. Does anyone any suggestion? Best regards.
Oscar, On Mon, Oct 22, 2018 at 2:25 AM Oscar Gomez Fuente <oscargomezf@gmail.com> wrote: > > Hi Matthew, > > > Thank you very much for your help. > > I was checking If the script is working fine: > -----> > #! /bin/sh > > NAME=ntpd > > # Read config file if it is present. > if [ -r /etc/default/$NAME ] > then > . /etc/default/$NAME > fi > > case "$1" in > start) > printf "Starting $NAME: " > CURRENT_DATE=$(date | grep "1970") > if [ "$CURRENT_DATE" != "" ]; then > /usr/sbin/ntpd -q -x > [ $? != 0 ] && echo -n "(No initial time set) - " > fi > start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g > [ $? = 0 ] && echo "OK" || echo "FAIL" > ;; > stop) > printf "Stopping $NAME: " > start-stop-daemon -K -q -n $NAME > [ $? = 0 ] && echo "OK" || echo "FAIL" > ;; > restart|reload) > echo "Restarting $NAME: " > $0 stop > sleep 1 > $0 start > ;; > *) > echo "Usage: $0 {start|stop|restart|reload}" >&2 > exit 1 > ;; > esac > > exit 0 > -----> > > But it seems to be that the command "/usr/sbin/ntpd -q -x" is not > working properly: > > # date --set "1970-01-10 10:10:00" > Sat Jan 10 10:10:00 UTC 1970 > # /etc/init.d/S49ntp restart > Restarting ntpd: > Stopping ntpd: OK > Starting ntpd: 10 Jan 10:10:04 ntpd[1859]: ntpd 4.2.8p12@1.3728-o Thu > Oct 18 16:16:56 UTC 2018 (1): Starting > 10 Jan 10:10:04 ntpd[1859]: Command line: /usr/sbin/ntpd -q -x > 10 Jan 10:10:04 ntpd[1859]: proto: precision = 1.718 usec (-19) > 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 0 v6wildcard [::]:123 > 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 1 v4wildcard 0.0.0.0:123 > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 2 lo 127.0.0.1:123 > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 3 eth0 192.168.20.226:123 > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 4 ppp0 172.21.39.120:123 > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 5 lo [::1]:123 > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 6 eth0 > [xxxx::xxxx:xxxx:xxxx:xxxx%2]:123 > 10 Jan 10:10:04 ntpd[1859]: Listening on routing socket on fd #23 for > interface updates > (No initial time set) - OK > > Notice that I checking the script forcing the date to 1970 with this > command. Does anyone any suggestion? > I'll give it a try today and let you know. Matt
Oscar, On Mon, Oct 22, 2018 at 3:49 AM Matthew Weber <matthew.weber@rockwellcollins.com> wrote: > > Oscar, > > On Mon, Oct 22, 2018 at 2:25 AM Oscar Gomez Fuente > <oscargomezf@gmail.com> wrote: > > > > Hi Matthew, > > > > > > Thank you very much for your help. > > > > I was checking If the script is working fine: > > -----> > > #! /bin/sh > > > > NAME=ntpd > > > > # Read config file if it is present. > > if [ -r /etc/default/$NAME ] > > then > > . /etc/default/$NAME > > fi > > > > case "$1" in > > start) > > printf "Starting $NAME: " > > CURRENT_DATE=$(date | grep "1970") > > if [ "$CURRENT_DATE" != "" ]; then > > /usr/sbin/ntpd -q -x > > [ $? != 0 ] && echo -n "(No initial time set) - " > > fi > > start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g > > [ $? = 0 ] && echo "OK" || echo "FAIL" > > ;; > > stop) > > printf "Stopping $NAME: " > > start-stop-daemon -K -q -n $NAME > > [ $? = 0 ] && echo "OK" || echo "FAIL" > > ;; > > restart|reload) > > echo "Restarting $NAME: " > > $0 stop > > sleep 1 > > $0 start > > ;; > > *) > > echo "Usage: $0 {start|stop|restart|reload}" >&2 > > exit 1 > > ;; > > esac > > > > exit 0 > > -----> > > > > But it seems to be that the command "/usr/sbin/ntpd -q -x" is not > > working properly: > > > > # date --set "1970-01-10 10:10:00" > > Sat Jan 10 10:10:00 UTC 1970 > > # /etc/init.d/S49ntp restart > > Restarting ntpd: > > Stopping ntpd: OK > > Starting ntpd: 10 Jan 10:10:04 ntpd[1859]: ntpd 4.2.8p12@1.3728-o Thu > > Oct 18 16:16:56 UTC 2018 (1): Starting > > 10 Jan 10:10:04 ntpd[1859]: Command line: /usr/sbin/ntpd -q -x > > 10 Jan 10:10:04 ntpd[1859]: proto: precision = 1.718 usec (-19) > > 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 0 v6wildcard [::]:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen and drop on 1 v4wildcard 0.0.0.0:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 2 lo 127.0.0.1:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 3 eth0 192.168.20.226:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 4 ppp0 172.21.39.120:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 5 lo [::1]:123 > > 10 Jan 10:10:04 ntpd[1859]: Listen normally on 6 eth0 > > [xxxx::xxxx:xxxx:xxxx:xxxx%2]:123 > > 10 Jan 10:10:04 ntpd[1859]: Listening on routing socket on fd #23 for > > interface updates > > (No initial time set) - OK > > > > Notice that I checking the script forcing the date to 1970 with this > > command. Does anyone any suggestion? > > If it's Ok with you, I'll send a v2 patch tonight and include your signed-off. I fixed the args (should have been -g -q) and added a timeout loop to manage the fact that unlike ntpdate, ntpd won't return if there is no network connection or the server can't be reached. Matt
Hi Matthew, > If it's Ok with you, I'll send a v2 patch tonight and include your signed-off. > > I fixed the args (should have been -g -q) and added a timeout loop to > manage the fact that unlike ntpdate, ntpd won't return if there is no > network connection or the server can't be reached. Ok, thank you for your help. Best regards. Oscar Gomez Fuente TST Sistemas www.tst-sistemas.es
Oscar, On Tue, Oct 23, 2018 at 2:59 AM Oscar Gomez Fuente <oscargomezf@gmail.com> wrote: > > Hi Matthew, > > > If it's Ok with you, I'll send a v2 patch tonight and include your signed-off. > > > > I fixed the args (should have been -g -q) and added a timeout loop to > > manage the fact that unlike ntpdate, ntpd won't return if there is no > > network connection or the server can't be reached. > This series is superseded by http://patchwork.ozlabs.org/patch/988212/ Matt
diff --git a/package/ntp/S48ntpdate b/package/ntp/S48ntpdate new file mode 100755 index 0000000..a8d4d70 --- /dev/null +++ b/package/ntp/S48ntpdate @@ -0,0 +1,30 @@ +#! /bin/sh + +NAME=ntpdate +NTP_SERVERS="0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org" + +start() { + printf "Starting $NAME: " + for ntpserver in $NTP_SERVERS + do + CURRENT_UNIX_TIME="$(date +%s)" + if [ $CURRENT_UNIX_TIME -lt 1000000000 ]; then + /usr/bin/ntpdate $ntpserver > /dev/null 2>&1 + else + break + fi + done + [ $? = 0 ] && echo "OK" || echo "FAIL" +} + +case $1 in + start) + start + ;; + *) + echo "Usage: $0 {start}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/package/ntp/S49ntp b/package/ntp/S49ntp index 35e5874..0e90f29 100755 --- a/package/ntp/S49ntp +++ b/package/ntp/S49ntp @@ -5,30 +5,30 @@ NAME=ntpd # Read config file if it is present. if [ -r /etc/default/$NAME ] then - . /etc/default/$NAME + . /etc/default/$NAME fi case "$1" in - start) - printf "Starting $NAME: " - start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - stop) - printf "Stopping $NAME: " - start-stop-daemon -K -q -n $NAME - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - restart|reload) - echo "Restarting $NAME: " - $0 stop - sleep 1 - $0 start - ;; - *) - echo "Usage: $0 {start|stop|restart|reload}" >&2 - exit 1 - ;; + start) + printf "Starting $NAME: " + start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g + [ $? = 0 ] && echo "OK" || echo "FAIL" + ;; + stop) + printf "Stopping $NAME: " + start-stop-daemon -K -q -n $NAME + [ $? = 0 ] && echo "OK" || echo "FAIL" + ;; + restart|reload) + echo "Restarting $NAME: " + $0 stop + sleep 1 + $0 start + ;; + *) + echo "Usage: $0 {start|stop|restart|reload}" >&2 + exit 1 + ;; esac exit 0 diff --git a/package/ntp/ntp.mk b/package/ntp/ntp.mk index af3c1aa..c2c910d 100644 --- a/package/ntp/ntp.mk +++ b/package/ntp/ntp.mk @@ -93,9 +93,16 @@ define NTP_INSTALL_TARGET_CMDS $(INSTALL) -m 644 package/ntp/ntpd.etc.conf $(TARGET_DIR)/etc/ntp.conf endef +ifeq ($(BR2_PACKAGE_NTP_NTPDATE),y) +define NTP_INSTALL_INIT_SYSV_NTPDATE + $(INSTALL) -D -m 755 package/ntp/S48ntpdate $(TARGET_DIR)/etc/init.d/S48ntpdate +endef +endif + ifeq ($(BR2_PACKAGE_NTP_NTPD),y) define NTP_INSTALL_INIT_SYSV $(INSTALL) -D -m 755 package/ntp/S49ntp $(TARGET_DIR)/etc/init.d/S49ntp + $(NTP_INSTALL_INIT_SYSV_NTPDATE) endef define NTP_INSTALL_INIT_SYSTEMD
Signed-off-by: Oscar Gomez Fuente <oscargomezf@gmail.com> --- package/ntp/S48ntpdate | 30 ++++++++++++++++++++++++++++++ package/ntp/S49ntp | 42 +++++++++++++++++++++--------------------- package/ntp/ntp.mk | 7 +++++++ 3 files changed, 58 insertions(+), 21 deletions(-) create mode 100755 package/ntp/S48ntpdate