Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update-rc.d and init.d dependencies

Tags:

init.d

rc

boot

So I'm trying to write some init.d scripts satisfying LSB so they run appropriately at startup and shutdown. Unfortunately, I'm having issues with LSB/update-rc.d to satisfy dependencies.

# Required-Start: $network $local_fs hadoop-namenode hadoop-datanode zookeeper-server
# Required-Stop:  $network $local_fs hadoop-namenode hadoop-datanode zookeeper-server
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6

however, when I run update-rc.d defaults, it merely generates the defaults involved, with the exact same start time as the already dependencies, which breaks things horribly. Am I missing something with update-rc.d or LSB to get this configured?

In case it's relevant, this is Ubuntu 12.04

like image 515
ohshazbot Avatar asked Aug 22 '12 19:08

ohshazbot


People also ask

What does RC update mean?

DESCRIPTION. OpenRC uses named runlevels. Rather than editing some obscure file or managing a directory of symlinks, rc-update exists to quickly add or delete services to and from from different runlevels. All services must reside in the /etc/init.

What is RC D and init D?

To avoid script duplication the files in the rc#. d/ directories are actually symbolic links to script files located in the /etc/init. d/ directory. Custom scripts to carry out tasks on the system can be created in the /etc/init. d/ directory and then symbolic links to those scripts can be created in the /etc/rc#.


2 Answers

To make your script run later in the boot sequence, just add a sequence number, like 98 in the following command. Then most dependencies will be satisfied.

Once, I had to use a boot script which depended on other boot scripts. This brought a lot troubles. In the end I used this command to solve the problem:

cd /etc/init.d
sudo update-rc.d my_script defaults 98

The 98 means my_script gets sequence number 98 at boot, it looks like it's range from 1 to 99, and most other boot scripts have smaller numbers, this ensures my script has all its dependencies ready.

BTW, to remove the old script, this can be used:

sudo update-rc.d -f my_old_script remove
# -f means 'force'

Hope this helps.

like image 162
Andrew_1510 Avatar answered Sep 21 '22 08:09

Andrew_1510


This approach doesn't work anymore on some systems (Debian Squeeze for example). The number is just ignored with no explanation. The preferred method is this: http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html

Look at "Required-Start:" script declaration.

like image 31
davidhq Avatar answered Sep 25 '22 08:09

davidhq