6

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?

0

3 Answers 3

3

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

 /etc/network/if-up.d/

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

#!/bin/sh
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:

#!/bin/sh
killall openfire
1
  • 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, 2010 at 2:34
1

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

So if you make it say S36openfire then it should load just after networking. Or make the number 99 (instead of 36) and it will load last, giving the network time to do its thing.

Hope that'll do the trick for you.

3
  • Ubuntu uses Upstart. See this related question. Sep 8, 2010 at 16:23
  • 1
    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, 2010 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, 2010 at 2:30
-1

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

or

start on starting network-interface

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

3
  • 2
    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, 2010 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?
    – mkm
    Dec 11, 2010 at 15:19
  • 1
    For googlers, I believe what you're looking for is start on started networking Jun 1, 2012 at 16:23

You must log in to answer this question.

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