view · edit · print · history

Running ntpclient in the background from init.d scripts doesn't require nohup and only one '&' is needed. I changed those.


How to Fix the Clock using Only ntpclient (correctly)

The documentation for ntpclient says:

On to ntpclient -l. This is actually easy, if you performed and understood the previous steps. Run
     ntpclient -l -h $NTPHOST
in the background.

which to me implies that you must deliberately run ntpclient in the background when using -l.

This is what I use then, following the advice in http://doolittle.icarus.com/ntpclient/HOWTO(approve sites)

Install ntpclient:

ipkg install ntpclient

Create the file /opt/etc/init.d/S10ntpclient containing the following:

if [ -n "`pidof ntpclient`" ]; then
/bin/killall ntpclient 2>/dev/null
/opt/bin/ntpclient -f 0 -s -l -i 600 -g 10000 -h pool.ntp.org >> /var/log/ntp.log &

In /etc/crontab , delete the line containing hwclock.

Make /opt/etc/init.d/S10ntpclient script executable: chmod +rx /opt/etc/init.d/S10ntpclient

Run the S10ntpclient script once by hand, and then it will run automatically every time you reboot.

This keeps accurate time on my Unslung as compared to an atomic (radio-controlled) clock. It is simpler than explicit use of adjtimex but still corrects the drift using that feature of ntpclient.

Alternate method based on ntpclient

Unfortunately, the above method does not work correctly for me. Somehow, ntpclient gives up after some time, with the '# inconsistent' message in the log file. Difficult to find good information on what to change to circumvent this message (my clock is too irregular?).

What I do instead of running ntpclient as background job, is running a small script basically doing an endless loop containing 'sleep 600', followed by '/var/log/ntpclient -f 0 -s -g 100000 -h nl.pool.ntp.org >>/var/log/ntp.log'. I copied ntpclient to the RAMdisk in /var/log, in order not to wake the hard disk in case it is asleep (see SpinDownUSBHarddisks?).

I start this script from a wrapper script in /opt/etc/init.d/S92ntpclient (the script itself does not return, as it contains an endless loop). I use S92 in order to schedule it after the RAMdisk creation (the wrapper also copies the ntpclient executable to the RAMdisk).

Is this an appropriate solution, or are there better ideas?

view · edit · print · history · Last edited by Kees Moerman.
Based on work by Kees Moerman, SamiT, and RFinch.
Originally by RFinch.
Page last modified on April 27, 2009, at 02:48 PM