Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ntp-client after establishing wlan? [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Tue Nov 16, 2010 9:51 pm    Post subject: ntp-client after establishing wlan? [solved] Reply with quote

Hi

How could I start ntp-client after the wireless connection is established successfully? I'm using wicd and the connection needs up to 20s after start of wicd. When ntp-client is started during that time, it failed.

I'm using baselayout 2 and /etc/init.d/ntp-client looks like this:
Code:
depend() {
        before cron portmap
        need net
        use dns logger
}

checkconfig() {
        if ! type "${NTPCLIENT_CMD}" >/dev/null 2>/dev/null ; then
                eerror "Please edit /etc/conf.d/ntp-client"
                eerror "Unable to locate the client command ${NTPCLIENT_CMD}!"
                return 1
        fi
        if [ -z "${NTPCLIENT_OPTS}" ] ; then
                eerror "Please edit /etc/conf.d/ntp-client"
                eerror "I need to know what server/options to use!"
                return 1
        fi
        return 0
}

start() {
        checkconfig || return $?

        ebegin "Setting clock via the NTP client '${NTPCLIENT_CMD}'"
        "${NTPCLIENT_CMD}" ${NTPCLIENT_OPTS}
        eend $? "Failed to set clock"
}

rc_depend_strict is set to "NO"


Last edited by samo on Thu Nov 25, 2010 9:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2593
Location: userland

PostPosted: Wed Nov 17, 2010 1:34 am    Post subject: Reply with quote

You could try to set the timeout for ntp-client to 120s or some similar big value (probably with an environment variable in /etc/conf.d/ntp-client), or you could change 'need net' to 'need net.wlan0' (not sure if that will work though), or you could try setting rc_depend_strict=YES. If the first solution works, do it this way.
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Wed Nov 17, 2010 10:44 pm    Post subject: Reply with quote

I've defined a timeout value.
Code:
# /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"

# 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_TIMEOUT=300

And I've changed /etc/init.d/ntp-client.
Code:
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/ntp/files/ntp-client.rc,v 1.11 200$

depend() {
        before cron portmap
#       need net
        need net.wlan0
        use dns logger
}

checkconfig() {
        if ! type "${NTPCLIENT_CMD}" >/dev/null 2>/dev/null ; then
                eerror "Please edit /etc/conf.d/ntp-client"
                eerror "Unable to locate the client command ${NTPCLIENT_CMD}!"
                return 1
        fi
        if [ -z "${NTPCLIENT_OPTS}" ] ; then
                eerror "Please edit /etc/conf.d/ntp-client"
                eerror "I need to know what server/options to use!"
                return 1
        fi
        return 0
}

start() {
        checkconfig || return $?

        ebegin "Setting clock via the NTP client '${NTPCLIENT_CMD}'"
        "${NTPCLIENT_CMD}" ${NTPCLIENT_OPTS}
        eend $? "Failed to set clock"
}

I've also set rc_depend_strict="YES"
But it didn't solve the problem.
Code:
rc boot logging started at Wed Nov 17 23:21:28 2010

hwclock         | * Setting system clock using the hardware clock [UTC] ...
 [ ok ]
modules         | * Loading module nvidia-agp ...
hostname        | * Setting hostname to gentoo ...
termencoding    | * Setting terminal encoding [UTF-8] ...
 [ ok ]
 [ ok ]
 [ ok ]
modules         | * Autoloaded 1 module(s)
sysctl          | * Configuring kernel parameters ...
 [ ok ]
fsck            | * Checking local filesystems  ...
fsck            |Reiserfs super block in block 16 on 0x803 of format 3.6 with standard journal
fsck            |Blocks (total/free): 5243200/215483 by 4096 bytes
fsck            |Filesystem is clean
fsck            |/dev/hd/samsung_hd1: sauber, 99/12048 Dateien, 45484/48160 Blöcke
 [ ok ]
root            | * Remounting root filesystem read/write ...
 [ ok ]
mtab            | * Updating /etc/mtab ...
 [ ok ]
localmount      | * Mounting local filesystems ...
 [ ok ]
swap            | * Activating swap devices ...
urandom         | * Initializing random number generator ...
 [ ok ]
 [ ok ]
bootmisc        | * Creating user login records ...
 [ ok ]
bootmisc        | * Cleaning /var/run ...
 [ ok ]
bootmisc        | * Wiping /tmp directory ...
 [ ok ]
dbus            | * Starting D-BUS system messagebus ...
keymaps         | * Setting keyboard mode [UTF-8] ...
consolefont     | * Setting console font [lat9w-16] ...
net.lo          | * Bringing up interface lo
alsasound       | * Loading ALSA modules ...
 [ ok ]
keymaps         | * Loading key mappings [de-latin1-nodeadkeys] ...
 [ ok ]
alsasound       | *   Loading: snd-card-0 ...
 [ ok ]
alsasound       | *   Loading: snd-card-0 ...
 [ ok ]
alsasound       | *   Loading: snd-seq-oss ...
 [ ok ]
alsasound       | *   Loading: snd-pcm-oss ...
 [ ok ]
 [ ok ]
alsasound       | * Restoring Mixer Levels ...
 [ ok ]
 [ ok ]
wicd            | * Starting wicd daemon ...
 [ ok ]
net.lo          | *   127.0.0.1/8 ...
 [ ok ]
net.lo          | *   Adding routes
net.lo          | *     127.0.0.0/8 via 127.0.0.1 ...
 [ ok ]
 [ ok ]

rc boot logging stopped at Wed Nov 17 23:21:34 2010


rc default logging started at Wed Nov 17 23:21:35 2010

xinetd          | * Starting xinetd ...
net.wlan0       | * Bringing up interface wlan0
netmount        | * Mounting network filesystems ...
 [ ok ]
mysql           | * Starting  ...
 [ ok ]
syslog-ng       | * Starting syslog-ng ...
 [ ok ]
mysql           | * Starting  (/etc/mysql/my.cnf)
cupsd           | * Starting cupsd ...
consolekit      | * Starting ConsoleKit daemon ...
net.wlan0       | *   Starting wpa_supplicant on wlan0 ...
 [ ok ]
ntp-client      | * WARNING: ntp-client is scheduled to start when net.wlan0 has started
net.wlan0       | *   Starting wpa_cli on wlan0 ...
vixie-cron      | * Starting vixie-cron ...
 [ ok ]
net.wlan0       | *   Backgrounding ... ...
net.wlan0       | * WARNING: net.wlan0 has started, but is inactive
 [ ok ]
 [ ok ]
hald            | * Starting Hardware Abstraction Layer daemon ...
sshd            | * Starting sshd ...
 [ ok ]
 [ ok ]
 [ ok ]
mythbackend     | * Starting MythTV Backend ...
 [ ok ]
 [ ok ]
xdm             | * Setting up kdm ...
 [ ok ]
apache2         | * Starting apache2 ...
 [ ok ]
local           | * Starting local ...
 [ ok ]

rc default logging stopped at Wed Nov 17 23:21:45 2010

/var/log/messages.log notifies this:
Code:
Nov 17 23:21:37 gentoo /etc/init.d/ntp-client[5691]: WARNING: ntp-client is scheduled to start when net.wlan0 has started
Nov 17 23:21:44 gentoo ntpdate[6338]: step time server 64.73.32.135 offset -1.682606 sec
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2593
Location: userland

PostPosted: Wed Nov 17, 2010 10:50 pm    Post subject: Reply with quote

Does your net.wlan0 interface try to auto-connect with some wireless network, or do you use network-manager or wpa_gui for choosing a connection?
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Wed Nov 17, 2010 11:01 pm    Post subject: Reply with quote

I'm using wicd with reconnect option. The connection is established automatically at start up.

I wonder, why there is now error message in /var/log/message.

Maybe a stupid question, but how can I check, if ntp-client is running or not? When I try to stop the script, I get a message, that it's already stopped.


Last edited by samo on Wed Nov 17, 2010 11:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2593
Location: userland

PostPosted: Wed Nov 17, 2010 11:06 pm    Post subject: Reply with quote

samo wrote:
I'm using wicd with reconnect option. The connection is established automatically at start up.

I wonder, why there is now error message in /var/log/message.

Maybe a silly question, but how can I check, if ntp-client is running or not? When I try to stop the script, I get a message, that it's already stopped.


You can check with
Code:
/etc/init.d/ntp-client status

But since your error log says that ntp-client will be started as soon as net.wlan0 is started, it seems that the service net.wlan0 itself does never 'start', even though your interface is up (you get a connection to the internet, right?). What does
Code:
/etc/init.d/net.wlan0 status

say once you have internet connection?
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Wed Nov 17, 2010 11:18 pm    Post subject: Reply with quote

Code:
# /etc/init.d/net.wlan0 status
 * status: inactive
# /etc/init.d/ntp-client status
 * status: stopped

Any idea?

I've configured wicd as described in Wiki
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2593
Location: userland

PostPosted: Wed Nov 17, 2010 11:39 pm    Post subject: Reply with quote

So the problem seems to be that net.wlan0 stays inactive, even though it should reach 'started' stage. When you set RC_DEPEND_STRICT=NO _and_ go back to 'need net', but leave the long timeout, does it work then?
How does wicd work, by the way? Will it connect automatically at startup, or once when you log in to your desktop environment?
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Thu Nov 18, 2010 6:31 am    Post subject: Reply with quote

Quote:
When you set RC_DEPEND_STRICT=NO _and_ go back to 'need net', but leave the long timeout, does it work then?

With these settings I get the following error:
Code:
rc boot logging started at Thu Nov 18 07:13:44 2010

hwclock         | * Setting system clock using the hardware clock [UTC] ...
 [ ok ]
termencoding    | * Setting terminal encoding [UTF-8] ...
hostname        | * Setting hostname to gentoo ...
 [ ok ]
modules         | * Loading module nvidia-agp ...
 [ ok ]
 [ ok ]
modules         | * Autoloaded 1 module(s)
sysctl          | * Configuring kernel parameters ...
 [ ok ]
fsck            | * Checking local filesystems  ...
fsck            |Reiserfs super block in block 16 on 0x803 of format 3.6 with standard journal
fsck            |Blocks (total/free): 5243200/214742 by 4096 bytes
fsck            |Filesystem is clean
fsck            |/dev/hd/samsung_hd1: sauber, 99/12048 Dateien, 45484/48160 Blöcke
 [ ok ]
root            | * Remounting root filesystem read/write ...
 [ ok ]
mtab            | * Updating /etc/mtab ...
 [ ok ]
localmount      | * Mounting local filesystems ...
 [ ok ]
swap            | * Activating swap devices ...
urandom         | * Initializing random number generator ...
 [ ok ]
 [ ok ]
bootmisc        | * Creating user login records ...
 [ ok ]
bootmisc        | * Cleaning /var/run ...
 [ ok ]
bootmisc        | * Wiping /tmp directory ...
 [ ok ]
dbus            | * Starting D-BUS system messagebus ...
consolefont     | * Setting console font [lat9w-16] ...
keymaps         | * Setting keyboard mode [UTF-8] ...
alsasound       | * Loading ALSA modules ...
net.lo          | * Bringing up interface lo
 [ ok ]
keymaps         | * Loading key mappings [de-latin1-nodeadkeys] ...
alsasound       | *   Loading: snd-card-0 ...
 [ ok ]
alsasound       | *   Loading: snd-card-0 ...
 [ ok ]
alsasound       | *   Loading: snd-seq-oss ...
 [ ok ]
alsasound       | *   Loading: snd-pcm-oss ...
 [ ok ]
 [ ok ]
 [ ok ]
alsasound       | * Restoring Mixer Levels ...
 [ ok ]
 [ ok ]
wicd            | * Starting wicd daemon ...
 [ ok ]
net.lo          | *   127.0.0.1/8 ...
 [ ok ]
net.lo          | *   Adding routes
net.lo          | *     127.0.0.0/8 via 127.0.0.1 ...
 [ ok ]
 [ ok ]

rc boot logging stopped at Thu Nov 18 07:13:50 2010


rc default logging started at Thu Nov 18 07:13:51 2010

xinetd          | * Starting xinetd ...
netmount        | * Mounting network filesystems ...
 [ ok ]
mysql           | * Starting  ...
 [ ok ]
syslog-ng       | * Starting syslog-ng ...
 [ ok ]
cupsd           | * Starting cupsd ...
consolekit      | * Starting ConsoleKit daemon ...
ntp-client      | * Setting clock via the NTP client 'ntpdate' ...
ntp-client      | * Failed to set clock
 [ !! ]
ntp-client      | * ERROR: ntp-client failed to start
vixie-cron      | * Starting vixie-cron ...
mysql           | * Starting  (/etc/mysql/my.cnf)
 [ ok ]
 [ ok ]
hald            | * Starting Hardware Abstraction Layer daemon ...
sshd            | * Starting sshd ...
 [ ok ]
 [ ok ]
 [ ok ]
mythbackend     | * Starting MythTV Backend ...
 [ ok ]
 [ ok ]
xdm             | * Setting up kdm ...
 [ ok ]
apache2         | * Starting apache2 ...
 [ ok ]
local           | * Starting local ...
 [ ok ]

rc default logging stopped at Thu Nov 18 07:14:03 2010

I don't know how wicd works in detail, but it seems like net.wlan0 are not used. I have disabled net.eth0 and net.wlan0 as described in the Wiki
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2593
Location: userland

PostPosted: Thu Nov 18, 2010 6:47 am    Post subject: Reply with quote

Code:
ntp-client      | * Failed to set clock

Ok, so this is the problem (and probably was from the beginning, this is why you should read your logs carefully, and post the relevant error messages). No idea why this happens. Is there anything in /var/log/messages about this?
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Thu Nov 18, 2010 8:06 pm    Post subject: Reply with quote

/var/log/messages contains following infos:
Code:
Nov 18 20:11:40 gentoo ntpdate[5803]: no servers can be used, exiting
Nov 18 20:11:40 gentoo /etc/init.d/ntp-client[5691]: ERROR: ntp-client failed to start

But when I start ntp-client manually after wireless connection is established everything looks fine.
Code:
# /etc/init.d/ntp-client start
ntp-client      | * Setting clock via the NTP client 'ntpdate' ...                                          [ ok ]
Code:
# /etc/init.d/ntp-client status
 * status: started
And /var/log/messages contains
Code:
Nov 18 21:02:36 gentoo ntpdate[9461]: step time server 169.229.70.95 offset -2.054481 sec
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Sat Nov 20, 2010 10:59 am    Post subject: Reply with quote

For me it seems to be a timeout problem. Does someone know how to fix?
Back to top
View user's profile Send private message
samo
Guru
Guru


Joined: 13 Mar 2004
Posts: 489

PostPosted: Thu Nov 25, 2010 9:38 pm    Post subject: Reply with quote

I have found a solution. wicd provides the possibility to execute some scripts after connection is established. I've written the following script:
Code:
$ cat /etc/wicd/scripts/postconnect/connect
#!/bin/bash
/etc/init.d/ntp-client start
/etc/init.d/nfs start
/etc/init.d/samba start
exit

For shutdown I use the following script:
Code:
$ cat /etc/wicd/scripts/predisconnect/disconnect
#!/bin/bash
/etc/init.d/ntp-client start
/etc/init.d/nfs start
/etc/init.d/samba start
exit
Back to top
View user's profile Send private message
greyspoke
Apprentice
Apprentice


Joined: 08 Jan 2010
Posts: 171

PostPosted: Sat Dec 04, 2010 3:44 pm    Post subject: Another couple of solutions Reply with quote

For the benefit of peeps who might be searching for answers like I was when I found this thread:

Another solution is to add lines to the server bit of your /etc/ntp.conf like the last two here:
Code:
server   0.uk.pool.ntp.org    iburst
server   1.uk.pool.ntp.org    iburst
server   2.uk.pool.ntp.org    iburst
server   3.uk.pool.ntp.org    iburst
server   127.127.1.0
fudge    127.127.1.0          stratum 10

The Gentoo ntp wiki doesn't deal with this but I found it elsewhere on the internet like here - it means that if ntp can't find a time server on the internet (like when net.wlan0 is still sorting out its DHCP stuff) it will use the local clock and not get flustered, but use proper time servers when they become available. With this you can have ntpd in your runlevels with no probs.

Before I found that I found a similar solution to your's samo, only for wpa_supplicant users like me. In /etc/conf.d/net you can add pre- and post- up or down functions as described in /usr/share/doc/openrc-0.6.3/net.example (if using baselayout 2). Here's one that worked for me, remove ntpd from your runlevels and add this to /etc/conf.d/net:
Code:
postup() {
   if [ ${IFVAR} != "lo" ]; then
# (long wait if you do this with net.lo)
      /etc/init.d/ntpd start
   fi
}

In theory the first solution might be better because it will cope with losing and regaining your internet connection without complaining.

ETA: I realise this is with ntpd, but I encountered similar problems trying to use ntp-client
Back to top
View user's profile Send private message
mimosinnet
l33t
l33t


Joined: 10 Aug 2006
Posts: 713
Location: Barcelona, Spain

PostPosted: Thu Jan 13, 2011 7:16 pm    Post subject: Reply with quote

samo wrote:
I have found a solution. wicd provides the possibility to execute some scripts after connection is established.


Nice solution if you are using wicd! I see you have been struggling with it for a while (in this thread and this other thread). Thanks very much for the solution. It has been very helpful for me and I have pointed at your solution in the gentoo wiki.

Cheers!
Back to top
View user's profile Send private message
Tolstoi
l33t
l33t


Joined: 20 May 2004
Posts: 678

PostPosted: Tue Sep 11, 2012 4:01 pm    Post subject: Reply with quote

samo wrote:
I have found a solution. wicd provides the possibility to execute some scripts after connection is established. I've written the following script:
Code:
$ cat /etc/wicd/scripts/postconnect/connect
#!/bin/bash
/etc/init.d/ntp-client start
/etc/init.d/nfs start
/etc/init.d/samba start
exit

For shutdown I use the following script:
Code:
$ cat /etc/wicd/scripts/predisconnect/disconnect
#!/bin/bash
/etc/init.d/ntp-client start
/etc/init.d/nfs start
/etc/init.d/samba start
exit


Thanks for the tip.

Shouldn't it be "stop" in the disconnect script ?
Back to top
View user's profile Send private message
gen2thomas
n00b
n00b


Joined: 09 May 2011
Posts: 2

PostPosted: Tue Nov 15, 2016 7:30 pm    Post subject: Reply with quote

Tolstoi wrote:

Shouldn't it be "stop" in the disconnect script ?


Right, also in my opinion it should be "stop" in the disconnect script and don't forget to set the executable flag for both scripts:
Code:

chmod u+x /etc/wicd/scripts/postconnect/connect
chmod u+x /etc/wicd/scripts/predisconnect/disconnect


And again: Thank you for the tip!
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
Page 1 of 1

 
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