Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a particular service (in this case OpenFire) that runs at startup. When it starts, it attempts to connect to a database at a given hostname. At startup time it fails to connect to that database because it cannot find the host in DNS.

My best guess is that this service is executing on startup before networking has initialized and DNS servers have been obtained from DHCP. Is there any way to specify startup service dependencies that must be met before executing the /etc/init.d/ script?

share|improve this question
This is a possible duplicate of How to run cron job when network is up – Marco Ceppi Sep 8 '10 at 14:20
I don't think it is. The question is about a cron job that is executed based on a timer, and should only continue if the network is up. This is about a command that is executed immediately after the network is up. – Ralf Sep 10 '10 at 15:43
Dont think its a duplicate either, though it is closely related. – LassePoulsen Sep 10 '10 at 17:10
up vote 1 down vote accepted

You could look in /etc/rc0.d for the service, it will have S##[name], ie - S35networking

So if you make it say S36openfire then it should load just after networking. Or make the number 99 and it will load last, giving the network time to do it's thing.

Hope that\ll do the trick for you.

share|improve this answer
Ubuntu uses Upstart. See the question linked to by Marco in the comment above. – Dennis Williamson Sep 8 '10 at 16:23
While Upstart would work, I already have an rc0 script established for my service. It was K20, while networking was S35. I changed it to K36, which should do the trick. Thanks for pointing me in the right direction. – roktechie Sep 10 '10 at 17:33
roktechie, K's are for stopping, and rc0 is for shutdown. What you want is to have the symlink in /etc/rc2.d with a number greater than 35. Still you're dealing with a race condition if you have a dynamic IP because networking's startup returns as soon as dhcp has started, not as soon as the IP is assigned. – SpamapS Dec 11 '10 at 2:30

Forget about upstart. There are much easier ways to do this. Put a script that launches Openfire here:


If openfire has to run as your user, so something like:

su -c "openfire" myUserName

Make sure you mark it as executable:

sudo chmod +x /etc/network/if-up.d/openfire

Likewise you can close openfire, when you loose your network connection, by putting a script in /etc/network/if-down.d/ that kills it:

killall openfire
share|improve this answer
Ralf, this doesn't offer ongoing administration of the service, whereas an upstart job would. However, if there's no desire to replace the init.d script, then just replace the 'su -c "openfire" .. with "service openfire start" and the killall with "service openfire stop" – SpamapS Dec 11 '10 at 2:34

if you don't configure your network using NetworkManager, you can try to configure your upstart conf to depend on networking:

start on starting networking


start on starting network-interface

I don't know how it interacts with NetworkingManager, perhaps NM triggers some events which are detectable through upstart.

share|improve this answer
This will cause openfire to be started before networking. I think you mean't start on started networking. This would still be a problem, because networking is started as soon as dhcp client is started. What you want is 'start on net-device-up IFACE!=lo' which will only fire when a non loopback device is brought up. – SpamapS Dec 11 '10 at 2:27
Thanks @SpamapS. Do you know if net-device-up will be fired when the interface is actually assigned an IP address or only brought up? – ithkuil Dec 11 '10 at 15:19
For googlers, I believe what you're looking for is start on started networking – Andrew Dunkman Jun 1 '12 at 16:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.