Enable programs on Linux systems to run automatically when they are powered on

Source: Internet
Author: User

Linux has its own set of complete boot system, grasp the context of Linux start-up, Linux startup process will no longer mysterious.

It is advisable to look at the drawings before reading.

In this article, suppose that the init tree set in Inittab is:









1. About Linux Startup

Init is the father of all processes

Init reads/etc/inittab, executes Rc.sysinit script

(Note that the filename is not necessarily, and some Unix will even write the statement directly in Inittab)

The Rc.sysinit script does a lot of work:

Init $PATH

Config network

Start Swap function

Set hostname

Check root file system, repair if needed

Check root space


Rc.sysinit perform RC according to Inittab? D Script

Linux is a multiuser system, Getty is the watershed between multi-user and Single-user

The system script was run before Getty

. About RC.D

All startup scripts are placed under/ETC/RC.D/INIT.D

RC?. D is the link to the script in Init.d,

The name format is:



S-Starting file passes the start argument to the script

K-initiated file passes the Stop argument to the script

Number determines the order of execution

3. Startup script Example

This is a/etc/rc.d/init.d/apache script to start the httpd:




SOURCE $RC _functions

Case "$" in


echo "Starting Apache daemon ..."

/usr/local/apache2/bin/apachectl-k start




echo "Stopping Apache daemon ..."

/usr/local/apache2/bin/apachectl-k stop




echo "Restarting Apache daemon ..."

/usr/local/apache2/bin/apachectl-k restart







echo "Usage: $ {Start|stop|restart|status}"

Exit 1


Esac can see that he accepts start,stop,restart,status parameters

And then you can build RC? D's Links:



Ln-sf.. /init.d/apache.. /rc0.d/k28apache &&

Ln-sf.. /init.d/apache.. /rc1.d/k28apache &&

Ln-sf.. /init.d/apache.. /rc2.d/k28apache &&

Ln-sf.. /init.d/apache.. /rc3.d/s32apache &&

Ln-sf.. /init.d/apache.. /rc4.d/s32apache &&

Ln-sf.. /init.d/apache.. /rc5.d/s32apache &&

Ln-sf.. /init.d/apache.. /rc6.d/k28apache4. About Rc.local

Often used rc.local is completely a matter of habit, not standard.

There are different implementations for each distribution, and you can do this:



chmod +x/etc/rc.d/rc.local

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc1.d/s999rc.local &&

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc2.d/s999rc.local &&

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc3.d/s999rc.local &&

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc4.d/s999rc.local &&

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc5.d/s999rc.local &&

Ln-sf/etc/rc.d/rc.local/etc/rc.d/rc6.d/s999rc.local5. About bash Startup scripts





It's bash's startup script.

Generally used to set the single user's startup environment, you can also achieve the boot single user's program, but to be clear that they are in the bash category rather than the system category.

Their specific role is described as follows:

/bin/bash This command interpreter (shell after abbreviation) uses a series of startup files to create a running environment:






Each file has a special function and has a different impact on the landing and interaction environment.

/etc/profile and ~/.bash_profile are invoked when an interactive landing shell is started.

/ETC/BASHRC and ~/.BASHRC are invoked when an interactive, non-landing shell is started.

~/.bash_logout is read when the user logs out of the login

An interactive landing shell will run after the/bin/login is successfully logged in. An interactive, non-landing shell is run through the command line, such as [prompt] $/bin/bash. Generally a non-interactive shell appears when running a shell script. A non-interactive shell is called because it does not wait for input on the command line but simply executes the script.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.