Use the script management service in CentOS

Source: Internet
Author: User

Use the script management service in CentOS

1. Run the chkconfig tool to manage the Service Startup Script in the/etc/rc. d/init. d or/etc/init. d/directory.
Add two lines at the beginning of the Service Startup Script:
# Chkconfig: 2345 88 12
In this way, you can use the tool chkconfig to manage the Service Startup Script.
Tool: benefits of the chkconfig tool:
If this tool is not used, we need to make a service run at levels 2, 3, 4, and 5, but not at other levels.
You need to manually set many symbolic connections:
Run the following command in/etc/rc. d/rc1.d: [root @ node2 rc1.d] # ln-sv K12nrped ../init. d/nrped
Run the following command in/etc/rc. d/rc2.d: [root @ node2 rc2.d] # ln-sv S88nrped ../init. d/nrped
Run the following command in/etc/rc. d/rc3.d: [root @ node2 rc3.d] # ln-sv S88nrped ../init. d/nrped
Run the following command in/etc/rc. d/rc4.d: [root @ node2 rc4.d] # ln-sv S88nrped ../init. d/nrped
Run the following command in/etc/rc. d/rc5.d: [root @ node2 rc5.d] # ln-sv S88nrped ../init. d/nrped
Run the following command in/etc/rc. d/rc6.d: [root @ node2 rc6.d] # ln-sv K12nrped ../init. d/nrped
Add these symbolic links. When the running level changes, the service will grant the control of the script rc. ------> The rc Script will mark S, K, and start the corresponding service according to the symbol ID of the corresponding running level directory (/etc/rc. d/rc $ runlevel. d. In this way, you can set whether a service is running at a running level.
Tool: chkconfig automatically sets the above symbolic link according to the # chkconfig line of the Service running script.

[Root@node2rc3.d] # chkconfigon

The symbolic links at various running levels will be created based on: # chkconfig: 2345 88 12.

2. To use tools: the service management service script must receive the start and stop options at least;
The Service Startup Script depends on the options entered by the user:
Stop -----> close the service
Start -----> start the service
Reload -----> tells the program to repeat the configuration file and change the running status of the program
Restart ----> restart the service

3. Lock directory for RedHat/SuSE
A mechanism for RedHat to manage services. You need to create a lock file under the/var/lock/subsys/directory.

[Root@node2rc.d] # vim/etc/init. d/nrped #! /Bin/bash # chkconfig: 23458911 # description: NRPEDAENONNRPE =/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 $ OPTIONSRETVAL =$? Echo [$ RETVAL = 0] & touch $ {lockfile} return $ RETVAL} stop () {echo-n $ "Stopping $ prog:" killproc-d-10 $ NRPERETVAL = $? Echo [RETVAL = 0] & rm-f $ {lockfile} reload () {echo-n $ "Reloading $ prog: "killproc $ NRPE-HUPecho} case" $1 "instart) start; stop) stop; restart) stopstart; reload) reload; status) status $ NRPE ;; *) echo "Usage: $ 0start | stop | restart | reload | status"; esacexit0

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: 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.