Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
NTP delays boot components
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sat Mar 08, 2014 7:18 pm    Post subject: NTP delays boot components Reply with quote

For a special project I'm running a .start script in /etc/local.d/ that deletes /home/* and re-creates the necessary folders and files there. NTP takes at least a few seconds to start at boot which delays the running of that script. During those seconds, someone could log in to an old home folder via lightdm. NTP also delays shorewall which causes some other problems. What can I do about this?
Back to top
View user's profile Send private message
milomouse
n00b
n00b


Joined: 13 May 2013
Posts: 14

PostPosted: Sat Mar 08, 2014 7:58 pm    Post subject: Reply with quote

I'm relatively new to NTP but could there be a delay in ntp while waiting for the network? Or traffic suffers when communicating with the server pool? For me, my network isn't always available right away which led to appending these lines below the default servers in /etc/ntp.conf as per http://wiki.gentoo.org/wiki/Ntp#Server and ntp starts immediately during the boot process.

Code:
server 127.127.1.0
fudge  127.127.1.0 stratum 10


Not sure if this is related to your delay or not (since I do not know your configuration variables), just an idea.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sun Mar 09, 2014 2:59 pm    Post subject: Reply with quote

That sounds like exactly what I need, but it doesn't seem to speed things up for me. Boot is still delayed for about 12 seconds on:

Code:
Setting clock via the NTP client 'ntpdate'


I'm using an otherwise completely default NTP config.
Back to top
View user's profile Send private message
milomouse
n00b
n00b


Joined: 13 May 2013
Posts: 14

PostPosted: Sun Mar 09, 2014 3:32 pm    Post subject: Reply with quote

Well, you seem to be running ntp-client instead of ntpd. If I understand correctly, if you run ntpd it acts as both server and client. Refer to: http://wiki.gentoo.org/wiki/Ntp#Server_2
Quote:
Add ntpd to the default runlevel to have the time synchronized automatically. There is no need to run a client when the service is running. Make sure you are not running ntp-client or ntpdate.

Quote:
If ntpd is run as a service, the time will automatically synchronize as long as the difference between the local time and the time on the server is less than 1000s (~17min).
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sun Mar 09, 2014 5:04 pm    Post subject: Reply with quote

Yes! Thank you so much.

The ebuild message is confusing though:

Code:
The way ntp sets and maintains your system time has changed.
Now you can use /etc/init.d/ntp-client to set your time at
boot while you can use /etc/init.d/ntpd to maintain your time
while your machine runs


That sounds like ntpd and ntp-client should both be started automatically. Should I file a bug?
Back to top
View user's profile Send private message
milomouse
n00b
n00b


Joined: 13 May 2013
Posts: 14

PostPosted: Sun Mar 09, 2014 5:29 pm    Post subject: Reply with quote

Not sure, but I guess it couldn't hurt. Maybe it will prompt a response from the package maintainer(s) or users as to why the message says what it does. Again, I am relatively new to NTP so my experience is limited. Anyway, glad this has helped with your situation!
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Tue Mar 11, 2014 8:01 pm    Post subject: Reply with quote

Can anyone confirm that the wiki is correct? There is some disagreement:

https://bugs.gentoo.org/show_bug.cgi?id=504096
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3920
Location: Hamburg

PostPosted: Tue Mar 11, 2014 9:39 pm    Post subject: Re: NTP delays boot components Reply with quote

grant123 wrote:
During those seconds, someone could log in to an old home folder via lightdm. NTP also delays shorewall which causes some other problems. What can I do about this?
quick&dirty: "after ntp-client" to /etc/init.d/xdm.
But this won't help in every case, probably run the xdm script from /etc/local.d_after_ you cleaned the HOME dirs.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Tue Mar 11, 2014 9:45 pm    Post subject: Reply with quote

So both ntp-client and ntpd should be started at boot?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Mar 11, 2014 9:47 pm    Post subject: Reply with quote

grant123 ...

It doesn't sound as though ntpd or ntp-client is the issue, its either DNS resolution (given that both ntpd and ntpd-client initscripts have "use net dns") or your dhcp is perhaps getting ntp info that causes it to request time service from the ISP (some ISP provided routers/DNS are configured to resolve to their ntp service) or something of that nature. In terms of DNS you can perhaps use a service other than that provided by the ISP (or router, if thats where DNS is provided) or run a caching DNS server (ie, net-dns/unbound or net-dns/pdnsd). For your dhcp client you can configure it to not request such information:

