Ntpd Installation

Aus Gude Systems GmbH
Zur Navigation springen Zur Suche springen

NTPD - Network Time Protocol Daemon

You can use ntpd to run your linux PC as NTP server. Beside using other ntp servers as time source, ntpd supports various parse drivers to read external hardware clock devices.

This HOWTO describes to install ntpd from tarball, which is maybe not recommended when your Linux distribution comes with ntpd as binary package, already pre-compiled using all refclock parse drivers.


NTPD supported devices

  • Expert mouseCLOCK
  • Expert mouseCLOCK NTS
  • Expert mouseCLOCK USB II (ntpd >= v4.2.4)
  • Expert GPS Clock
  • Expert GPS Clock USB
  • EMC Professional ( V.24 config XNTP)
  • EMC Professional NET


Installing NTPD with get_ntp.tar.gz

  • Please use the script make_all.sh from get_ntp.tar.gz to download, patch and compile ntpd in one step.
  • get_ntp is using the ntp.org sources, plus some custom patches to maintain optimal hardware compatibility with Gude devices
  • if you want to manually review and install these patches, please follow the instructions from make_all.sh
wget https://files.gude-systems.com/ntp/get_ntp.tar.gz
tar -xzvpf get_ntp.tar.gz
cd get_ntp
./make_all.sh

