This question is about Debian, but I guess it's the same in many linux environments.
The /etc/init.d
directory defines the services that run at boot-time. As I see it, there are two mechanisms that define who runs and when:
- runlevel directories – The
/etc/rcN.d/
directories, in which there are symlinks to scripts ininit.d
with numbers that define the running order. These symlinks are generated from runningupdate-rc.d
. - insserv files –
.depend.start/stop/boot
files that are generated from the utilityinsserv
. In these files you see the running scripts underTARGETS
, and the order in which they appear is the running order (See this post)
So first question – Which of these decides the boot order?
In order to change the boot order I guess you can either edit the symlinks name in the rc.N
directories, or change the order of appearence in .depend.start
. But both of these changes will be overwritten by a call to insserv
or update-rc.d
.
So second question – How do you control the boot order init.d scripts in a way that will last after a call to insserv
or update-rc.d
?
Best Answer
With
sysvinit
(systemd is different, but you'd use units there, not initscripts), the boot order is determined during boot by the ordering of files in/etc/rc?.d
. The symlinks there are generated byupdate-rc.d
with the help ofinsserv
, which is really an implementation detail (as are the.depend.boot
etc. files). All you need to care about are the dependencies between initscripts, declared in their LSB headers; e.g.:If you want to change the boot order, you need to add dependencies to the relevant initscripts. The safest way to do that is to add overrides to
/etc/insserv/overrides
: create a new file there with the same name as the script you wish to override, and write the new header to that file. Then runupdate-rc.d yourscript defaults
to re-calculate the symlinks.You'll find more information in the manpages for
insserv
andupdate-rc.d
.