Auto-start service on bootup that depend on network

6,816

Solution 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.

Solution 2

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
Share:
6,816

Related videos on Youtube

roktechie
Author by

roktechie

Updated on September 17, 2022

Comments

  • roktechie
    roktechie over 1 year

    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?

  • Dennis Williamson
    Dennis Williamson over 13 years
    Ubuntu uses Upstart. See this related question.
  • roktechie
    roktechie over 13 years
    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.
  • SpamapS
    SpamapS over 13 years
    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
    SpamapS over 13 years
    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
    SpamapS over 13 years
    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"
  • uuu777
    uuu777 over 13 years
    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?
  • Andrew Dunkman
    Andrew Dunkman almost 12 years
    For googlers, I believe what you're looking for is start on started networking