[ltp] getting correct time on a laptop *solved*
Martin Steigerwald
linux-thinkpad@linux-thinkpad.org
Fri, 18 Aug 2006 16:23:18 +0200
Hello,
just wanted to inform you, that I solved the getting correct time on a
laptop problem since quite some time (see older thread with that
subject). It works in a ifplugd / guessnet controlled automatic network
adaption setup and it works nicely together with suspend to disk
(currently sws2, but that shouldn't matter).
I still use chrony, but I made some adaptions for it in order to work.
1) on suspend chrony is stopped after the network is brought down
2) on resume chrony is started before the network is brought up again (and
thus the mechanism to switch chrony into online mode when network it
brought up works)
3) as a work-around for my DSL environment and chrony's feature not to try
again on DNS failure chrony is restarted again 1-2 minutes after the
network has been brought up. The DSL modem needs some time to setup the
internet connection.
4) hwclock is disabled:
root@deepdance:~ -> head -1 /etc/init.d/hwclock.sh
exit 0
root@deepdance:~ -> head -1 /etc/init.d/hwclockfirst.sh
exit 0
5) chrony runs with following configuration options:
server de.pool.ntp.org offline minpoll 8
server de.pool.ntp.org offline minpoll 8
server de.pool.ntp.org offline minpoll 8
Regulate realtime clock
rtcfile /var/lib/chrony/chrony.rtc
This gives a fast adaption if clock differs by more than 30 seconds...:
initstepslew 30 de.pool.ntp.org de.pool.ntp.org
6) For real time clock I added "genrtc" module to /etc/modules
7) Chrony is brought online when network is brought up and offline when it
is brought down: I copied the scripts /etc/ppp/ip-up.d/chrony
and /etc/ppp/ip-down.d/chrony to /etc/network/if-up.d/chrony
and /etc/network/if-down.d/chrony. I adapted up and down scripts to use a
different /var/run filename. I adapted the if-up.d-Script to trigger the
chrony restarting after to minutes
/etc/acpi/hibernate.sh:
#!/bin/sh
# Detect change of network environment and handle chrony
/etc/init.d/ifplugd stop
ifdown eth0
/etc/init.d/chrony stop
sync
hibernate
# Detect change of network enviroment and handle chrony
/etc/init.d/chrony start
/etc/init.d/ifplugd start
/etc/network/if-up.d/chrony:
#!/bin/sh
# Start chrony stuff in at least one minute, lets see whether that works,
26.6.2006
#nohup /etc/chrony/network-up.sh
at -f /etc/chrony/network-up.sh now
#/etc/chrony/network-up.sh </dev/null 2>&1 >/dev/null &
#screen /etc/chrony/network-up.sh
The nohup, /dev/null variante blocked ifplugd and a screen can not be
started from a script...
/etc/network/if-down.d/chrony:
#!/bin/sh
# This script tells chronyd that the connection is down
# so that it won't try to contact the server.
# John Hasler <jhasler@debian.org> 1998-2003
# Any possessor of a copy of this program may treat it as if it
# were in the public domain. I waive all rights.
# Put a hint in the logfile that we are running
logger "/etc/network/if-down.d/chrony: Putting chrony offline..."
/bin/pidof chronyd > /dev/null || exit 0
# Don't mark the connection offline unless we know ppp brought it up.
test -e /var/run/chrony-eth0-up || exit 0
KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf)
PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys`
/usr/bin/chronyc >/dev/null << EOF
password $PASSWORD
offline
EOF
rm -f /var/run/chrony-eth0-up
exit 0
/etc/chrony/network-up.sh:
#!/bin/sh
# This script tells chronyd that the connection is up so that it can
# contact the server. John Hasler <jhasler@debian.org> 1998-2003
# Any possessor of a copy of this program may treat it as if it
# were in the public domain. I waive all rights.
# Debugging?
#set -x
# Wait a bit till the DSL router likely built up an internet connection
sleep 60
# Put a hint in the log file that we are running
logger "/etc/chrony/network-up.sh: restarting chrony, put it online and do
some rapid measurements..."
# Make sure that chrony does DNS lookups, 25.6.2006, martin
# Should better wait till pool.ntp.org can be accessed!
# but for now I tell at to defer it about a minute, 25.6.2006, martin
/etc/init.d/chrony restart >/dev/null
# Otherwise chronyc will hang ;(, oh man this is sucking so extremely,
26.6.2006, martin
sleep 5
# Copied from /etc/ppp/ip-up.d/chrony, just modified the /var/run
filename, 25.6.2006, martin
/bin/pidof chronyd > /dev/null || exit 0
KEY=$(awk '$1 ~ /^commandkey$/ { print $2; exit}' /etc/chrony/chrony.conf)
PASSWORD=`awk '$1 ~ /^'$KEY'$/ {print $2; exit}' /etc/chrony/chrony.keys`
/usr/bin/chronyc > /dev/null << EOF
password $PASSWORD
online
EOF
touch /var/run/chrony-eth0-up
exit 0
I know my solution is a hack and it would be way better if chrony handled
network outages automatically and would retry DNS lookups from time to
time, but at least this works for my highly inaccurate IBM ThinkPad T23
clock.
And no right now I didn't yet replace the CMOS battery ;).
My solution produces undesirable results when you use more than one
network interface for internet access at once. If you switch network
interfaces you have to bring down the old network interface before
bringing up the new one.
Maybe this helps someone. Suggestions welcome. I believe it can be
improved in many ways. For now I am just happy that I have a second exact
clock on my laptop.
Regards,
--
Martin 'Helios' Steigerwald - http://www.Lichtvoll.de
GPG: 03B0 0D6C 0040 0710 4AFA B82F 991B EAAC A599 84C7