Note:

  • running ./make_all.sh will just download, patch and compile the ntpd sources in it's own local subdirectories, without tainting your root filesystem
  • running make install is skipped for now, for it will copy all binaries to your root file system, so make sure you have no other ntp distributions installed (such as rpms, debian packages, etc)
  • if you want to install, change directory to the ntpd sources (like : cd ntpd- and run make install

Additional kernel mode drivers

All devices listed above are polled by a userspace serial device (e.g. /dev/ttyS0). If the device has a real serial interface, such as the Expert mouseCLOCK or the Expert GPS Clock, you do not need any aditional kernel mode drivers. If you are using an USB device, there has to be a kernel mode driver which emulates a serial interface.

  • You need USB FTDI Single Port Serial Driver support to run the Expert mouseCLOCK USB II (ftdi_sio.ko)
  • You need USB Prolific 2303 support to run the Expert GPS Clock USB (plusb.ko)

Make sure your kernel supports:

Code maturity level options  --->
  [*] Prompt for development and/or incomplete code/drivers

Device Drivers  --->
  USB support  --->
    <*> Support for USB
    <M>   EHCI HCD (USB 2.0) support
    <M>   OHCI HCD support
    <M>   UHCI HCD (most Intel and VIA) support

    USB Serial Converter support  --->
      <M>   USB FTDI Single Port Serial Driver (EXPERIMENTAL)
      <M>   USB Prolific 2303 Single Port Serial Driver

Configuring serial interface

tty symlink, refclock-0

Before we start configuring ntpd, we need to prepare our serial device environment. ntpd assumes a symlink to the serial interface the hardware is connected to.

  • make /dev/refclock-0 link to the tty your dcf clock is connected to
  • make /dev/gps0 link to the tty your Expert GPS Clock is connected to


  • Expert mouseCLOCK / EMC Professional / EMC Professional NET
ln -s /dev/ttyS0 /dev/refclock-0
  • Expert mouseCLOCK USB II (ntpd >= v4.2.4)
ln -s /dev/ttyUSB0 /dev/refclock-0
  • Expert GPS Clock
ln -s /dev/ttyS0 /dev/gps0
  • Expert GPS Clock USB
ln -s /dev/ttyUSB0 /dev/gps0

udevd

If your system is using udevd, it is recommended to configure udevd to create the right symlink once a device appears. Try to insert one the following rules to /etc/udev/rules.d/99_mydevice.rules :

  • Expert mouseCLOCK / EMC Professional / EMC Professional NET
KERNEL=="ttyS*", NAME="%k", SYMLINK="refclock-%n", GROUP="uucp"
  • Expert mouseCLOCK USB II (ntpd >= v4.2.4)
KERNEL=="ttyUSB*", ATTRS{idProduct}=="e88a", SYMLINK+="refclock-%m"
  • Expert GPS Clock
KERNEL=="ttyS*", NAME="%k", SYMLINK="refclock-%n", GROUP="uucp"
  • Expert GPS Clock USB
KERNEL=="ttyUSB*", ATTRS{idProduct}=="2303", SYMLINK+="gps%m"

Note: After you added new rules, udevd needs to be restarted to apply the new ruleset:

kill -HUP udevd

Receiver signal test

testdcf : Expert mouseCLOCK signal test

If you are using the Expert mouseCLOCK or Expert mouseCLOCK USB II, you should now start a brief signal test with testdcf:

  • Expert mouseCLOCK :
./parseutil/testdcf /dev/refclock-0
  • Expert mouseCLOCK USB II (ntpd >= v4.2.4) :
./parseutil/testdcf /dev/refclock-0 --type=1
~/ntp-4.2.8/parseutil > ./testdcf /dev/refclock-0

   setting RTS/DTR for GudeADS Expert mouseCLOCK ...

   DCF77 monitor 4.11 - Copyright (C) 1993-2006, Frank Kardel

   RADMLSMin....PHour..PMDay..DayMonthYear....P
   RADMLS1248124P124812P1248121241248112481248P
 \ ............................................ *** INCOMPLETE
 / -###--#-###---##------#--------#............ *** INCOMPLETE
 \ ............................................ Mo, 13:21:09, 07.07.03, <__D_>

If you receive a time like this, you receiver is operating OK. If it takes about 2 or 3 minute to receive a time, your receiver works perfectly. If not, please try to find a better position and make sure the LED blinks very periodically one time per second.

Expert GPS Clock signal test

You now can use a common terminal application to check whats dropping out of your GPS receiver.

minicom -s
┌───────────────────────────────────────────────────────────────────────┐
│ A -    Serial Device      : /dev/gps0                                 │
│ B - Lockfile Location     : /var/lock                                 │
│ C -   Callin Program      :                                           │
│ D -  Callout Program      :                                           │
│ E -    Bps/Par/Bits       : 4800 8N1                                  │
│ F - Hardware Flow Control : Yes                                       │
│ G - Software Flow Control : No                                        │
│                                                                       │
│    Change which setting?                                              │
└───────────────────────────────────────────────────────────────────────┘
        │ Screen and keyboard      │
        │ Save setup as dfl        │
        │ Save setup as..          │
        │ Exit                     │
        │ Exit from Minicom        │
        └──────────────────────────┘

The GPS receiver indicates a valid time at the GPSRMC NMEA sentence. (Status A=active or V=Void).

$GPRMC,083202.152,A,5056.7397,N,00657.1417,E,0.05,263.84,190307,,,A*6A
$GPGSA,A,2,16,22,03,,,,,,,,,,3.0,2.8,1.0*3F

Here, you received 08:32 UTC, the time as valid (A), and you have signals from three satellites in charge of that time: 2, 16, 22, 03. For detailed infos, please each check GPS NMEA sentance information.

Hint: instead of using minicom you can do:

stty -F /dev/gps0 4800 && cat /dev/gps0

EMC Professinal signal test

Now you can use a common terminal application to check what is transmitted via the serial interface.

minicom -s
┌───────────────────────────────────────────────────────────────────────┐
│ A -    Serial Device      : /dev/ttyS0                                │
│ B - Lockfile Location     : /var/lock                                 │
│ C -   Callin Program      :                                           │
│ D -  Callout Program      :                                           │
│ E -    Bps/Par/Bits       : 9600 8N1                                  │
│ F - Hardware Flow Control : Yes                                       │
│ G - Software Flow Control : No                                        │
│                                                                       │
│    Change which setting?                                              │
└───────────────────────────────────────────────────────────────────────┘
        │ Screen and keyboard      │
        │ Save setup as dfl        │
        │ Save setup as..          │
        │ Exit                     │
        │ Exit from Minicom        │
        └──────────────────────────┘
Welcome to minicom 2.2

OPTIONS: I18n
Compiled on Aug 27 2007, 08:52:48.
Port /dev/ttyS0

               Press CTRL-A Z for help on special keys

.

141300061107
.
.

141400061107
.

to reassure, you can use /dev/ttyS0 and /dev/refclock-0 as tty when using minicom.

Hint: instead of using minicom you can do:

stty -F /dev/ttyS0 9600 && cat /dev/ttyS0


ntpd configuration file /etc/ntp.conf

To tell ntpd which hardware is connected to which serial interface, adjust /etc/ntp.conf to fit your purpose.
You find this sample ntp.conf within Get_ntp.tgz:

#################################
# local clock
server 127.127.1.0
fudge 127.127.1.0 stratum 10

#################################
# Expert mouseCLOCK USB II
# server 127.127.8.0 mode 19

#############################################
# Expert mouseCLOCK
# server 127.127.8.0 mode 14

#############################################
# Expert mouseCLOCK NTS
# server 127.127.8.0 mode 16

#################################
# EMC Professional
# server 127.127.8.0 mode 12

#################################
# Expert GPS CLOCK (NMEA device)
# server 127.127.20.0

# logging
logfile /var/log/ntp
logconfig =all

# you should not need to modify the following paths
driftfile       /var/lib/ntp/ntp.drift

# additional use internet ntp time server
#server timeserver.example.org
  • Note: Lines beginning with # are remarks, so un-remark the # server line to match your hardware.
  • Extra info : Server 127.127.8.0 mode 14 means :
    • 127.127 : use hardware parse driver
    • .8 : use parse driver 8
    • .0 : use reflock-0 to poll this device
    • mode 14 : use driver 8's clock type 14

Starting ntpd

If you installed ntpd by make install, you should be able to call ntpd like this

/usr/sbin/ntpd

In case you need an rc script to start ntpd automatically in certain runlevels, please feel free to use this sample rc script '/etc/init.d/ntpd:

 case "$1" in
   start)
       echo -n "Starting ntpd "
       /usr/sbin/ntpd
       echo -e " done"
       ;;
   stop)
       echo -n "Shutting down ntpd:"
       killall /usr/sbin/ntpd
       echo -e " done"
       ;;
   reload|restart)
       $0 stop  &&  $0 start
       ;;
   status)
       echo -n "Checking for service ntpd: "
       checkproc /usr/sbin/ntpd && echo OK || echo No process
       ;;
   *)
       echo "Usage: $0 {start|stop|status|reload|restart}"
       exit 1
 esac

