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

4 Answers 4


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.


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.


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.

  • I will see if such a file exists on my installation. Thanks.
    – RobS
    Nov 12, 2009 at 14:15
  • No such file in gentoo unfortunately.
    – RobS
    Nov 14, 2009 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?

  • In my gentoo there is no /etc/network
    – RobS
    Nov 12, 2009 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .