Linux RC. Local self-starting service

Source: Internet
Author: User

Linux has its own complete startup system, which captures the context of Linux Startup. the Linux Startup Process will no longer be mysterious.

In this article, we assume 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. Bash Startup Script
6. About Automatic startup of the boot program

1. about Linux Startup

Init is the top layer of all processes.
Init reads/etc/inittab and executes the RC. sysinit script.
(Note that the file name is not certain. Some UNIX statements may even be written directly in the inittab)

The RC. sysinit script has done 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: Execute RC according to inittab ?. D script
Linux is a multi-user system, and Getty is the watershed between multiple users and individual users.
The system script is run before Getty.

2. About rc. d

All startup scripts are placed under/etc/rc. d/init. d.

RC ?. D contains the link of the script in init. d. The naming format is:

S {number} {name}

K {number} {name}

The file starting with S passes the start parameter to the script.

Files starting with K pass the stop parameter to the script

Number determines the execution order

3. STARTUP script example

This is a/etc/rc. d/init. d/Apache script used to start httpd:

Code:

#! /Bin/bash

......

We can see that it accepts the start, stop, restart, and status parameters.

Then we can establish RC ?. D link:

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

RC. Local, which is frequently used, is a habit rather than a standard.

Different releases 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. Bash Startup Script

/Etc/profile

/Etc/bashrc

~ /. Bash_profile

~ /. Bashrc

Is the bash STARTUP script.

It is generally used to set the startup environment for a single user. It can also be used to launch a single user program, but it should be clear that they are in the bash category rather than the system category.

Their specific functions are described as follows:

The/bin/bash command interpreter (Shell) uses a series of startup files to create a runtime environment:
/Etc/profile

/Etc/bashrc

~ /. Bash_profile

~ /. Bashrc

~ /. Bash_logout

Each file has special functions and has different effects on the login and interaction environments.

/Etc/profile and ~ /. Bash_profile is called when an interactive login shell is started.

/Etc/bashrc and ~ /. Bashrc is called when an interactive non-login shell is started.

~ /. Bash_logout is read when the user logs out.

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

6. About Automatic startup of the boot program

System scripts can be placed in/etc/rc. d/init. d and/etc/rc. d/RC ?. D links can also be directly placed in/etc/rc. d/rc. Local.

The init. d script contains complete parameters such as start, stop, status, and reload. It is a standard practice and is recommended.

Programs used by specific users (if some users need to use Chinese input methods but some do not need them) are placed in ~ .

========================================================== ======================================
Set Automatic startup
Create a smsafe file under/etc/init. d/

Content:
#! /Bin/bash
# Chkconfig: 35 95 1
# Description: script to start/stop smsafe
Case $1 in
Start)
SH/opt/startsms. Sh
;;
Stop)
SH/opt/stopsms. Sh
;;
*)
Echo "Usage: $0 (START | stop )"
;;
Esac
Change permissions
# Chmod 775 smsafe

Add 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

Run the following command to start and stop the script.
# Service smsafe start startup

# Service smsafe stop

========================================================== ====================================
JIRA mainly relies on the Catalina. Sh script in the bin directory, providing parameters such as start and stop of the init script.

#! /Bin/bash

#

# Chkconfig: 2345 85 15

# Description: Jira

# Processname: Jira

# Source function library

./Etc/init. d/functions

# The following line is important. It is the installation path of Jira. If not, the system will prompt that the file cannot be found.

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 "$1" in

Start)

Start

;;

Stop)

Stop

;;

Restart | RELOAD)

Stop

Start

;;

Status)

Status Jira

Retval =$?

;;

*)

Echo $ "Usage: $0 {START | stop | restart | status }"

Exit 1

Esac

Exit $ retval

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

Save as/etc/init. d/Jira

Then use chkconfig -- add Jira

OK

Start/etc/init. d/Jira start

Stop/etc/init. d/Jira stop

========================================================== ====================================

(Taking WebSphere as an example)

1. Create the startup script startwebsphere in the/etc/rc. d/init. d directory and type the following content:
#! /Bin/sh
/Opt/WebSphere/appserver/bin/startserver. Sh server1

Modify the permission of the file:
Chmod 755 startwebsphere

2. Create a soft connection under the corresponding directory (assuming that the system enters X11 by default)
CD/etc/rc. d/rc5.d
Ln-S ../init. d/startwebsphere s99startwebsphere

3. restart the system.

========================================================== ====================================
Oracle self-starting script in Linux

1. Write a startoracle. SQL statement in the/directory.
VI/startoracle. SQL Add the following two rows to save
Startup
Exit

2. Configure/etc/rc. Local
Add the following content to VI/etc/rc. Local and save
Su-Oracle-c '$ ORACLE_HOME/bin/LSNRCTL start'
Su-Oracle-c '$ ORACLE_HOME/bin/sqlplus "/As sysdba" @/startoracle. SQL'

3. If you want to automatically start Oracle Enterprise Manager (EM) and ISQLPLUS, you can configure them as follows:
VI/etc/rc. Local:
Su-Oracle-c '$ ORACLE_HOME/bin/emctl start dbconsole'
Su-Oracle-c '$ ORACLE_HOME/bin/isqlplusctl start'

You can query the files on the ports used by EM and ISQLPLUS:
$ ORACLE_HOME/install/portlist. ini (using Oracle 10.1.0.3 as an example)

========================================================== ====================================
# Bind a file directly under the root command line:
ARP-s 192. x. 00: Ea: Se binding.
ARP-D Deletion
ARP-F batch Import

Related Article

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.