Rc. local self-starting service in Linux

Source: Internet
Author: User
As long as you grasp the context of linux startup, the linux startup process will no longer be mysterious.

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.