Linux rc.local self-starting service

  

linux has its own complete boot system, grabbing the context of Linux boot, Linux boot process will no longer be mysterious.

This article assumes that the init tree set in inittab is:

/etc/rc.d/rc0.d/etc/rc.d/rc1.d/etc/rc.d/Rc2.d/etc/rc.d/rc3.d/etc/rc.d/rc4.d/etc/rc.d/rc5.d/etc/rc.d/rc6.d/etc/rc.d/Init.d

Directory

1. About linux startup 2. About rc.d3. Startup script example 4. About rc.local5. About bash startup script 6. About boot program auto Start

1. About Linux startup

init is the top init of all processes read /etc/inittab, execute rc.sysinit script (note that the file name is not necessarily, some Unix even The statement will be written 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 According to inittab, rc?.d script is a multi-user system. Getty is a watershed of multiple users and single users. The system script is run before getty

2. About rc.d

All The startup script is placed in /etc/rc.d/init.d under

rc?.d is init.d The link to the script, the naming format is:

S{number}{name}

K{number}{name}

S start the file to pass the start parameter to the script< Br>

K starts the file to pass the stop parameter to the script

number determines the order of execution

3. Startup script example

This is used to start httpd /etc/rc.d/init.d/apache Script:

Code:

#!/bin/bash

......

can be seen that he accepts start, stop, restart, status parameters

and then can create a link to rc?.d:

Code:

cd /etc/Rc.d/init.d &&

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/K28apache

4. About rc.local

The regular use of rc.local is completely customary. Title, not a standard.

These distributions have different implementation methods, which can be implemented as follows:

Code:

touch /etc/rc.d/rc.local

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.local

5. About bash startup scripts

/Etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

is the startup script for bash

Generally used to set up a single-user boot environment, you can also implement the program of the boot single user, but make sure that they belong to the bash category rather than the system category.

Copyright © Windows knowledge All Rights Reserved