ntpd setup

Having issues with your DietPi installation, or, found a bug? Post it here.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

ntpd setup

Post by Gord_W »

Hi,

I would like to get the clock on the rpi set so that it doesn't drift. I'm using the rpi for a timing application over a wide temperature range and just having the clock updated once per day with a cron job is not going to cut it as the drift is significant.

So I would like to have ntp running all the time.

If I run nptd from the command line, it starts and runs.

I've edited the ntp.config file to allow for logs to be created
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

My rpi is headless and I'm using ssh.

So my problems and questions and remember that I am a beginner here:

1) What is the best way to start ntp at boot and set the clock?
2) Can I just remove the ntp lines in the daily cron job and not break anything else?
3) When i run ntp from the command line the drift file does not get updated. ntp is running under root and the drift file is owned by ntp. I don't know if that is the problem or not with my ignorance.
4) Is there a place that errors (like file permissions) would show up? I have logging turned on, but there is little that I see in the /var/log area.
5) loopstats and peerstats start to show in the /var/log/ntpstats dir, but they get deleted every few minutes by something so that I only have 0 to 5 last entries. I was expecting a full day per file of data that I could look at.
6) There is no clockstats file - should there be in ntp client mode?

Any other pointers that I may be missing?

Thanks,
Gordon Williams
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: ntpd setup

Post by Fourdee »

Hi Gordon,

DietPi runs ntpd during boot and once daily. We use the ntpd -gq flag to quit ntpd when its obtained the time, saving resources.

I'll need to update DietPi code to allow for a constant running ntpd. I will create a option in dietpi.txt that will allow for both options.

ntpd runs as root, so there is no chance of file permission issues.

DietPi-Ramlog will clear log files every hour. If you need to keep your logfiles, you can change the logging mode to Ramlog #2 or Full:http://dietpi.com/phpbb/viewtopic.php?f ... art=20#p68

Git Ticket: https://github.com/Fourdee/DietPi/issues/124
It will be available in v102.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: ntpd setup

Post by Fourdee »

Gordon,

Would an hourly NTPD update be sufficient?
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: ntpd setup

Post by Fourdee »

I've added:
- DietPi-Config > Advanced > Time sync (ntpd)

Available in V102
tsync.jpg
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: ntpd setup

Post by Gord_W »

Hi,

I was not asking for you to change the setup as my needs are not like most users. It was more how to make changes myself to make it run as I need it to. Some advice please :)

I want ntpd to run continuously to keep the clock disciplined and synchronized to real time from the servers. The current uncorrected clock has about a 40 ppm error slow (at room temp) and if ntpd runs it will increase the clock frequency to remove this error. This error gets stored in the drift file when everything is working properly (but it is not currently being stored, maybe due to permissions as root doesn't own that file, user ntp does).

As I will be eventually running this not connected to the internet and ntp servers, I'm expecting a clock error in excess of 150 ppm at -20 deg. For clock discipline then I will be using a temperature corrected rtc with a pulse per second output with a max. error of 3 ppm. That is a struggle for another day! Right now I just want ntp working normally.

So I'm looking for:
1) ntpd started at boot with the time of day set and then left running to continuously nudge the rpi clock to correct for errors.
2) No hourly or daily ntp correction through cron.
3) Drift file update working. It is currently at -6.366 ppm with ntp owner on your V101 wheezy version
4) I'll have another look at the log files to try and figure out why they are being deleted - it doesn't seem like it hourly.

Thanks,
Gordon
******************
Hi, I see that you have already implemented something while I was writing the reply! It looks like 1) and 2) is covered. Could you have a look at the drift file? /var/lib/ntp/ntp.drift Does this get updated regularly? or is it sitting with the Apr 1 2015 last modified date?
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: ntpd setup

Post by Fourdee »

Gord_W wrote:So I'm looking for:
1) ntpd started at boot with the time of day set and then left running to continuously nudge the rpi clock to correct for errors.
2) No hourly or daily ntp correction through cron.
3) Drift file update working. It is currently at -6.366 ppm with ntp owner on your V101 wheezy version
4) I'll have another look at the log files to try and figure out why they are being deleted - it doesn't seem like it hourly.
Hi Gordon,

So you are looking for a way to obtain the slew (drift) without applying the current time to the system clock?
Drift file update working. It is currently at -6.366 ppm with ntp owner on your V101 wheezy version
Seems you are right, appears this file is not being updated.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: ntpd setup

Post by Gord_W »

Hi,
So you are looking for a way to obtain the slew (drift) without applying the current time to the system clock?
On boot I want the system time to jump to the real time and then start making corrections based on the errors found from the ntp servers.

Once ntpd is working it will automatically correct for the drift and clock offset to slowly move the rpi clock to real time from the servers. The drift file is used on boot to set the initial expected drift and then it adjusts from there. If the file is not present the drift is assumed to be zero and therefore takes longer to synchronize the rpi clock to real time.

Gordon
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: ntpd setup

Post by Gord_W »

Drift file update working. It is currently at -6.366 ppm with ntp owner on your V101 wheezy version


Seems you are right, appears this file is not being updated.
I changed the ownership of the drift file to root from ntp. After a couple of hours of running and the frequency offset determined and stabilized it wrote to the file. So every thing seems to be working properly.

I will wait until I see V102 to get ntp started automatically at boot.

Thanks,

Gordon Williams
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: ntpd setup

Post by Fourdee »

Gord_W wrote:
Drift file update working. It is currently at -6.366 ppm with ntp owner on your V101 wheezy version


Seems you are right, appears this file is not being updated.
I changed the ownership of the drift file to root from ntp. After a couple of hours of running and the frequency offset determined and stabilized it wrote to the file. So every thing seems to be working properly.

I will wait until I see V102 to get ntp started automatically at boot.

Thanks,

Gordon Williams
Great to hear.

I tried no end of options to try and get the drift file working. Maybe I didn't wait long enough during testing.

Are you running ntpd with command line options (eg: -f /etc/ntp.drift), or just ntpd?
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Gord_W
Posts: 134
Joined: Sat Oct 24, 2015 6:30 pm

Re: ntpd setup

Post by Gord_W »

Are you running ntpd with command line options (eg: -f /etc/ntp.drift), or just ntpd?
Just running ntpd from the command line with no arguments. It does take a while to stabilize before it writes the file. If you want to see the log files and track convergence you need to uncomment the section in ntp.conf.

Gordon Williams
Post Reply