/etc/conf.d/net
Code:
dhcp_eth0="nontp"

HTH & best ... khay
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Fri Mar 14, 2014 11:14 pm    Post subject: Reply with quote

All of my systems actually use unbound. One of my networks uses DHCP to get an IP from the ISP, but it uses wicd to do that so I can't specify nontp. My other network specifies its own IP statically and so doesn't use DHCP and ntp-client still takes ~12 seconds to start.

I'm not clear on the expected behavior here. ntp-client shouldn't take ~12 seconds to start? All of my systems exhibit that behavior.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Mar 14, 2014 11:47 pm    Post subject: Reply with quote

grant123 wrote:
All of my systems actually use unbound.

grant123 ... OK, this poses the question: how is unbound configured?

grant123 wrote:
One of my networks uses DHCP to get an IP from the ISP, but it uses wicd to do that so I can't specify nontp.

You can use the '--nohook ntp' switch to dhcpcd ... if wicd doesn't allow you to configure such things you can edit /etc/dhcpcd.conf and add 'nohook ntp'.

grant123 wrote:
My other network specifies its own IP statically and so doesn't use DHCP and ntp-client still takes ~12 seconds to start.

OK, but I was speculating on probable causes ... I also use unbound, dhcpcd, and ntp-client and I am not seeing this same issue.

grant123 wrote:
I'm not clear on the expected behavior here. ntp-client shouldn't take ~12 seconds to start? All of my systems exhibit that behavior.

In which case there is probably some aspect of your setup that these various systems have in common. So far there isn't much in this thread that provides much of a clue, so you need to provide some concrete information to go on. You might also try a process of elimination, disabling unbound, dhcpcd (while asignining a static IP), etc, so as to track down the probable culprit

HTH & best ... khay
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Fri Mar 14, 2014 11:55 pm    Post subject: Reply with quote

Why don't you give your tasks to the script that delete/recreate home ?

Per example, lightdm run from the script itself after you have made your /home tasks.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sat Mar 15, 2014 12:24 am    Post subject: Reply with quote

What is gained by starting ntp-client? Everything seems to work fine (and no 12 second delay) if I start ntpd and don't start ntp-client (as suggested in the wiki).
Back to top
View user's profile Send private message
milomouse
n00b
n00b


Joined: 13 May 2013
Posts: 14

PostPosted: Sat Mar 15, 2014 2:22 pm    Post subject: Reply with quote

Using the init script, "ntp-client" checks for time change in the foreground (therefore the rest of init scripts are on hold until this finishes), whereas "ntpd" is a daemon that is run in the background and checks for time change there (allowing the rest of init to start while this is happening)? On a system where time accuracy is critical to boot, say before a user reaches login, you may use ntp-client first but have ntpd run afterwards if your system is going to be up for a while. For most users, ntpd is probably sufficient but if you have a strict logging time (or file modification down to the second is crucial) then you may need ntp-client during init..

Of course internet, DNS resolve, caching, etc, are factors in your foreground ntp-client speed, as I believe @khayyam has mentioned. As of right now, if you're having a 12s delay with ntp in foreground then chances are there is a 12s delay in checking/setting time when running ntp in background. So, its possible that users may reach login before the time is changed (if needed). Anyway, just thinking out loud, anyone correct me if I'm wrong, etc, etc.

On a side note, if I start ntp-client during init the boot delay is only a few seconds and not 12 or so as you describe. Maybe there is something else going on causing your delay. You could always create a custom init script to run in "default" (before net) that writes DATE to a file after / is +rw, then another script (or just you) check DATE time after ntp-client& and/or ntpd (after ntp-client ntpd) to see how long it takes or if there is a change, etc.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21490

PostPosted: Sat Mar 15, 2014 3:35 pm    Post subject: Reply with quote

ntpd may refuse to change the time if doing so would result in a large jump. ntp-client has no such restriction. A large time change after processes start may confuse some tools. For example, xscreensaver locks the display if the current wall time is more than its tolerance away from the wall time of last user activity. To see this, set your clock forward a day and watch your screen immediately blank/lock. Build tools may also become confused if the system goes backward in time. Therefore, you generally want to get the time to be approximately correct as soon as you can after boot.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sun Mar 16, 2014 1:02 am    Post subject: Reply with quote

