Basic use of the chkconfig command in CentOS

Source: Internet
Author: User
In a linux operating system, you often need to create some services which are made into shell scripts. these services must be automatically started when the system starts and closed. In the/etc/rc. d/init. d Directory of the script to be automatically started, run the command chkconfig -- addfilename to enable automatic registration, start, and shut down. In essence, some file connections are generated under the rc0.d-rc6.d directory, which are connected to/etc/rc. d/init. d. in the linux operating system, you often need to create some services which are made into shell scripts. these services must be automatically started when the system is started and closed.
In the/etc/rc. d/init. d Directory of the script to be automatically started, run the command chkconfig -- add filename to enable automatic registration, start, and shut down. Essentially
Is to generate some file connections under the rc0.d-rc6.d Directory, these connections connect to the shell script of the specified file under the/etc/rc. d/init. d Directory.


Syntax:
Chkconfig [-- add] [-- del] [-- list] [system service] or chkconfig [-- level <等级代号> ] [System service] [on/off/reset]
The usage of chkconfig is displayed when no parameter is available. If the service name is added, check whether the service is started at the current running level. If yes, true or no is returned.
Returns false. If on, off, or reset is specified after the service name, chkconfi changes the startup information of the specified service. On and off indicate that the service is started.
Start and stop. reset refers to resetting the service startup information, no matter what is specified by the problematic initialization script. On and off switches. by default, the system is only valid for 3, 4, and 5 running levels, but the reset can be valid for all running levels.

 

Chkconfig -- list # list all System Services
Chkconfig -- add httpd # add httpd service
Chkconfig -- del httpd # Delete the httpd service
Chkconfig -- level httpd 2345 on # sets httpd to on when the running level is 2, 3, 4, or 5.
Chkconfig -- list # list all system startup statuses
Chkconfig -- list mysqld # list mysqld service settings
Chkconfig -- level 35 mysqld on # set mysqld to run at level 3 and 5, -- level 35 indicates that the operation is only executed at level 3 and 5, on


Start, off, and off
Chkconfig mysqld on # set mysqld to on at each level. "each level" includes 2, 3, 4, and 5 levels.




Parameter usage:
-- 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.
-------------------------------------------------------------------------------
Level 0: Shutdown
Level 1: Single user mode
Level 2: Multi-user command line mode without network connection
Level 3: Multi-user command line mode with network connection
Level 4: Unavailable
Level 5: Multi-user mode with graphic interface
Level 6: Restart
It should be noted that the level option can specify the running level to be viewed, not necessarily the current running level. For each running level, there can be only one startup script or stop
Stop the script. When you switch to the running level, init does not restart the started service or stop the stopped service again.
-------------------------------------------------------------------------------
-- List: displays the running status of all system services. if a specific service is specified, only the system running level of a service is displayed.
Chkconfig -- list [name]: displays the running status information (on or off) of all running-level system services ). If the name is specified, only the specified service is displayed.


Status at different running levels.
Chkconfig -- add name: add a new service. Chkconfig ensures that each running level has a startup (S) or kill (K) entry. If it is missing


The default init script is automatically created.
Chkconfig -- del name: delete the service and delete the connection from/etc/rc [0-6]. d.
Chkconfig [-- level levels] name: Sets whether a service is started, stopped, or reset at the specified running level.


Run-level files:
Each service managed by chkconfig needs to add two or more lines of comments to the script in the corresponding init. d. The first line tells chkconfig that the default startup running level is
And the priority of start and stop. If a service is not started at any running level by default, use-to replace the running level. The second line describes the service. you can use the \ cross-line comment.



--------------------------------------------------------------------------
Summary:

Chkconfig-add servername is to add a startup service

Chkconfig -- delete servername delete a startup service

Chkconfig -- list View all

Chkconfig -- level 3 servername on | off modify startup/Stop service level

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.