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

How CentOS uses scripts to manage services

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how CentOS uses script management services. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. Use tools: chkconfig manages the service startup scripts in the / etc/rc.d/init.d or / etc/init.d/ directory.

To add two lines at the beginning of the service startup script:

# chkconfig: 2345 88 12

# description: XXXXXXXXX XXXXXX

This allows you to use the tool: chkconfig to manage the service startup scripts.

Using tools: benefits of the chkconfig tool:

Instead of using this tool, we want a service to run at levels 2, 3, 4, and 5, and not at other levels. To set up many symbolic connections manually:

Execute in / etc/rc.d/rc1.d: [root@node2 rc1.d] # ln-sv K12nrped.. / init.d/nrped

Execute in / etc/rc.d/rc2.d: [root@node2 rc2.d] # ln-sv S88nrped.. / init.d/nrped

Execute in / etc/rc.d/rc3.d: [root@node2 rc3.d] # ln-sv S88nrped.. / init.d/nrped

Execute in / etc/rc.d/rc4.d: [root@node2 rc4.d] # ln-sv S88nrped.. / init.d/nrped

Execute in / etc/rc.d/rc5.d: [root@node2 rc5.d] # ln-sv S88nrped.. / init.d/nrped

Execute in / etc/rc.d/rc6.d: [root@node2 rc6.d] # ln-sv K12nrped.. / init.d/nrped

After adding these symbolic links. When the run level changes, the service gives control to the script rc. -> the rc script will shut down and start the corresponding service according to the symbol of the corresponding run-level directory (/ etc/rc.d/rc$runlevel.d): s and K. This enables you to set whether a service is running at a run level.

Tool: chkconfig automatically sets the above symbolic link based on the # chkconfig line where the service runs the script.

[root@node2 rc3.d] # chkconfig on

Symbolic links at each run level are created based on: # chkconfig: 2345 88 12.

2. In order to use the tool: the service management service script needs to receive at least start and stop options

The service startup script is based on the options entered by the user:

Stop-> shut down the service

Start-> start the service

Reload-> tell the program to reread the configuration file and change the running state of the program

Restart-> restart service

3 、 Lock directory for RedHat / SuSE

A mechanism for RedHat management services to create a lock file in the / var/lock/subsys/ directory.

[root@node2 rc.d] # vim / etc/nagios/nrpe.cfg. D lockfile=/var/lock/subsys/nrpedprog=nrpedRETVAL=0. Bash chkconfig: 2345 89 1 lockfile=/var/lock/subsys/nrpedprog=nrpedRETVAL=0: NRPE DAENONNRPE=/usr/local/nagios/bin/nrpeOPTIONS= "- c / etc/nagios/nrpe.cfg-d" lockfile=/var/lock/subsys/nrpedprog=nrpedRETVAL=0. / etc/rc.d/init.d/functionsstart () {echo-n $"Starting $prog:" daemon $NRPE $OPTIONS RETVAL=$? Echo [$RETVAL= 0] & & touch ${lockfile} return $RETVAL} stop () {echo-n $"Stopping $prog:" killproc-d-10$ NRPE RETVAL=$? Echo [RETVAL = 0] & & rm-f ${lockfile}} reload () {echo-n $"Reloading $prog:" killproc $NRPE-HUP echo} case "$1" in start) start;; stop) stop;; restart) stop start;; reload) reload;; status) status $NRPE *) echo "Usage: $0 start | stop | restart | reload | status";; esacexit 0 this article on "how to use script management service in CentOS" ends here. I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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