Thanks for the explanation guys, that makes sense. What is the setting that updates the system clock right before rebooting or shutting down? I would think that would minimize the time jump on boot.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Tue Apr 01, 2014 5:47 pm    Post subject: Reply with quote

Does anyone remember that setting?
Back to top
View user's profile Send private message
overkll
Veteran
Veteran


Joined: 21 Sep 2004
Posts: 1249
Location: Austin, Texas

PostPosted: Tue Apr 01, 2014 8:13 pm    Post subject: Reply with quote

Look in /etc/conf.d/hwclock.

ntp-client and ntpdate are just slow. They used to update the clock immediately but something changed sometime ago and both have become quite slow. I don't think the dhpc or dns has anything to do with it.

If one disables ntpd, then restarts ntp-client or run ntpdate -s <yourchoiceofntpserver.tld> you'll see how slow it is.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Tue Apr 01, 2014 8:34 pm    Post subject: Reply with quote

It's really slow here too.

It looks like the hwclock is synchronized with the swclock on boot and shutdown by default. Does that mean my swclock should be accurate within a small margin of error at boot?

EDIT: I'm thinking ntp-client makes sense for a system that is always online, but maybe not for a laptop that is only online intermittently.
Back to top
View user's profile Send private message
aevertett
n00b
n00b


Joined: 23 Jun 2014
Posts: 4

PostPosted: Fri Jul 04, 2014 12:55 pm    Post subject: Reply with quote

Generally, a linux host computers system time is set to the hardware real time clock at start up and then the hardware clock is set to the system time at shutdown. The thinking behind this is that the hardware real time clock maintains time during power down. However, if the hosts system clock is corrected by a NTP server or GPS hardware clock during normal operation, then this also corrects the hardware real time clock at shutdown. At start up the hardware clock should therefore be not too far away from the correct time.
Ev.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Fri Jul 04, 2014 3:33 pm    Post subject: Reply with quote

Is ntp-client really necessary then?
Back to top
View user's profile Send private message
vaxbrat
l33t
l33t


Joined: 05 Oct 2005
Posts: 731
Location: DC Burbs

PostPosted: Fri Jul 04, 2014 3:50 pm    Post subject: time drift, etc Reply with quote

The closer the pool of clocks are for ntp-client the better (eg on your lan ntp pool vs external gentoo server pool). If I recall from my research of ntp some years back, there are a number of calls to the ntp host server in order to determine network latency. That's what takes a few seconds (other than those times when your dns is messed up, and you're dealing with resolver timeouts).

The hardware clock will tend to drift. The amount of that drift can differ greatly between brands of machine. A hideously expensive server tends to have a real good hardware clock, but that's about the only given. Your mobo battery may be dead and leave you permanently in the 1970's each time you boot. This is why ntp protocol prefers a pool of at least 3 servers to keep an eye on each other and measure the amount of slew in each others clock.

If you have a dedicated clock device such as a gps unit attached to your network, its time will be dead-on accurate. That's why if you have one of these things, you make your ntp.conf use it as the definitive guy that trumps all others.
Back to top
View user's profile Send private message
Pearlseattle
Apprentice
Apprentice


Joined: 04 Oct 2007
Posts: 162
Location: Switzerland

PostPosted: Fri Jul 04, 2014 8:14 pm    Post subject: Reply with quote

grant123 wrote:
Is ntp-client really necessary then?

It is, if for any reason your clock is skewed by more than (60 seconds? 60 minutes? Don't remember).
If that's the case (e.g. in the case of a battery failing) then ntpd will refuse to synchronize (as the time difference is huge it will suppose that something basic is broken in your system).

Direct answer:
In my opinion (and this is what I did) the best option is not to enable neither ntp-client nor ntpd directly but to write an own init-script that runs in the background and starts firsts ntp-client and then ntpd on its own.
This is ok only if your PC skews towards the past - if it does it towards the future I would then keep things as they are.
Same thing for a server - better spend 10 seconds more during boot than to have to deal with inconsistencies with the datetime of the files.
Cheers
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54097
Location: 56N 3W

PostPosted: Fri Jul 04, 2014 9:41 pm    Post subject: Reply with quote

Pearlseattle,

PC BIOS clocks always lose time.

When the crystals are cut, a spread of frequencies ore obtained. They can be divided into two groups.
Fast - those that gain time and slow, those that loose time.
Fast crystals can be slowed down in the electronics. Slow ones are always slow. This makes slow crystals cheap, so they find their way into PCs
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum