# ntp-client sntp randomly fails?

## tld

EDIT: I've changed the subject of this thread because of my findings (in my reply below).

I've been going crazy trying to get the ntp-client service working reliably on my MythTV frontend machine.

I use my MythTV backend server as a master ntp server and sync other machines, including the above frontend, to it.

I recently discovered that without realizing it, my /etc/conf.d/ntp-client, unlike my ntp.conf setup, was using the default settings (pointed to 0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org etc). The reason I was looking into any of this in the first was because I periodically had that part of the boot process hang for a VERY long time...I'll get into that later.

Here's what's in my current /etc/conf.d/ntp-client:

```

NTPCLIENT_CMD="sntp"

NTPCLIENT_OPTS="-p -t 5 -s mythback"
```

When rebooting today, that failed.  I shelled into the machine and tried to start it, and had it fail twice:

```
mythfront ~ # /etc/init.d/ntp-client start

 * Setting clock via the NTP client 'sntp' ...

 1 Apr 11:26:52 sntp[1308]: Started sntp

 * Failed to set clock                                                                                                                          [ !! ]

 * ERROR: ntp-client failed to start

mythfront ~ # /etc/init.d/ntp-client start

 * Setting clock via the NTP client 'sntp' ...

 1 Apr 11:27:05 sntp[1320]: Started sntp

 * Failed to set clock                                                                                                                          [ !! ]

 * ERROR: ntp-client failed to start

```

However I manually ran the same sntp command being run by the service and that worked:

```
mythfront ~ # sntp -p -t 5 -s mythback

 1 Apr 11:28:58 sntp[1370]: Started sntp

2014-04-01 11:28:58.128453 (+0500) +0.070404 +/- 0.954361 secs
```

After that, it started with no problem, and I can't even make it fail if I wanted to:

```
mythfront ~ # /etc/init.d/ntp-client start

 * Setting clock via the NTP client 'sntp' ...

 1 Apr 11:29:05 sntp[1383]: Started sntp

2014-04-01 11:29:05.040283 (+0500) +0.000012 +/- 0.954468 secs
```

WTF?  As far as the "-t 5" option:  When pointed to the gentoo ntp servers I periodically had issues where the boot would hang on that step.  That got me looking into what sntp might have as far as timeout options.  That led me to this all but indiscernible mess:

http://bugs.ntp.org/show_bug.cgi?id=2233

According to that, apparently recent versions of sntp have a -g option for overall wait timeout.  However the current version has only -t which is number of seconds to wait for broadcasts.  What I discovered is that the person who logged that bug was correct in that it actually takes five times the "-t" value for an actual timeout.  Also, it turns out the default -t value is 68 seconds, meaning it can hand for up to 5:40!...I was able to prove that out by attempting to sync to an invalid ip...I mean seriously(??).

Anyway...if anyone has any ideas as to those failures I'd love to hear it.

TomLast edited by tld on Fri Jul 25, 2014 12:57 pm; edited 3 times in total

----------

## tld

Wow...I figured out the issue with that ntp-client service, though I was pretty surprise at what I found:

During the boot process the sntp program is apparently failing to resolve the name mythback, which is in my /etc/hosts file.  As you can see above, after the system's up, it works.

I've changed to the title of the thread accordingly.  Any ideas what would cause that?

Tom

----------

## Tony0945

I'm guessing that it's got to do with the order that services start at boot. 

Just wanted to post to encourage you to continue. I'm very interested in this, but very much the noob.

----------

## freke

Have you tried editing /etc/conf.d/ntp-client to point to the ip-address instead? (ie. just to verify that it really it's because it's not using /etc/hosts - or it's because the network is not available at the time?)

----------

## khayyam

tom ...

please try replacing 'rc_use=dns' with 'rc_need=net' in /etc/conf.d/ntp-client

If this doesn't resolve the issue, could you post /etc/hosts and the ntp-client config

HTH & best ... khay

----------

## tld

Thanks for the replies!  In answer to all the various questions, I have to back-pedal on my previous post:

I thought this was related to the hosts file etc, because it worked when I changed my /etc/conf.d/ntp-client to use the ip and rebooted:

```
cat ntp-client 

# /etc/conf.d/ntp-client

# Command to run to set the clock initially

# Most people should just leave this line alone ...

# however, if you know what you're doing, and you

# want to use ntpd to set the clock, change this to 'ntpd'

#NTPCLIENT_CMD="ntpdate"

NTPCLIENT_CMD="sntp"

# Options to pass to the above command

# This default setting should work fine but you should

# change the default 'pool.ntp.org' to something closer

# to your machine.  See http://www.pool.ntp.org/ or

# try running `netselect -s 3 pool.ntp.org`.

#NTPCLIENT_OPTS="-s -b -u \

#   0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org \

#   2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"

#NTPCLIENT_OPTS="-p -s \

#   0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org \

#   2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org"

# NOTE: Based on the double talk here:

# http://bugs.ntp.org/show_bug.cgi?id=2233

# There's supposed to be a wait timeout in some version (-g?) but for now, it appears to

# wait for 5 times the -t timeout, which means a default of 5:40!...so I'm usig -t 5.

#NTPCLIENT_OPTS="-p -t 5 -s mythback"

NTPCLIENT_OPTS="-p -t 5 -s 192.168.1.51"

```

...and that did in fact work after I made that change.  However I rebooted earlier today after installing a new kernel, and it failed again, so the behavior is clearly random.  This is from my /etc/var/rc.log:

```
* Setting clock via the NTP client 'sntp' ...

16 Jul 09:44:22 sntp[1008]: Started sntp

 * Failed to set clock

 [ !! ]

```

Again, that exact command works manually every time with either the ip or name:

```
mythfront ~ # sntp -p -t 5 -s 192.168.1.51

16 Jul 16:28:16 sntp[2317]: Started sntp

2014-07-16 16:28:16.817586 (+0500) +0.000371 +/- 0.036148 secs

mythfront ~ # sntp -p -t 5 -s mythback

16 Jul 16:28:29 sntp[2318]: Started sntp

2014-07-16 16:28:29.188293 (+0500) +0.000018 +/- 0.036331 secs

```

Both of those result in a status ($?) of 0.

I have to say that, in many ways, that sntp replacement for ntpdate has been a complete mess.  Aside from whatever is going on here, I've found it to be poorly or even incorrectly documented...just a mess from the word go frankly.

Tom

----------

## tld

Yea...just had a chance to reboot it again, with absolutely nothing different since this mornings reboot when it failed and this time it worked.  Like I said, it seems totally random when run from the service, and works without fail manually.  Craziness.

```
 * Setting clock via the NTP client 'sntp' ...

16 Jul 16:49:22 sntp[1009]: Started sntp

2014-07-16 16:49:24.694737 (+0500) +1.061825 +/- 0.055161 secs

 [ ok ]

```

EDIT: Also, I know for a fact that the network is working at that point because I have NFS mounts (on the same machine!...mythback) that mount flawlessly before that.

Tom

----------