Debugging

Getting ntpd's operational status infos

ntpd can be queried by ntpq

# ntpq -c clocklist

status=0001 clk_okay, last_clk_noreply,
device="RAW DCF77 CODE (DTR SET/RTS CLR)",
timecode="-----------------D--S124-12-P124-1-p-2--1-1-----8--2------P",
poll=29, noreply=1, badformat=3, baddata=0, fudgetime1=258.000,
fudgetime2=0.000, stratum=0, refid=DCFa, flags=0,
refclock_time="c10254a1.00000000  Mon, Aug 12 2002 15:37:05.000 UTC",
refclock_status="DST; TIME CODE; (LEAP INDICATION; ANTENNA)",
refclock_format="RAW DCF77 Timecode",
refclock_states="*NOMINAL: 00:29:05 (94.07%); NO RESPONSE: 00:01:16 (4.09%); 
ILLEGAL DATE: 00:00:34 (1.83%); running time: 00:30:55"
# ntpq -c peers
  remote           refid      st t when poll reach   delay   offset  jitter
 ==============================================================================
  *GENERIC(0)      .DCFa.     0  l    5   64    1    0.000   22.846   0.008

This ntpq query shows that your Expert mouseCLOCK has been running for 29:05 minutes, with 94.07% of clean received radio signals. Ntpd should now operate as ntp server!

Server time synchronized?

If ntpd gets synchronized to your refclock's time, it will show in /var/log/ntp

14 Dec 11:46:00 ntpd[14402]: PARSE receiver #0: SYNCHRONIZED
14 Dec 11:46:00 ntpd[14402]: clock GENERIC(0) event 'clk_okay' (0x00)

Avoiding sanity limit

If ntpd does not work, your clock may have drifted too far. If you view /var/log/ntp, you may see an entry similar to:

18 Aug 21:04:40 ntpd[7220]: time correction of 1738 seconds exceeds sanity limit (1000); set clock manually to the correct UTC time. 

This sanity check can be overridden by adding the command-line switch "-g" when starting ntpd.

ntpd -g

Further information