Score:0

NTP Configuration not being used

us flag

I am trying to set up a GPS NTP server on my SBC running Ubuntu 20.04 (headless) but I am having a configuration issue. When I reboot I get this:

$ ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*_gateway        163.237.218.18   2 u   22   64    1    2.727    0.011   0.159

/etc/ntp.conf says:

pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

# GPS Serial data reference
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.0 refid GPS

# GPS PPS reference
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid PPS

/etc/ntp/step-tickers
is blank

I found on the internet a configuration for making a "device" that will run as a GPS timeserver and it said to do this:

$ su -
# killall -9 gpsd ntpd
# gpsd -n /dev/ttyXX
# sleep 2
# ntpd -gN
# sleep 2
# cgps 

and that works

root@ubuntu:/home/zach# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
*SHM(0)          .GPS.            0 l    8   16    1    0.000  -40.232   0.000
 SHM(1)          .PPS.            0 l    -   16    0    0.000    0.000   0.000

any idea why i cannot get ntp to read /etc/ntp.conf at boot?

EDIT: I am unsure if gpsd is running at startup.

I did a dmesg | grep gps and nothing came up.

I then wrote a bash script with that killall line in it. I don't think it will run (@startup sh in crontab) though because it has to be elevated. I tried as init.d (i don't really know what I am doing there) and I get an error message audit: type=1400 audit(1636322022.316:45): apparmor="DENIED" operation="ptrace" profile="/usr/sbin/gpsd" pid=2794 comm="gpsd" requested_mask="read" denied_mask="read" peer="/usr/sbin/ntpd"

user10489 avatar
in flag
Have you enabled gpsd at boot? You probably need to modify the ntp systemctl start to wait for gpsd to get a lock.
Christian Ehrhardt avatar
sl flag
Since 18.04 and later you should use chrony instead of ntpd, would you be willing to try if chrony+gpsd works better for you? A guide how to configure it for your setup is at https://ubuntu.com/server/docs/network-ntp
Zach avatar
us flag
@ChristianEhrhardt that looks great. I think it is working
Christian Ehrhardt avatar
sl flag
Great to hear that @Zach, so maybe self-answer here the way you got it working that we can up-vote this better chrony answer?
Zach avatar
us flag
@christian done
Christian Ehrhardt avatar
sl flag
Thank you @Zach
Score:1
us flag

Ok, thanks to @ChristianEhrhardt, the use of Chrony seems to have worked quite well for some reason unbeknownst to me.

I already have gpsd running so I didn't have to mess with that, but it is important to indicate here. I am using the GPS plugged in via USB and not PPS. The device is ttyACM0

I used several guides on the internet and i am not sure the exact steps I took but it went something like this:

sudo apt install chrony

and then I had to configure the .conf file

sudo nano /etc/chrony/chrony.conf

I figured out that in order to make the GPS timeserver actually serve time to other computers I had to uncomment as below. I have serveral subnets so I opened it wide up

#Allow to be a NTP server 
allow 192.168.0.0/24

I needed to add my GPS source so I added:

#GPS Sources
refclock SHM 0 refid GPS precision 1e-1 offset 0 delay 0 stratum 2
refclock SOCK /var/run/chrony.ttyACM0.sock refid PPS

I know that restarting services is a thing, but I prefer the reboot.

sudo reboot now

Then I enabled it as a service

systemctl enable chrony

Then I checked to make sure it worked

chronyc sources

And lastly I verified that it was serving time to other computers. I went to a different machine and checked ntpq -p

and TA-DA

Score:0
pk flag

It is also possible, if your Server gets it's IP via DHCP, that the ntp-options will be set via /var/lib/ntp/ntp.conf.dhcp. I sometimes even had a lingering file from the installation that kept that behaviour going even after changing to a static configuration. If so, just remove it.

Maybe a service like this could work / not tested

[Unit]
Description=NTP-GPSD-FIX
Requires=ntpd.service
Requires=gpsd.service?

[Service]
ExecStart=/path/to/a/script/with/the/commands

[Install]
WantedBy=multi-user.target
Zach avatar
us flag
Unfortuanately not.That folder var/lib/ntp is empty save one file ntp.drift
crpb avatar
pk flag
Which servic/daemon is starting your ntpd? And best the configuration of it. And is the device ready in that moment?
Zach avatar
us flag
/etc/init.d/ntp DAEMON=/usr/sbin/ntpd
crpb avatar
pk flag
You could check the runlevel of the gpsd and ntp. /etc/rc*/ `update-rc.d`
user10489 avatar
in flag
You may also need to modify the gpsd script to not "finish" starting until the gps has a lock, otherwise ntpd may ignore gpsd even if it is running. If your gps does a fast warm start, this may be good enough except for the two minutes after the gps loses power.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.