NTP Configuration not being used
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"
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