Skip to main content
Topic: ntpd run fails to start (Read 1140 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

ntpd run fails to start

I find that the network availability test in ntpd-runit run script has started to fail (for me at least in armtix).

The test
Code: [Select]
[ "$(ip route | awk '/^default/{print ($3!="")+($5!="")}')" = "2" ]
is failing because the awk command is now producing two lines
Code: [Select]
# ip route | awk '/^default/{print ($3!="")+($5!="")}'
2
2
which is because the output of the route command may contain two default lines eg
Code: [Select]
# ip route
default via 192.168.0.1 dev eth0 proto dhcp metric 100
default via 192.168.0.1 dev eth0 proto dhcp src 192.168.0.41 metric 1002
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.41 metric 100
192.168.0.0/24 dev eth0 proto dhcp scope link src 192.168.0.41 metric 1002

I don't know if this is specific to my network. The simple awk test could be  resurrected by using an awk line like this
Code: [Select]
[ "`ip route|awk '/^default/{if(($3!="")+($5!="")==2){print 1;exit 0}}'`" = "1" ]

I continue to use a script, have-net, which now looks like this
Code: [Select]
# cat  /bin/have-net
#/bin/sh
for d in /sys/class/net/*;do
[ `basename $d` = lo ] && continue
[ "`cat $d/operstate`" = "up" ] && echo "connected" && exit 0
done
[ -x /usr/bin/ip -a -x /usr/bin/awk ] \
&& [ "`ip route|awk '/^default/{if(($3!="")+($5!="")==2){print 1;exit 0}}'`" = "1" ] \
&& echo "connected" \
&& exit 0
fi
echo "disconnected"
exit 1
and my ntpd run is changed to
Code: [Select]
# cat ntpd/run
#!/bin/sh
/usr/bin/have-net >/dev/null 2>&1 || exit 1
ntpd -g -q #run once and exit
exec ntpd -g -u ntp:ntp -n >/dev/null 2>&1

Re: ntpd run fails to start

Reply #1
You have 2 routes marked as default, this is not OK. Make sure you don't have several dhcp clients on one interface
ARMtix

Re: ntpd run fails to start

Reply #2
You have 2 routes marked as default, this is not OK. Make sure you don't have several dhcp clients on one interface
unfortunately it's easy to have both wifi and ethernet competing; especially with NetworkManager. Seemingly it does not interfere with connectivity. So it will likely be a common problem. Relying on setup perfection is just wrong.

Re: ntpd run fails to start

Reply #3
Only one default route is actually used, the other one is ignored (tested myself today)
As of your case, i think you should only exit if "ntpd -g -q" failed. If it works same as ntpdate, it should fail if it can't reach server thus restarting script
ARMtix

 

Re: ntpd run fails to start

Reply #4
Actually I think you are right; there's probably no point in checking the network if the ntpd check is sufficient;  additionally the failure is at least in the right direction  in that the slower long running command will execute.

I have been experimenting with setting up a timestamp that can reduce the amount of slew, but I think the ntpd -g -q will do the job without it.