Mailinglist Archive: opensuse (2912 mails)

< Previous Next >
Re: [SLE] Time synch problem
  • From: "Carlos E. R." <robin1.listas@xxxxxxxxxx>
  • Date: Tue, 15 Feb 2005 21:50:43 +0100 (CET)
  • Message-id: <Pine.LNX.4.58.0502120326250.7212@xxxxxxxxxxxxxxxx>

The Wednesday 2005-02-09 at 21:48 -0500, B. Stia wrote:

> On Wednesday 09 July 2003 19:31, (A long time ago) Carlos E. R. wrote:

Uau!

Actually, it was:

Date: Thu, 10 Jul 2003 01:31:55 +0200 (CEST)
From: Carlos E. R.
Subject: Re: [SLE] Time synch problem
X-Message-Number-for-archive: 152757

I have a longish archive :-)


>
> ..........<snipped some>..........
> > Or, you may have a temporary network connection, like I do; I will
> > explain this in some detail.
>
> Please do, I have been fooling with this for months now, off and on, and
> have yet to make this work successfully.

I wrote a micro-howto, posted at Togan's Unofficial SuSE FAQ, that has
about the same info, a bit more organized and expanded.

> >
> > We can adjust the clock to "internet" time, once, sometime after we
> > connect to internet. This, apparently, can be done with the daemon,
> > using some option I don't fully understand. Or we can use ntpdate - a
> > program which is to disappear some time in the future, but that I
> > use, and SuSE uses as well in its own script.
>
> ntpdate is still with us. I invoke it manually as root every once in
> awhile to update my time,

I know. But, as I said just below, calling "rcxntpd ntptimeset" is safer
and easier.

> > For this, we can simply call "/etc/init.d/xntpd ntptimeset" - and
> > assume that when "ntpdate" finally disappears SuSE will adjust the
> > script appropriately ;-)
>
> So far, so good :-)
> >
> > Of course, /etc/ntp.conf has to be configured; at least, it must have
> > a list of servers:
> >
> > server IP_address
> > server name_address
>
> This is what I normally invoke manually: ntpdate 216.139.201.6
> and then I do a hwclock --systohc
>
> And that would go where? In this line found about half way down the
> script?
> ##
> # server 127.127.8.0 mode 5 prefer

Well, simply:

server 216.139.201.6

should work. Right now, I don't know about "mode" and the other options,
but I don't think they matter. I'd have to verify.

Notice that calling "rcxntpd ntptimeset" is equivalent to calling
"ntpdate x.x.x.x". You can add several servers, and it will contact all of
them and use the best time available.



> > This is sufficient for "xntpd ntptimeset" to work; just leave the
> > rest of the config at the default values.
> >
> > Ok, so when is the appropriate time to make this time adjust? Well,
> > ideally, during system boot-up, after network connection is
> > established. This is done properly by the service xntpd, if enabled.
> > The SuSE script "/etc/init.d/xntpd start" does first a clock set
> > using ntpdate, if the variable XNTPD_INITIAL_NTPDATE is set to
> > "AUTO". Then, it starts the daemon to keep time synchronized.
>
> OK, it does that but is based on what exists at that time though,
> right ? and would be updated at the next boot-up for the adjusted time,
> right ? And that would be accomplished via the dial-up connection as
> per below.

I don't quite follow. Ok, I'll rephrase. If you have a permanent network
connection, then you can define service "xntpd" to run (chkconfig xntpd
on) to run during system init. This will set up the clock correctly on
every boot, querying a remote server for the date/time.

If you don't, then the other method applies.

In any case, that is different of the automatic drift adjustment based on
/etc/adjtime file.

(See the "further reading" at the end of this email)


