Command for modifying system services in Linux: chkconfig (checkconfig)

Source: Internet
Author: User
Chkconfig function description: check and set various services of the system. Syntax: chkconfig [-- add] [-- del] [-- list] [system service] or chkconfig [-- level & lt; level code & gt;] [system service] [on/off/reset] Supplement: RedHat complies with GPL rules...

Chkconfig
Function description: check and set various services of the system.
Syntax: chkconfig [-- add] [-- del] [-- list] [system service] or chkconfig [-- level <等级代号> ] [System service] [on/off/reset]
Note: This is a program developed by Red Hat following the GPL rules. it can query the system services that the operating system will execute at each execution level, including various resident services.
Parameters:
-- Add adds the specified system service, enables the chkconfig command to manage it, and adds relevant data in the system startup description file.
-- Del: deletes the specified system service. it is no longer managed by the chkconfig command, and relevant data is also deleted in the description file started by the system.
-- Level <等级代号> Specify the execution level of the Read system service.

First, run the chkconfig -- list command to view all added System Services (the following results are only part of the results)

[Root @ fd init. d] # chkconfig -- list
Diskdump 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Xfs 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Rhnsd 0: off 1: off 2: off 3: on 4: on 5: on 6: off
Cups-config-daemon 0: off 1: off 2: off 3: on 4: on 5: on 6: off
Netfs 0: off 1: off 2: off 3: on 4: on 5: on 6: off
Nfs 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Microcode_ctl 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Netplugd 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Netdump 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Cpuspeed 0: off 1: on 2: on 3: on 4: on 5: on 6: off
Syslog 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Smb 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Ntpd 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Rawdevices 0: off 1: off 2: off 3: on 4: on 5: on 6: off
Psacct 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Vncserver 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Saslauthd 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Dc_server 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Mdmonitor 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Httpd 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Ibmasm 0: off 1: off 2: off 3: off 4: off 5: off 6: off
Dc_client 0: off 1: off 2: off 3: off 4: off 5: off 6: off

The first column indicates the service name, and the value 0-6 indicates whether the service is enabled (on) or disabled (off) in the six startup modes)
For example, by default, the service that automatically detects the new hardware is started (the service name is kudzu). each time it is started, the service needs to be detected for a period of time. we can disable the service, you can call it with hardware changes later.
Chkconfig kudzu off
Chkconfig -- list kudzu
Kudzu 0: off 1: off 2: off 3: off 4: off 5: off 6: off
We can see that all the services of the new hardware are disabled, and the new hardware will not be detected when it is started again. If you have hardware changes, you can choose to open the service (chkconfig kudzu on). In fact, there is a simpler way to enter
Service kudzu start
Start the new hardware service manually. These services are stored in the/etc/init. d Directory. they are all executable shell files, such as the new hardware service
[Root @ fd/] # ls-l/etc/init. d/kudzu
-Rwxr-xr-x 1 root 2095 Aug 23 2005/etc/init. d/kudzu
In fact, we can write shell files here and add them as system services, but we must follow a simple reservation. Let's take a look at the specific content of kudzu.
Compile a simple service script to start tomcat in this mode, vi/etc/init. d/tomcat. the content is as follows:
[Root @ fd/] # cat/etc/init. d/kudzu
#! /Bin/bash
#
# Kudzu This scripts runs the kudzu hardware probe.
#
# Chkconfig: 345 05 95
# Description: This runs the hardware probe, and optionally configures \
# Changed hardware.
# This is an interactive program, we need the current locale
Content omitted
 
 
# Chkconfig: 2345 20 80
# Description: simple example to start tomcat
Export JAVA_HOME =/usr/java/jdk1.5.0 _ 16
Export CLASS_PATH =/usr/java/jdk1.5.0 _ 16/lib
Export PATH = $ JAVA_HOME/bin: $ PATH
/Usr/Tomcat/bin/startup. sh
Add tomcat to the service
Chkconfig -- add tomcat
Status set to start
Chkconfig tomcat on
The comments in the first few lines of the tomcat file must contain two parts: chkconfig and description. otherwise, when "chkconfig -- add tomcat" is executed, the error message "tomcat service does not support chkconfig" appears. This line of chkconfig indicates the default startup running level and the priority of start and stop. if the service is not started at any running level by default, "-" is used instead of "Run level. In tomcat, the script is started at runtime level 2, 3, 4, and 5. the priority for starting is 20 (the higher the priority, the later the service starts) and the priority for stopping is 80. If the service has been set, you can modify the startup priority by editing the tomcat file. delete the service and add it.
I mimic the content of the new hardware service to write a complicated tomcat service, start tomcat at system startup, and disable tomcat when the system is disabled. The content is as follows:
 
# Chkconfig: 2345 30 70
# Description: Starts and Stops Tomcat.
Export JAVA_HOME =/usr/java/jdk1.5.0 _ 16
Export CLASS_PATH =/usr/java/jdk1.5.0 _ 16/lib
Export PATH = $ JAVA_HOME/bin: $ PATH
Case "$1" in
Start)
/Usr/Tomcat/bin/startup. sh
Touch/var/lock/subsys/tomcat
;;
Status)
If [-f/var/lock/subsys/tomcat]; then
Echo $ "tomcat is running"
Exit 0
Fi
Echo $ "tomcat has stopped"
Exit 3
;;
Stop)
/Usr/Tomcat/bin/shutdown. sh
Rm-f/var/lock/subsys/tomcat
;;
Restart)
/Usr/Tomcat/bin/shutdown. sh
/Usr/Tomcat/bin/startup. sh
;;
*)
Echo "Usage: tomcat {start | stop | restart | status }"
Exit 1
Esac
Exit 0

 

This article is from "Thinking"

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.