Although the preface was original, after all, I studied the startup of ubuntu for two whole days. During the study, I watched the Linux private house dish of laruence and studied/etc/init. d/Shell Source Code, etc., but it is undeniable that I have read a lot of articles in China and abroad, and the final solution is based on a good blog article. Here I will first make recommendations: manage Ubuntu boot through update-rc.d next, I will record some of my own gains (testing environment ubuntu10.04 & ubuntu12.04) Ubuntu system run level
- 0 system shutdown status
- 1. maintenance status of a single user or System
- 2 ~ 5 Users
- 6. Restart
Update-rc.d overview Linux services can be started, stopped and reload with the use of scripts stocked (store) in/Etc/init. d/. However, during start up or when changing runlevel, those scripts are searched in/etc/rcX. d/where X is the runlever number (you can use the runlevel command to view the default runlevel of the system ).
This tutorial will explain how one can activate (activation), disactivate or modifu 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:
sudo /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 is will take care of removing/adding any required links to/etc/init. d automatically. taking
Apache2 as an example. as you can see, for runlevels 0, 1 and 6 There Is a k at the ining of the link, for runlevels 2, 3, 4 and 5, there is a S. those two letters stands for kill and start. removing a serviceif 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 a simple:
update-rc.d [-f] servicename remove
Option-F force removal of symlinks even If/etc/init. d/name still exists. (equivalent to/etc/init. the Apache script still exists in D/, but/etc/rcX. d/all the soft links about apache2 are deleted.) adding a servicedefault prioritiesnow, if you want to re-add your service to be started on boot up, you can simply use: specifying custom runlevelsfinally, if you want to start and kill on specific runlevels, like for instances starting writelog with priority 90 on runlevels 2, 3, 4, 5 and kill with priority 91 on runlevels 0, 1 and 6, you can follows this operation: One of my init. d. STARTUP script example
wangzhengyi@cloud-1:/etc/init.d$ cat writelog #!/bin/sh### BEGIN INIT INFO# Provides: wzy# Required-Start: $remote_fs $syslog# Required-Stop: $remote_fs $syslog# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: test update-rc.d to start a service### END INIT INFPATH="/sbin:/usr/sbin:/bin:/usr/bin"DESC="write log daemon"SCRIPTNAME="/home/wangzhengyi/scripts/ceshi.sh"export PATH=$PATH. /lib/lsb/init-functionsdo_start() {log_begin_msg "Runing wzy writeing log scripts $SCRIPTNAME"if [ -x $SCRIPTNAME ]; then$SCRIPTNAMEES=$?filog_end_msg $ES}case "$1" in start)do_start;;restart|reload|force-reload|staus)echo "Error: argument '$1' not supported" >&2 exit 3;;stop);;*) echo "Usage: $0 start|stop" >&2 exit 3 ;;esacexit 0
RC. local preferred. Check RC. the local file running permission and running level can be seen, RC. local runs at runlevel 2, 3, 4, 5, and has a running priority of 99, which is the lowest priority. Therefore, we can add the script to be started to RC. go to local
Wangzhengyi @ cloud-1 :~ $ CAT/etc/rc. Local #! /Bin/sh-e # RC. local ## this script is executed at the end of each multiuser runlevel. # Make sure that the script will "Exit 0" on success or any other # value on error. # In order to enable or disable this script just change the execution # bits. # By default this script does nothing. # Run the test script if [-x/home/wangzhengyi/scripts/Ceshi. sh]; then/home/wangzhengyi/scripts/Ceshi. shfiexit 0
Note boot is nothing more than these two methods, I recommend the first update-rc.d management, because this is more flexible, and can solve the relevant dependencies, this study for nearly two days, I have learned all the Linux boot process, and I hope it will be helpful to you!