/ETC/RC.D/INIT.D Self-Starter program description

Source: Internet
Author: User
Tags chmod

Reprint Address: http://www.cnblogs.com/diyunpeng/archive/2009/11/11/1600886.html

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

In this article, suppose 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.D
3. Startup script Example
4. About Rc.local
5. About bash Startup scripts
6. About the automatic startup of the boot program


1. About Linux Startup

Init is the top level 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


2. About RC.D

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

RC?. D is a link to the script in Init.d, and the name format is:

S{number}{name}

K{number}{name}

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:

Code:

#!/bin/bash

......

Can see that he accepts start,stop,restart,status parameters

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

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

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

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

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

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:
/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout

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

6. About the automatic startup of the boot program

System scripts can be placed in/ETC/RC.D/INIT.D and build/ETC/RC.D/RC? D links, which can also be placed directly in the/etc/rc.d/rc.local.

The INIT.D script contains the complete start,stop,status,reload and other parameters, which are standard practices that are recommended for use.

A program that is used for a particular user (such as a user who needs to use the Chinese input method but not needed) is placed in a bash startup script in ~/.

========================================================================
Set the system to start automatically
Create a Smsafe file under/etc/init.d/

Content:
#!/bin/bash
# CHKCONFIG:35 95 1
# Description:script to Start/stop Smsafe
Case is in
Start
sh/opt/startsms.sh
;;
Stop
sh/opt/stopsms.sh
;;
*)
echo "Usage: $ (start|stop)"
;;
Esac
Change permissions
# chmod 775 Smsafe

Join Auto Start
# Chkconfig–add Smsafe

View automatic startup settings
# chkconfig–list Smsafe

Smsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off

You can start and stop scripts later with the following command
# service Smsafe Start

# Service Smsafe Stop

=======================================================================
Jira's startup relies primarily on the catalina.sh script in the bin directory, providing parameters such as the start,stop of the Init script

#!/bin/bash

#

# chkconfig:2345 85 15

# Description:jira

# Processname:jira

# source Function Library

. /etc/init.d/functions

#下面一行比较重要, for Jira installation path, if not, you will be prompted not to find the file

Catalina_home= "/var/www/jira"

Retval=0

Start () {

Echo-n $ "Starting Jira services:"

. /var/www/jira/bin/catalina.sh start

Retval=$?

Echo

}

Stop () {

Echo-n $ "Shutting down Jira services:"

. /var/www/jira/bin/catalina.sh stop

Retval=$?

Echo

}

Case "$" in

Start

Start

;;

Stop

Stop

;;

Restart|reload)

Stop

Start

;;

Status

Status Jira

Retval=$?

;;

*)

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

Exit 1

Esac

Exit $RETVAL

-------------------------------

Save As/etc/init.d/jira

And then use Chkconfig--add Jira

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.