Managing Automatic startup programs for Ubuntu systems through update-rc.d

Source: Internet
Author: User
Reprinted and noted down my usage experience. Linuxservicescanbestarted, stoppedandreloadedwiththeuseofscriptsstockedin/etc/init. d/. However, duringstartuporwhenchangingrunlevel, thosescriptsaresearchedin

Reprinted and noted down my usage experience.

Linux services can be started, stopped and reloaded with the use of scripts stocked in/etc/init. d /. however, during start up or when changing runlevel, those scripts are searched in/etc/rcX. d/where X is the runlevel number. this tutorial will explain how one can activate, deactivate or modify a service start up. 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:

/Etc/init. d/apache2 start

You coshould 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:

# Ls-l/etc/rc ?. D/* apache2
Lrwxrwxrwx 1 root 17/etc/rc0.d/K91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc1.d/K91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc2.d/S91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc3.d/S91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc4.d/S91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc5.d/S91apache2-> ../init. d/apache2
Lrwxrwxrwx 1 root 17/etc/rc6.d/K91apache2-> ../init. d/apache2

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 wowould need to delete every single link in/etc/rcX. d/. Using update-rc.d it is as simple:

Update-rc.d-f apache2 remove

The use of-f is to force the removal of the symlinks even if there is still/etc/init. d/apache2.

Note: This command will only disable the service until next time the service is upgraded. if you want to make sure the service won't be re-enabled upon upgrade, you shoshould also type the following:

# Update-rc.d apache2 stop 80 0 1 2 3 4 5 6.

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:

# 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 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:

# 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:

# 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.