Enhancement #1964

Ntp: force ntpd syncronization

Added by Giacomo Sanchietti about 8 years ago. Updated about 8 years ago.

Status:CLOSEDStart date:05/30/2013
Priority:NormalDue date:05/30/2013
Assignee:-% Done:

100%

Category:nethserver-ntp
Target version:v6.4-beta2
Resolution: NEEDINFO:No

Description

If the difference between local and remote server is too high, ntpd can't syncronize the clocks.

We should force the ntp syncronization before start.

Patch:

--- nethserver-ntp-clock-adjust.ori    2013-05-20 15:27:17.480658645 +0200
+++ nethserver-ntp-clock-adjust    2013-05-20 15:29:42.482824328 +0200
@@ -34,6 +34,10 @@
 my $status = $db->get_prop('ntpd', 'status') || '';

 if($status eq 'enabled') { 
+    if ( system("/sbin/service ntpd status 2&>/dev/null") ne 0 ) {
+        # force syncronization
+        qx(/usr/sbin/ntpd -q)
+    }
     qx(/sbin/service ntpd restart);
 } else {
     # manual date setting


Related issues

Related to NethServer 6 - Task #934: Remove ntpdate calls in scripts CLOSED 03/28/2012
Related to NethServer 6 - Bug #1988: NTP server validation failed CLOSED 05/30/2013 05/30/2013

Associated revisions

Revision 13284cd3
Added by Davide Principi about 8 years ago

/etc/ntp.conf template (10servers): append "iburst" option to "server" configuration command. Refs #1964

Revision 35a8ac16
Added by Davide Principi about 8 years ago

nethserver-ntp-clock-adjust action: restart ntpd in the usual way. Refs #1964

History

#1 Updated by Davide Principi about 8 years ago

  • Due date set to 05/30/2013
  • Status changed from NEW to ON_DEV
  • Assignee set to Davide Principi
  • Start date set to 05/30/2013
  • % Done changed from 0 to 30
  • Estimated time set to 2.00

#2 Updated by Davide Principi about 8 years ago

From ntpd man page

The initial delay to set the clock can be reduced using
the iburst keyword with the server configuration command

[...]

most applications will probably want to specify the iburst keyword with the server configuration command. With this keyword a volley of messages are exchanged to groom the data and the clock is set in about 10 s

I tested it with pool.ntp.org. The system clock was set about 10 minutes early. In /etc/ntp.conf

...
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

In /var/log/messages:

May 30 18:16:13 davidep6 ntpd[6728]: ntpd 4.2.4p8@1.1612-o Fri Feb 22 11:23:27 UTC 2013 (1)
May 30 18:16:13 davidep6 ntpd[6729]: precision = 0.098 usec
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #0 wildcard, 0.0.0.0#123 Disabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #1 wildcard, ::#123 Disabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #2 lo, ::1#123 Enabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #3 eth0, fe80::a00:27ff:fe04:72eb#123 Enabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #4 lo, 127.0.0.1#123 Enabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on interface #5 eth0, 192.168.9.6#123 Enabled
May 30 18:16:13 davidep6 ntpd[6729]: Listening on routing socket on fd #22 for interface updates
May 30 18:16:13 davidep6 ntpd[6729]: kernel time sync status 2040
May 30 18:16:13 davidep6 ntpd[6729]: frequency initialized 436.432 PPM from /var/lib/ntp/drift
May 30 18:16:21 davidep6 ntpd[6729]: synchronized to 212.45.144.88, stratum 2
May 30 18:31:00 davidep6 ntpd[6729]: time reset +879.048993 s
May 30 18:31:00 davidep6 ntpd[6729]: kernel time sync status change 2001

When ntpd is restarted the clock is stepped (time reset +879.048993 s).

This seems a viable solution, what do you think?

#3 Updated by Davide Principi about 8 years ago

  • Status changed from ON_DEV to MODIFIED
  • % Done changed from 30 to 70

In nethserver-dev: nethserver-ntp-1.0.3-2.1.0git35a8ac16.ns6.noarch

#4 Updated by Davide Principi about 8 years ago

  • Status changed from MODIFIED to ON_QA
  • % Done changed from 70 to 80

In nethserver-testing:
nethserver-ntp-1.0.4-1.ns6.noarch.rpm

#5 Updated by Davide Principi about 8 years ago

  • Assignee deleted (Davide Principi)

Test case 1

  • stop ntpd
  • change system time, setting a time in the past
  • start ntpd

In /var/log/messages:

time reset +XXX

Test case 2

  • stop ntpd
  • change system time, setting a time in the future
  • start ntpd

In /var/log/messages:

time reset -XXX

#6 Updated by Giacomo Sanchietti about 8 years ago

  • Assignee set to Giacomo Sanchietti

#7 Updated by Giacomo Sanchietti about 8 years ago

  • Status changed from ON_QA to VERIFIED
  • % Done changed from 80 to 100

It works correctly setting a time in the past or in the future:

Jul 24 07:31:35 localhost ntpd[29534]: time reset -9517.760581 s

Jul 24 07:31:09 localhost ntpd[29506]: time reset +4854.115579 s

Marking VERIFIED

#8 Updated by Davide Principi about 8 years ago

  • Status changed from VERIFIED to CLOSED
  • Assignee deleted (Giacomo Sanchietti)

Released!

In nethserver-updates:
nethserver-ntp-1.0.4-1.ns6.noarch.rpm

Also available in: Atom PDF