Skip to contentSkip to conversation

ntp: added S48ntpdate script

PATCH New Oscar Gomez Fuente 2 participants 7 messages Oct 19, 2018 – Oct 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntp: added S48ntpdate script

---
 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
package/ntp/S48ntpdate new file +30 -0
new file mode 100755
index 0000000..a8d4d70
@@ -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
package/ntp/S49ntp +21 -21

51 lines not on this page · raw message

package/ntp/ntp.mk +7 -0
index af3c1aa..c2c910d 100644
@@ -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
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 ntp: added S48ntpdate script

Oscar,

Quoted 70 lines · Oscar Gomez Fuente
---
 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
package/ntp/S48ntpdate new file +30 -0
new file mode 100755
index 0000000..a8d4d70
@@ -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
package/ntp/S49ntp +1 -13
index 35e5874..0e90f29 100755
@@ -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: "

package/ntp/S49ntp NAME=ntpd · line 13

Quoted 10 lines
package/ntp/S49ntp +2 -8
-    $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
Quoted 43 lines
package/ntp/S49ntp +18 -0
+               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
package/ntp/ntp.mk +7 -1
index af3c1aa..c2c910d 100644
@@ -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
--
Quoted 2 lines

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 at corp.rockwellcollins.com.

#2 lore raw

PATCH 1/1 ntp: added S48ntpdate script

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 at 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.

#3 lore raw

PATCH 1/1 ntp: added S48ntpdate script

Oscar,

Quoted 73 lines · Oscar Gomez Fuente

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 at 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
Quoted 3 lines

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

#4 lore raw

PATCH 1/1 ntp: added S48ntpdate script

Oscar,

Quoted 81 lines · Matthew Weber

Oscar,

Quoted 76 lines · Oscar Gomez Fuente

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 at 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

#5 lore raw

PATCH 1/1 ntp: added S48ntpdate script

Hi Matthew,

Quoted 5 lines

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

#6 lore raw

PATCH 1/1 ntp: added S48ntpdate script

Oscar,

Quoted 9 lines · Oscar Gomez Fuente

Hi Matthew,

Quoted 5 lines

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