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

The usage of chkconfig command in Linux

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

Share

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

This article introduces the knowledge of "the usage of chkconfig command in Linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The chkconfig command is mainly used to update (start or stop) and query the run-level information of system services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes symbolic connections.

Use syntax

The code is as follows:

Chkconfig [--add] [--del] [--list] [system Services] or chkconfig [--level] [system Services] [on/off/reset]

Chkconfig displays usage when running with no parameters. If you add the service name, check to see if the service is started at the current run level. If yes, return true, otherwise return false. If on,off or reset is specified after the service name, chkconfig changes the startup information of the specified service. On and off refer to the service being started and stopped, respectively, and reset refers to the startup information of the reset service, regardless of what is specified in the problematic initialization script. On and off switches, by default, are only valid for runlevel 3, 4, and 5, but reset is valid for all runlevels.

Parameter usage

The code is as follows:

-- add adds the specified system service so that the chkconfig instruction can manage it, and at the same time adds relevant data to the narrative file started by the system.

-- del deletes the specified system service, is no longer managed by the chkconfig instruction, and deletes the relevant data in the narrative file started by the system.

-- level specifies at which execution level the read system service will be turned on or off.

Level 0 indicates that the computer is turned off

Level 1 means: single user mode

Level 2 means: multi-user command line mode without network connection

Level 3 means: multi-user command line mode with network connection

Level 4 means: not available

Level 5 means: multi-user mode with graphical interface

Level 6 means: restart

It is important to note that the level option specifies the runlevel to view, not necessarily the current runlevel. There can be only one start script or stop script per runlevel. When switching runlevels, init does not restart services that have already been started, nor does it stop services that have been stopped again.

The code is as follows:

Chkconfig-- list [name]: displays the running status information (on or off) of all runlevel system services. If name is specified, only the status of the specified service at different runlevels is displayed.

Chkconfig-- add name: add a new service. Chkconfig ensures that each runlevel has a startup (S) or kill (K) entry. If it is missing, it is automatically created from the default init script.

Chkconfig-- del name: delete the service and remove the associated symbolic link from / etc/rc [0-6] .d.

Chkconfig [--level levels] name: sets whether a service is started, stopped, or reset at the specified runtime level.

Run-level file

Each service managed by chkconfig needs to add two or more lines of comments to the script under the corresponding init.d. The first line tells chkconfig the default run level to start and the priority to start and stop. If a service is not started at any runtime level by default, use-instead of runlevel. The second line describes the service and can be commented with\ cross-line comments.

For example, random.init contains three lines:

The code is as follows:

# chkconfig: 2345 20 80

# description: Saves and restores system entropy pool for\

# higher quality random number generation.

Use example

The code is as follows:

Chkconfig-- list # lists all system services

Chkconfig-add httpd # add httpd services

Chkconfig-- del httpd # Delete httpd service

Chkconfig-- level httpd 2345 on # sets httpd to be on when runlevels are 2, 3, 4 and 5

Chkconfig-- list # lists the startup of all the services in the system

Chkconfig-- list mysqld # lists mysqld service settings

Chkconfig-- level 35 mysqld on # sets mysqld to boot at levels 3 and 5.-- level 35 indicates that the operation is only performed at levels 3 and 5, on indicates start, and off indicates shutdown.

Chkconfig mysqld on # sets mysqld to on at each level, and "each level" includes levels 2, 3, 4 and 5

How to add a service

Service scripts must be stored in the / etc/ini.d/ directory

Chkconfig-add servicename, add this service to the list of chkconfig tool services, and the service will be given an entry in / etc/rc.d/rcN.d

Chkconfig-level 35 mysqld on to modify the default startup level of the service.

This is the end of the introduction to "the use of chkconfig commands in Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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