When installing a new service under debian, the default is to enable it. So for instance, if you just installed apache2 package, after you installed it, apache service will be started and so will it be upon the next reboots.
If you do not use apache all the time, you might want to disable this service from starting up upon boot up and simply start it manually when you actually need it by running this command:
1 |
# /etc/init.d/apache2 start |
You could either disable this service on boot up by removing any symbolic links in /etc/rcX.d/SYYapache2 or by using update-rc.d.
The advantage of using update-rc.d is that it will take care of removing/adding any required links to /etc/init.d automatically.
Taking apache2 as an example, let’s examine how /etc/rcX.d is looking like:
1 2 3 4 5 6 7 8 |
# ls -l /etc/rc?.d/*apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc0.d/K91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc1.d/K91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc2.d/S91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc3.d/S91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc4.d/S91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc5.d/S91apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc6.d/K91apache2 -> ../init.d/apache |
As you can see, for runlevels 0, 1 and 6 there is a K at the beginning of the link, for runlevels 2, 3, 4 and 5, there is a S. Those two letters stands for Kill and Start.
On Debian and Ubuntu, runlevels 2, 3, 4 and 5 are multi-users runlevels.
Runlevel 0 is Halt.
Runlevel 1 is single user mode
Runlevel 6 is reboot
1. Removing A Service
If you want to totally disable apache2 service by hand, you would need to delete every single link in /etc/rcX.d/. Using update-rc.d it is as simple as:
1 |
# update-rc.d -f apache2 remove |
2. Adding A Service
2.1. Default Priorities
Now, if you want to re-add this service to be started on boot up, you can simply use:
1 2 3 4 5 6 7 8 9 |
# update-rc.d apache2 defaults Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K20apache2 -> ../init.d/apache2 /etc/rc1.d/K20apache2 -> ../init.d/apache2 /etc/rc6.d/K20apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S20apache2 -> ../init.d/apache2 |
2.2. Custom Priorities
But as you can see, the default value is 20 which is pretty different than 91 … a S20 link is started before a S91 and and K91 is kill before K20.
To force apache2 to be started with priorities 91 for both Start and Kill, we need to use the following command:
1 2 3 4 5 6 7 8 9 |
# update-rc.d apache2 defaults 91 Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K91apache2 -> ../init.d/apache2 /etc/rc1.d/K91apache2 -> ../init.d/apache2 /etc/rc6.d/K91apache2 -> ../init.d/apache2 /etc/rc2.d/S91apache2 -> ../init.d/apache2 /etc/rc3.d/S91apache2 -> ../init.d/apache2 /etc/rc4.d/S91apache2 -> ../init.d/apache2 /etc/rc5.d/S91apache2 -> ../init.d/apache2 |
2.3. Different Priorities For Start And Kill
Alternatively, if you want to set different priorities for Start than for Kill, let say Start with 20 and Kill with 80, you will need to run:
1 2 3 4 5 6 7 8 9 |
# update-rc.d apache2 defaults 20 80 Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K80apache2 -> ../init.d/apache2 /etc/rc1.d/K80apache2 -> ../init.d/apache2 /etc/rc6.d/K80apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S20apache2 -> ../init.d/apache2 |
3. Specifying Custom Runlevels
Finally, if you only want to Start and Kill on specific runlevels, like for instance starting apache with priority 20 on runlevels 2, 3, 4 and 5 and Kill with priority 80 on runlevels 0, 1 and 6:
1 2 3 4 5 6 7 8 9 |
# update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 . Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K80apache2 -> ../init.d/apache2 /etc/rc1.d/K80apache2 -> ../init.d/apache2 /etc/rc6.d/K80apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S20apache2 -> ../init.d/apache2 |
Or, to start with priority 20 for runlevel 2, 3 and 4 and priority 30 for runlevel 5 and kill with priority 80 for runlevel 0, 1 and 6:
1 2 3 4 5 6 7 8 9 |
# update-rc.d apache2 start 20 2 3 4 . start 30 5 . stop 80 0 1 6 . Adding system startup for /etc/init.d/apache2 ... /etc/rc0.d/K80apache2 -> ../init.d/apache2 /etc/rc1.d/K80apache2 -> ../init.d/apache2 /etc/rc6.d/K80apache2 -> ../init.d/apache2 /etc/rc2.d/S20apache2 -> ../init.d/apache2 /etc/rc3.d/S20apache2 -> ../init.d/apache2 /etc/rc4.d/S20apache2 -> ../init.d/apache2 /etc/rc5.d/S30apache2 -> ../init.d/apache2 |
Comment Policy:
Your words are your own, so be nice and helpful if you can. Please, only use your real name, not your business name or keywords. Using business name or keywords instead of your real name will lead to the comment being deleted. Anonymous commenting is not allowed either. Limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please.