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:
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
# Description: XXXXXXXXX XXXXXX
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 @ node2 rc3.d] # chkconfig on |
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 @ node2 rc. d] # vim/etc/init. d/nrped #! /Bin/bash # chkconfig: 2345 89 11 # description: 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 |