Take the 2-minute tour ×

I have a headless media server using mpd running on gentoo. Mpd is configured to start at boot (and I don't have the rc scripts running in parallel either), but unfortunately mpd won't start if it can't bind to an interface. I've tried giving my wireless lan a static ip address but occasionally mpd won't start because the wlan card has not associated with the access point (I'm using wpa_supplicant).

Now when ssh starts it's quite happy to wait for the interface to come up. But even with a little digging I'm unable to find out quite how it does that.

My horrible hack would be for the mpd script just to wait for "sufficient" time for the wlan card to associate, but that won't work in all circumstances.

Anyone got any pointers?

NB: Related questions that don't answer my question (but might be useful to others are here):

run-a-script-when-connected-to-a-wireless-network-in-linux, and linux-how-to-start-skype-or-other-program-only-when-im-online

share|improve this question

4 Answers 4

up vote 2 down vote accepted

In gentoo startup scripts, ( /etc/init.d/mpd in your example ) there should be a

 depend() { ... }

section near the top. This is how init ends up determining the order for startup. You should put a requirement for network to finish before starting mpd there. I think the line is

 need net

Check to see what is in the depend section in /etc/init.d/sshd. The same line from that should probably work if you add it to the mpd startup script.

share|improve this answer
+1 Thanks, this looks like it could work. –  RobS Nov 14 '09 at 16:01

A general approach would be to try starting mpd in a loop, until it starts successfully. I believe mpd would normally throw a certain exit code (which you can catch in your startup script) when it was unable to start for certain reasons.

share|improve this answer

From /etc/wpa_supplicant/ifupdown.sh:

# This file is executed by ifupdown in pre-up, post-up, pre-down and
# post-down phases of network interface configuration. It allows
# ifup(8), and ifdown(8) to manage wpa_supplicant(8) and wpa_cli(8)
# processes running in daemon mode.

Around about line 144 (on my copy) of the script it seems to do it's post-up operations - you should be able to place your launch mpd here unless someone can think of a better place.

share|improve this answer
I will see if such a file exists on my installation. Thanks. –  RobS Nov 12 '09 at 14:15
No such file in gentoo unfortunately. –  RobS Nov 14 '09 at 16:02

One of the answers in the first link you gave suggests putting a script in /etc/network/if-up.d which is what I'd suggest to you. Have you tried that?

share|improve this answer
In my gentoo there is no /etc/network –  RobS Nov 12 '09 at 14:14

Your Answer


