Linux Setup boot up

Source: Internet
Author: User

Tips for knowledge

Run level
Simply put, the run level is the functional level that the operating system is currently running.

0 -1 -Single-user mode       12 -3 -4 -5 -6 -reboot (never set Initdefault to 6)

I. /etc/rc.local
(1) Execute the command: Edit "/etc/rc.local", add the command you want to run the boot

(2) Run the program script: Then add the full path of the program to execute on the last line of the file.

For example, each time you turn on a hello.sh, the script is placed under/usr, you can add a line "/usr/./hello.sh" in "/etc/rc.local", or "cd/opt &&/hello.sh"

Two./etc/init.d

When Linux is powered on, it does not run all the scripts under/ETC/INIT.D directly, but instead executes the scripts under/ETC/RC$RUNLEVEL.D according to different runlevel.

Here the runlevel is used to differentiate the system's operation (such as single-user runlevel, multimedia desktop runlevel, server runlevel are different).

(1) We first put the executable script under the/ETC/INIT.D

(2) Then create a symbolic connection
There are a few directories worth noting under/etc:

(0,1 ... 6 for Start Level 0 for stop, 1 for single user mode, 2-5 for multi-user mode, 6 for restart

Their role is equivalent to Redhat under the RC.D, we can put the script to RCS.D, and then modify the file name, give it a boot sequence number, such as: S88mysql.

However, the best way to do this is to put it under the appropriate boot level, specifically:
Put MySQL in the/ETC/INIT.D directory first.
View the current system's startup level $ sudo runlevel
Set startup level $ UPDATE-RC.D MySQL start 98 2.
(98 is the start sequence number, 2 is the system's operating level, can adjust itself, note do not forget the end of the period)

Now we go to the/etc/rc2.d, there is a s98mysql such a symbolic link.

Soft Links:

S is the shorthand of start, the representative starts;
K is the shorthand for kill, the representative closes;
60 numbers represent the order in which they are started. After 60 is usually the more insured number, since other services were started;

Recommended reference:

Http://www.cnblogs.com/wangkangluo1/archive/2012/04/20/2459036.html

Http://blog.chinaunix.net/uid-26000296-id-3986914.html

Http://www.cnblogs.com/gzggyy/archive/2012/08/07/2626574.html

In Ubuntu, you can use UPDATE-RC.D to install/etc/init.d/proxy into various runlevel.[email protected]:~# UPDATE-RC.D Proxy Defaults AboutUpdate-rc.d:warning:/etc/init.d/proxy missing LSB informationupdate-rc.d:see //wiki.debian.org/lsbinitscripts>Adding system Startup for/etc/init.d/Proxy .../etc/rc0.d/k99proxy. /init.d/Proxy/etc/rc1.d/k99proxy. /init.d/Proxy/etc/rc6.d/k99proxy. /init.d/Proxy/etc/rc2.d/s99proxy. /init.d/Proxy/etc/rc3.d/s99proxy. /init.d/Proxy/etc/rc4.d/s99proxy. /init.d/Proxy/etc/rc5.d/s99proxy. /init.d/proxyupdate-RC.D is followed by three parameters, namely/etc/init.d The script name, default installation mode, run priority. The higher the number of priorities, the more late the operation, and here we put the service we wrote in the last run. If you want to uninstall a randomly started service, perform an update-RC.D-f proxy Remove in update-RC.D the warning message when installing, because we wrote the/etc/init.d/Proxy is too simple, even the LSB information is not provided. Update-rc.d:warning:/etc/init.d/proxy missing LSB informationupdate-rc.d:see //wiki.debian.org/lsbinitscripts>just make a few minor changes and you can avoid that warning. as follows: #!/bin/SH# # # BEGIN INIT info# provides:proxy# Required-Start: $remote _fs# Required-Stop: $remote _fs# Default-start:2 3 4 5# Default-stop:0 1 6# Short-Description:start or stop the HTTP proxy.### END INIT INFO Case " $" inchstart) Start-stop-daemon--start--background--exec/root/proxy.py;; Stop) Start-stop-daemon--stop--name proxy.pyEsacIn this case, one of the simplest random start-up services is written, and it looks like the article is quite long, but in fact there are just a few commands. At the next boot-up, proxy.py will be automatically run as the root user. 

Registering the script as a system service

can see "/etc/rc.d/INIT.D "There are a lot of files, every file can see the content, in fact, are some shell script." The start of the system service is through the/etc/rc.d/INIT.D "is implemented in the script file in the. We can also write a script of our own to put here. The contents of the script file are also very simple, similar to this (for example, a name called "Hahad"):. /etc/init.d/Functionsstart () {Echo "starting my process"CD/opt./haha.SH}stop () {Killallhaha.SH        Echo "stoped"after you have written the script file, you are done with the following steps:chmod+x Hahad #增加执行权限chkconfig--add Hahad #把hahad添加到系统服务列表chkconfig hahad on #设定hahad的开关/off) chkconfig--List Hahad #就可以看到已经注册了hahad的服务 finished all the work at this time. 

  

Linux Setup boot up

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.