* [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script
@ 2018-10-16 16:44 Oscar Gomez Fuente
2018-10-16 17:01 ` Matthew Weber
0 siblings, 1 reply; 5+ messages in thread
From: Oscar Gomez Fuente @ 2018-10-16 16:44 UTC (permalink / raw)
To: buildroot
Signed-off-by: Oscar Gomez Fuente <oscargomezf@gmail.com>
---
package/ntp/S49ntp | 58 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/package/ntp/S49ntp b/package/ntp/S49ntp
index 35e5874..f5c4cb8 100755
--- a/package/ntp/S49ntp
+++ b/package/ntp/S49ntp
@@ -1,34 +1,44 @@
#! /bin/sh
NAME=ntpd
+NTPDATE=/usr/bin/ntpdate
# Read config file if it is present.
-if [ -r /etc/default/$NAME ]
-then
- . /etc/default/$NAME
+if [ -r /etc/default/$NAME ]; then
+. /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
- ;;
+case $1 in
+start)
+ printf "Starting $NAME: "
+ if [ -f $NTPDATE ]; then
+ NUM_SERVER=0
+ CURRENT_DATE=$(date | grep "1970")
+ while [ "$NUM_SERVER" != "4" -a "$CURRENT_DATE" != "" ]
+ do
+ $NTPDATE $NUM_SERVER.pool.ntp.org > /dev/null 2>&1
+ CURRENT_DATE=$(date | grep "1970")
+ NUM_SERVER=$(( $NUM_SERVER + 1 ))
+ done
+ 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
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script
2018-10-16 16:44 [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script Oscar Gomez Fuente
@ 2018-10-16 17:01 ` Matthew Weber
2018-10-17 15:14 ` Oscar Gomez Fuente
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Weber @ 2018-10-16 17:01 UTC (permalink / raw)
To: buildroot
Oscar,
On Tue, Oct 16, 2018 at 11:45 AM Oscar Gomez Fuente
<oscargomezf@gmail.com> wrote:
>
> Signed-off-by: Oscar Gomez Fuente <oscargomezf@gmail.com>
> ---
> package/ntp/S49ntp | 58 ++++++++++++++++++++++++++++++++----------------------
> 1 file changed, 34 insertions(+), 24 deletions(-)
>
> diff --git a/package/ntp/S49ntp b/package/ntp/S49ntp
> index 35e5874..f5c4cb8 100755
> --- a/package/ntp/S49ntp
> +++ b/package/ntp/S49ntp
> @@ -1,34 +1,44 @@
> #! /bin/sh
>
> NAME=ntpd
> +NTPDATE=/usr/bin/ntpdate
>
> # Read config file if it is present.
> -if [ -r /etc/default/$NAME ]
> -then
> - . /etc/default/$NAME
> +if [ -r /etc/default/$NAME ]; then
> +. /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
> - ;;
> +case $1 in
> +start)
> + printf "Starting $NAME: "
> + if [ -f $NTPDATE ]; then
> + NUM_SERVER=0
I'd suggest checking if there was a preferred time server you should
use in /etc/default/$NAME before assuming using the pool. I don't
believe there is a defined syntax for that config's variables as it is
different from the actual ntp.conf. You can probably just assume a
variable name like NTP_SERVER.
> + CURRENT_DATE=$(date | grep "1970")
> + while [ "$NUM_SERVER" != "4" -a "$CURRENT_DATE" != "" ]
> + do
> + $NTPDATE $NUM_SERVER.pool.ntp.org > /dev/null 2>&1
> + CURRENT_DATE=$(date | grep "1970")
> + NUM_SERVER=$(( $NUM_SERVER + 1 ))
> + done
> + 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
> --
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script
2018-10-16 17:01 ` Matthew Weber
@ 2018-10-17 15:14 ` Oscar Gomez Fuente
2018-10-17 19:49 ` Oscar Gomez Fuente
0 siblings, 1 reply; 5+ messages in thread
From: Oscar Gomez Fuente @ 2018-10-17 15:14 UTC (permalink / raw)
To: buildroot
Hi Matthew,
> I'd suggest checking if there was a preferred time server you should
> use in /etc/default/$NAME before assuming using the pool. I don't
> believe there is a defined syntax for that config's variables as it is
> different from the actual ntp.conf. You can probably just assume a
> variable name like NTP_SERVER.
Yes, it is a great idea. What do you think about that?
----->
#! /bin/sh
NAME=ntpd
NTPDATE=/usr/bin/ntpdate
MAX_NUM_SERVERS=3
NTP_NAME_SERVER=pool.ntp.org
# Read config file if it is present.
if [ -r /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
case $1 in
start)
printf "Starting $NAME: "
if [ -f $NTPDATE ]; then
CURRENT_DATE=$(date | grep "1970")
if [ -r /etc/default/$NAME ]; then
$NTPDATE $NTP_SERVER > /dev/null 2>&1
CURRENT_DATE=$(date | grep "1970")
fi
NUM_SERVER=0
while [ $NUM_SERVER -le $MAX_NUM_SERVERS -a
"$CURRENT_DATE" != "" ]
do
$NTPDATE $NUM_SERVER.$NTP_NAME_SERVER > /dev/null 2>&1
NUM_SERVER=$(( $NUM_SERVER + 1 ))
CURRENT_DATE=$(date | grep "1970")
done
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
----->
Best regards.
Oscar Gomez Fuente
TST Sistemas
www.tst-sistemas.es
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script
2018-10-17 15:14 ` Oscar Gomez Fuente
@ 2018-10-17 19:49 ` Oscar Gomez Fuente
2018-10-17 20:09 ` Matthew Weber
0 siblings, 1 reply; 5+ messages in thread
From: Oscar Gomez Fuente @ 2018-10-17 19:49 UTC (permalink / raw)
To: buildroot
Hi everyone,
I made some improvements. If everyone thinks it is ok I will send a patch:
----->
#! /bin/sh
NAME=ntpd
NTPDATE=/usr/bin/ntpdate
MAX_NUM_SERVERS=3
NTP_NAME_SERVER=pool.ntp.org
# 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 [ -f $NTPDATE -a "$CURRENT_DATE" != "" ]; then
if [ "$NTP_SERVER" != "" ]; then
$NTPDATE $NTP_SERVER > /dev/null 2>&1
CURRENT_DATE=$(date | grep "1970")
fi
NUM_SERVER=0
while [ $NUM_SERVER -le $MAX_NUM_SERVERS -a "$CURRENT_DATE" != "" ]
do
$NTPDATE $NUM_SERVER.$NTP_NAME_SERVER > /dev/null 2>&1
NUM_SERVER=$(( $NUM_SERVER + 1 ))
CURRENT_DATE=$(date | grep "1970")
done
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
----->
Best regards.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script
2018-10-17 19:49 ` Oscar Gomez Fuente
@ 2018-10-17 20:09 ` Matthew Weber
0 siblings, 0 replies; 5+ messages in thread
From: Matthew Weber @ 2018-10-17 20:09 UTC (permalink / raw)
To: buildroot
Oscar,
On Wed, Oct 17, 2018 at 2:49 PM Oscar Gomez Fuente
<oscargomezf@gmail.com> wrote:
>
> Hi everyone,
>
> I made some improvements. If everyone thinks it is ok I will send a patch:
> ----->
> #! /bin/sh
>
> NAME=ntpd
> NTPDATE=/usr/bin/ntpdate
Do you need to try more then one server?
I'd suggest the following instead which handles the default NTP_SERVER
without a conditional and removes the loop.
NTP_SERVER=0.pool.ntp.org
>
> # 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 [ -f $NTPDATE -a "$CURRENT_DATE" != "" ]; then
$NTPDATE $NTP_SERVER > /dev/null 2>&1
[ $? = 1 ] && 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
>
> ----->
>
> Best regards.
--
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-10-17 20:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-16 16:44 [Buildroot] [PATCH 1/1] ntp: added ntpdate support to the S49ntp script Oscar Gomez Fuente
2018-10-16 17:01 ` Matthew Weber
2018-10-17 15:14 ` Oscar Gomez Fuente
2018-10-17 19:49 ` Oscar Gomez Fuente
2018-10-17 20:09 ` Matthew Weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox