Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rc.local self-starting service instance in Linux system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "rc.local self-starting service instance in Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Linux has its own complete startup system, which grasps the context of linux startup, and the startup process of linux will no longer be 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

Catalogue

1. About the startup of linux

two。 About rc.d

3. Startup script example

4. About rc.local

5. About bash startup script

6. About the automatic startup of the boot program

1. About the startup of linux

Init is the top level of all processes

Init read / etc/inittab, execute rc.sysinit script

(note that the file name is not necessary, and some unix even write statements 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 executes rc?.d scripts according to inittab

Linux is a multi-user system, and getty is a watershed between multi-user and single-user.

Before getty, you ran system scripts.

two。 About rc.d

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

Placed in rc?.d is a link to a script in init.d, named in the following format:

S {number} {name}

K {number} {name}

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

Files starting with K pass stop parameters to the script

Number decides the order of execution

3. Startup script example

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

Code:

#! / bin/bash

.

You can see that he accepts the start,stop,restart,status parameter.

You can then set up a link to rc?.d like this:

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 often used, is entirely a matter of habit, not standard.

Different distributions have different implementations, 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 script

/ etc/profile

/ etc/bashrc

~ / .bash_profile

~ / .bashrc

Is the startup script for bash

Generally used to set up a single-user startup environment, you can also boot single-user programs, but to make it clear that they all belong to the bash category rather than the system category.

Their specific roles are described as follows:

/ bin/bash, the command interpreter (hereinafter referred to as shell), uses a series of startup files to establish a runtime environment:

/ etc/profile

/ etc/bashrc

~ / .bash_profile

~ / .bashrc

~ / .bash_logout

Each file has a special function and has a different impact on the login and interaction environment.

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

/ etc/bashrc and ~ /. Bashrc are called when an interactive non-login shell starts.

~ / .bash_logout is read when the user logs out and logs in

An interactive login shell will run after / bin/login has successfully logged in. An interactive non-login shell is run from 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 simply executes a script.

6. About the automatic startup of the boot program

System scripts can be placed in / etc/rc.d/init.d and linked to / etc/rc.d/rc?.d, or directly in / etc/rc.d/rc.local.

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

Programs for specific users (for example, some users need to use Chinese input methods and others do not) are placed in the bash startup script in ~ /.

=

Set up 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 $1 in

Start)

Sh / opt/startsms.sh

Stop)

Sh / opt/stopsms.sh

*)

Echo "Usage: $0 (start | stop)"

Esac

Change permissions

# chmod 775 smsafe

Join automatic 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 the script later with the following command

# start service smsafe start

# service smsafe stop stop

=

The startup of jira mainly depends 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

# the following line is important, which is the installation path of jira. If not, the file will not 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

And then use chkconfig-- add jira

OK

Start / etc/init.d/jira start

Stop / etc/init.d/jira stop

=

(take Websphere as an example)

1. Create a new startup script startWebsphere in the / etc/rc.d/init.d directory and type:

#! / bin/sh

/ opt/WebSphere/AppServer/bin/startServer.sh server1

Modify the permissions of the file:

Chmod 755 startWebsphere

two。 Establish a soft connection under the corresponding directory (assuming the system enters X11 by default)

Cd / etc/rc.d/rc5.d

Ln-s.. / init.d/startWebsphere S99startWebsphere

3. Just restart the system.

=

Self-starting script of oracle under linux

1. Write a StartOracle.sql, suppose you put it in the / directory

Vi / StartOracle.sql add the following two lines to save

Startup

Exit

two。 Configuration / etc/rc.local

Add the following content to vi / etc/rc.local and save it

Su-oracle-c'$ORACLE_HOME/bin/lsnrctl start'

Su-oracle-c'$ORACLE_HOME/bin/sqlplus "/ as sysdba" @ / StartOracle.sql'

3. If you want to start oracle enterprise manager (em) and isqlplus automatically, you can configure them as follows

Vi / etc/rc.local join:

Su-oracle-c'$ORACLE_HOME/bin/emctl start dbconsole'

Su-oracle-c'$ORACLE_HOME/bin/isqlplusctl start'

You should know that the ports used by em and isqlplus can query files:

$ORACLE_HOME/install/portlist.ini (take oracle 10.1.0.3 as an example)

=

# demonstration of direct binding under root command line:

Arp-s 192.x.x.x. 00:ea:se binding.

Arp-d deletion

Arp-f batch import

This is the end of the introduction of "rc.local self-starting Service instance in Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report