Linux self-Starting service script (/ETC/RC.D/INIT.D or its link/etc/init.d)

Source: Internet
Author: User

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

Linux has its own set of complete boot system, seize the Linux boot context, the Linux startup process will no longer mysterious.

In this article, it is assumed 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. Automatic start-up 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 file name is not necessarily, some Unix will even write the statement directly in the 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 a watershed between multiuser and single users.
The system script was run before Getty


2. About RC.D

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

RC?. A link to the script in INIT.D is placed in D, and the naming format is:

S{number}{name}

K{number}{name}

s starts the file to pass the start parameter to the script

K-Started file passing the stop parameter 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 httpd:

Code:

#!/bin/bash

......

Can see that he accepts the Start,stop,restart,status parameter

Then you can set up RC?. D's 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

Often used rc.local is a purely customary problem, not a standard.

Each release has a different implementation method, 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

It's bash's startup script.

Generally used to set up a single user's startup environment, you can also implement a single user program, but to make it clear that they belong to the bash category rather than the system category.

Their specific role is described as follows:

/bin/bash This command interpreter (hereafter called Shell) 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 different effects on the landing and interactive environment.

/etc/profile and ~/.bash_profile are called when launching an interactive login shell.

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

~/.bash_logout is read when the user logs off the login

An interactive login 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. Typically a non-interactive shell appears when you run the shell script. A non-interactive shell is called because it does not wait for input on the command line and simply executes the script.

6. Automatic start-up of the boot program

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

The Init.d script contains complete parameters such as Start,stop,status,reload, which are standard practices that are recommended for use.

Programs that are used for a particular user (for example, some users need to use Chinese input methods and some do not) are placed in the 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 $ 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 Auto-start settings
# chkconfig–list Smsafe

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

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

# Service Smsafe Stop Stop

=======================================================================
Jira's startup relies primarily on the catalina.sh script in the bin directory, which provides 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 the Jira installation path, no, 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

Then use Chkconfig--add Jira

Ok

Start/etc/init.d/jira Start

Stop/etc/init.d/jira Stop

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

(with WebSphere as an example)

1. In the/ETC/RC.D/INIT.D directory, under new startup script Startwebsphere, type the following:
#!/bin/sh
/opt/websphere/appserver/bin/startserver.sh Server1

Permissions to modify this file:
chmod 755 Startwebsphere

2. Establish a soft connection in the corresponding directory (assuming the system enters X11 by default)
Cd/etc/rc.d/rc5.d
Ln-s. /init.d/startwebsphere S99startwebsphere

3. Restart the system to

=======================================================================
Self-booting scripts for Oracle under Linux

1. Write a startoracle.sql, assuming that it is placed in/directory
Vi/startoracle.sql Add the following two lines to save
Startup
Exit

2. Configure/etc/rc.local
Vi/etc/rc.local Add the following to save
Su-oracle-c ' $ORACLE _home/bin/lsnrctl start '
Su-oracle-c ' $ORACLE _home/bin/sqlplus "/as sysdba" @/startoracle.sql '

3. If you also want to automatically start Oracle Enterprise Manager (EM) and Isqlplus can be configured as follows
Vi/etc/rc.local join:
Su-oracle-c ' $ORACLE _home/bin/emctl start dbconsole '
Su-oracle-c ' $ORACLE _home/bin/isqlplusctl start '

To know the ports such as EM and isqlplus can query the file:
$ORACLE _home/install/portlist.ini (Example of ORACLE 10.1.0.3)

=======================================================================
#root命令行下直接绑定演示:
Arp-s 192.x.x.x. 00:ea:se binding.
arp-d Delete
Arp-f Bulk Import

Linux self-Starting service script (/ETC/RC.D/INIT.D or its link/etc/init.d)

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.