As the question is clear from the title, how do I change Linux services startup/boot order?
4 Answers
Instead of doing it manually, like suggested in the other answers, you could also change the init script. Just add such a line to the header:
# chkconfig: 35 90 10
This will instruct chkconfig
to add the service to the runlevels 3 and 5, with a start position of 90 and a kill position of 10.
![](../../users/profiles/29879.webp)
- 4,645
- 2
- 23
- 27
-
This. Absolutely this. If you manually rename the symlinks you'll get a surprise if someone comes along and runs `chkconfig off servicename && chkconfig on servicename` – batfastad Nov 25 '16 at 11:02
-
Worked like a charm. I needed to configure dependencies between mysqld and a servlet container. I couldn't figure out the start position of mysqld, so I configured the servlet container's start position to 99 and it works just fine, mysqld gets started first. Thanks. – jpangamarca Jun 16 '17 at 23:22
You can change the order by renaming the symlinks under /etc/rcX.d/ where x will be your run level.
You'll see a bunch of files starting with Sxx or Kxx. S links are traced during startup while the K ones are parsed for shutdown. The xx here represents the order.
But this order is set for a reason, so be careful while changing them.for example. ntpd should start only after the networking subsystem is initialized.
![](../../users/profiles/52825.webp)
- 328
- 1
- 2
- 6
You want to read a little about your runlevels and rc.d directories. Inside the rc.d directories you can find the S and K links, like S20apache K10apache, that is basically what orders startup/shutdown of scripts.
There are some changes being made on this architecture but most of the linuxes are still using it.
-
I'm amazed most distros still use this system; better systems like `rcorder` have been around for a while. – Chris S Aug 30 '10 at 12:42
-
-
This is spot on. Depending on your distro, however, you may have different ways of altering this value--so read up on the specific documentation for your distro. – Andrew M. Aug 30 '10 at 12:53
-
1Some distributions, such as Ubuntu, use [Upstart](http://upstart.ubuntu.com/) ( [Wikipedia](http://en.wikipedia.org/wiki/Upstart) ). – Dennis Williamson Aug 30 '10 at 14:03
If you've arrived here, chances are you have two services where one depends upon the other but, because they're starting in the wrong order, the one with the dependency is failing to start. Suggestions about editing the symlinks are informative, in terms of illustrating how the startup sequence runs, and would work alright until someone did a "chkconfig on" on your service at which point the symlinks would be re-created as they were originally. Really, you want to deal with the issue at the init script level, which is actually much less messy to do anyway. It will also be consistent across the different runlevels. You probably won't need to add a "# chkconfig" line as suggested in answer 4 as there will likely be a similar line in there already.
I'll use an example of a server running Openldap (slapd) with a MySQL database backend (mysqld). Configuring that pair, and why you might want to, is a whole other story.
On boot, Openldap fails to start because it depends on MySQL and the startup sequence has it trying to start before it - slapd has position 27 and mysqld has position 64
The relevant symlinks in /etc/rc3.d/ are
S27slapd -> ../init.d/slapd
and
S64mysqld -> ../init.d/mysqld
I look for values set in the two init scripts:
[root ~]# grep chkconfig /etc/rc.d/init.d/mysqld
# chkconfig: - 64 36
[root ~]# grep chkconfig /etc/rc.d/init.d/slapd
# chkconfig: - 27 73
I edit the chkconfig line in /etc/rc.d/init.d/slapd to have a start position higher than the one in /etc/rc.d/init.d/mysqld (I chose 85)
[root ~]# grep chkconfig /etc/rc.d/init.d/slapd
# chkconfig: - 85 73
I do "chkconfig slapd on" and recheck the symlinks
[root ~]# chkconfig slapd on
[root ~]# ls -l /etc/rc3.d/ | grep mysqld
lrwxrwxrwx 1 root root 16 Dec 10 13:45 S64mysqld -> ../init.d/mysqld
[root ~]# ls -l /etc/rc3.d/ | grep slapd
lrwxrwxrwx 1 root root 15 Apr 28 14:18 S85slapd -> ../init.d/slapd
Now, when this server starts up, mysqld starts before slapd and all is right with the world.
![](../../users/profiles/351918.webp)
- 71
- 1
- 1