Linux – Dependencies with /etc/init.d scripts

dependenciesredhat-enterprise-linux

I have a script that start a DB2 database server instance at boot time and another script that starts an application which has as dependency that DB2 database must be up.

In Solaris there was a way to create a dependency between two services, such that you could say: The application can only be started if DB2 is running.

Is there a way to create such a dependency in Redhat 6.5, other than waiting for a safe moment (sleep x) and then start the application ?

Best Answer

Use the Required-Start header field. Assuming the init script for DB2 is called db2server, add this line to the header section of the second script:

# Required-Start: db2server

Here's the LSB documentation you're looking for.

If you look at other scripts, you'll see a header section with these fields:

### BEGIN INIT INFO
# Provides: 
# Required-Start: 
# Required-Stop: 
# Should-Start: 
# Should-Stop: 
# Default-Start: 
# Default-Stop: 
# Short-Description: 
# Description: 
### END INIT INFO

The *-Start and *-Stop fields can take explicit names of other SysVInit scripts, or descriptive placeholders such as $local_fs, $remote_fs.

Note: I'm aware this question is roughly 18 months old, but the other answer was pretty much just a set of links without explanation.

Related Question