> >
> > And, if our network connection is not permanent? Then, the script
> > "/etc/ppp/poll.tcpip", which is called from "/etc/ppp/ip-up", will
> > adjust the clock first thing: assuming we have some servers
> > configured, it will be done every time we connect to internet with
> > the modem. I do it differently, only once every five times, and I
> > also update the hwclock.
>
> As per what you do. I dial up, download my mail or whatever, sign off
> and then not dial up again until needed. Maybe 5 to 20 minutes at a
> time. There may be times where I do this 4 or 5 time during one session
> of several hours. And, how do you update the hwclock, from the same
> script/command ??
>
> This is what is in the ip-up script.
>
> run_poll_tcpip()
> {
> [ "$RUN_POLL_TCPIP" = "no" ] && return
>
> /etc/ppp/poll.tcpip | logger -p security.notice -t poll.tcpip
> >
> > The danger of this method is that the clock might suddenly go forward
> > or backward a bit (seconds or hours, it depends): not very nice on a
> > *nix system, but we can not avoid it.
>
> Hey, that is the way it is !!
> >
> >
> > More details to be aware of: what happens to the hardware or CMOS
> > clock?
> >
> > Well, the script "/etc/init.d/boot.clock" (read it, it is documented)
> > does this sequence of things (using the command "hwclock") before
> > starting system services:
> >
> > - Create if it doesn't exist, the file "/etc/adjtime"
>
> Have an adjtime
>
> > - Adjust hardware clock (CMOS) for known drift during the time the
> > computer has been off; this depends on the previous file to work.
> > - Copy CMOS clock (hardware) to system time (CPU and OS
> > maintained).
>
> ????

There are two clocks. Read my howto, I explain it there.

> >
> > After this, the system goes fully up, and maybe, the clock is
> > adjusted from the internet or by hand (danger!). But (and this is
> > very different than windows) the CPU maintained clock has to be
> > copied back to the CMOS, because the kernel doesn't do it. SuSE does
> > it in the script "/etc/init.d/halt" that copies system time to
> > hardware time just before power off. Me, I prefer to do it just after
> > I adjust to network time, inside "ip-up.local", like this:
>
> Don't have an ip-up.local file, and ip-up says "don't edit". Does it
> make a difference ? Either is fine by me unless there is some specific
> reason.

ip-up calls ip-up.local if it exists. Add your things to ip-up.local
only.

> >
> > /usr/sbin/rcxntpd ntptimeset
> > /sbin/hwclock --systohc
> >
> > More things to be aware of: a common mistake is manually adjusting
> > the system clock from kde control center (for example), and not
> > updating the hwclock at the same time: the drift adjust algorithm of
> > hwclock thinks that the CMOS clock is fast or slow by the same amount
> > you adjusted the clock, and the next boot it will adjust the time by
> > several hours... The solution is to delete "/etc/adjtime" and call
> > "/sbin/hwclock --systohc" just then (documented on the SuSE sdb).
>
> I never adust the time manually. Always call ntpdate and hwclock.
>
> Your explanation was very enlightening re: how the whole time thing
> works. That is good and adds to our knowledge. However, it is still not
> clear to me as to the way to adjust the time when I go on-line and keep
> the system accurate to a reasonable degree.
>
> Would appreciate a step-by-step saying put this line here and that line
> there.

Ok, there are two automatic ways. If your system runs
/etc/ppp/poll.tcpip (ie, you have not disabled it), that will do. It
contains the following code:

#
# Now set system time if we have some NTP servers
# and no running xntp.
#
while true ; do
set -- $(/sbin/runlevel)
test -e /etc/init.d/rc${2}.d/S*xntpd && break
test -x /usr/sbin/ntpdate || break
checkproc /usr/sbin/xntpd &> /dev/null && break
/usr/sbin/rcxntpd ntptimeset
break
done

Else, add something like this to /etc/ppp/ip-up.local

/etc/init.d/xntpd ntptimeset &> $NTPDATEOUT
. /etc/sysconfig/clock
/sbin/hwclock --systohc $HWCLOCK
# If HWCLOCK is for localtime or UTC. If not present, by default it uses whatever was done the last time.
# I put it just in case I deleted the /etc/adjtime file, because in that case it would use localtime.


My script does a few extra things, like syncing only once per day. I
haven't copied that for simplicity.


... some days later...

[ further reading ;-) ]


The sequence of events is this:

* Boot.
Run /etc/init.d/boot.clock
Check for existence of '/etc/adjtime', create if not.
Get time and date from the CMOS clock, adjusting for drift, with
command: /sbin/hwclock --adjust $HWCLOCK
Continue with boot, enter runlevel 2, 3 or 5
If service xntpd is enabled (1), run /etc/init.d/boot.clock/xntpd
(after $remote_fs $syslog $named are running)
Using the network, get correct time and set the clock, right now.
Start the xntpd daemon to keep the clock in time.
Continue boot.

* System running.
One of two things may happen:
If enabled, the xntpd daemon keeps the system clock on its toes.
If not, then ntpdate or 'rcxntpd ntptimeset' can be called
as soon as network goes up to update the time.
This is done from '/etc/ppp/poll.tcpip' without user
intervention. (2)

* System stopping.
...
The xntpd daemon stops.
...
Copy system time to cmos clock, calculate drift (3).


Notes:

(1) Running xntp only makes sense if you have a permanent network
connection.

(2) The pppd daemon calls '/etc/ppp/ip-up' if present. This script, wrote
by SuSE, calls 'poll.tcpip' and 'ip-up.local', if present. This
behaviour can be disabled by setting 'RUN_POLL_TCPIP = no' -
theoretically in '/etc/sysconfig/network/ifcfg-ppp0' (because it
appears to break '/sbin/conf.d/SuSEconfig.hostname')

(3) If at this point the time is incorrect, the CMOS clock will be set
incorrectly; and worse, the '/etc/adjtime' file will store the wrong
drift. Perhaps it would make sense to disable it.


--
Cheers,
Carlos Robinson


< Previous Next >
Follow Ups
References