2

I have a Debian Jessie Linux system with an internal RTC clock which the user can adjust or change. It may or may not be connected to external IP and therefore may or may not have access to NTP. I would like to provide an option in the clock setting UI to "set from NTP" if it is available, but I don't want the system clock to be constantly updated from NTP.

  • How can I configure ntpd to be active, but not update the system clock?
  • How can I read and display the 'ntp time' (which will be shown along with the system clock)? (C or Python is fine)
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • I'm not sure I understand. You want to have 3 different times: the hardware rtc clock, the kernel clock, and the real world clock provided by some ntp server? – meuh Oct 03 '16 at 18:19
  • 1
    What's the purpose of running a system with time different from real one? – Serge Oct 03 '16 at 18:33
  • two times: system/rtc and NTP. but the update of the system/rtc from NTP needs to be under manual control, i.e. not automatic. – Dave Lawrence Oct 03 '16 at 22:00
  • The question says that the RTC can be adjusted. If this means that it can be tuned (made to run faster or slower), then the user can use this configuration to calibrate the RTC. – G-Man Says 'Reinstate Monica' Oct 04 '16 at 00:42

1 Answers1

5

The easiest solution to avoid having NTP update your system clock is not to run it.

Instead, use something like ntpdate on demand, to ask the potential remote NTP servers how wrong your local clock is.

ntpdate -qu 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org

server 212.47.239.163, stratum 2, offset 0.000638, delay 0.03052
server 92.243.6.5, stratum 3, offset -0.001490, delay 0.03011
...
 4 Oct 00:00:55 ntpdate[10962]: adjust time server 91.121.167.54 offset -0.000156 sec

In this mode ntpdate doesn't even need to be run as root, so you can be sure there is no chance of "accidentally" updating your local clock.

By the way, are you aware that ntpd can handle being disconnected from its upstream time servers, and that having the daemon running over a long period of time can help minimise the drift inherent in most system clocks?

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Hi, Thanks for the suggestion. The command seems to take a while to run, but if I run it every minute or so in a thread and store a local offset from the system clock which can then be used to display "NTP time". – Dave Lawrence Oct 04 '16 at 08:29
  • @DaveLawrence if you run it every minute you'll likely upset the owners of the upstream clocks. The NTP Pool is run on an altruistic basis, with a broad expectation of "a few" requests per hour per client. It's also not intended to give anything better than ±1 second accuracy, but most clocks manage ±50ms or better. – Chris Davies Oct 04 '16 at 11:26
  • @DaveLawrence if you're really looking for something to keep track of the accuracy of your own local clock(s), run your own local NTP server and monitor against that. – Chris Davies Oct 04 '16 at 11:29
  • Understood, now problem to run once an hour. – Dave Lawrence Oct 04 '16 at 11:36
  • @DaveLawrence crontab will do that – Chris Davies Oct 04 '16 at 12:30
  • sorry, typo, meant "NO problem", not "NOW problem"! – Dave Lawrence Oct 04 '16 at 12:32