In Linux, The chkconfig command is described in detail to add a service and start or stop the system service in two ways.

Source: Internet
Author: User
Tags stop script

In Linux, The chkconfig command is described in detail to add a service and start or stop the system service in two ways.

The chkconfig command is used to update (start or stop) and query the running level information of the system service. Remember that chkconfig does not automatically disable or activate a service immediately, but simply changes the symbolic connection. I. Usage Syntax of chkconfig

1. chkconfig [-- add] [-- del] [-- list] [System Service] Or chkconfig [-- level <levels level code>] [System Service] [on/off/reset]

2. 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 <level code> specifies 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: reserved by the System
Level 5: multi-user mode with graphic interface
Level 6: restart
3. The level option specifies the running level to be viewed, not necessarily the current running level. For each running level, only one startup script or stop script is allowed. When you switch to the running level, init does not restart the started service or stop the stopped service again.

4. chkconfig -- list [name]: displays the running status information (on or off) of all running-level system services ). If the name is specified, only the status of the specified service at different running levels is displayed.
5. chkconfig -- add name: add a new service. Chkconfig ensures that each running level has a startup (S) or kill (K) entry. If the init script is missing, it is automatically created from the default init script.
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.

6. 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 the default startup running level 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.
For example, random. init contains three rows:
# Chkconfig: 2345 20 80
# Description: Saves and restores system entropy pool \
# Higher quality random number generation.

Example:
Chkconfig -- list # list all system services
Chkconfig -- add httpd # add httpd service
Chkconfig -- del httpd # Delete the httpd service
Chkconfig -- level 2345 httpd on # Set 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 indicates that the operation is started, and off indicates that the operation is disabled.
Chkconfig mysqld on # Set mysqld to on at each level. "Each level" includes 2, 3, 4, and 5 levels.

7. How to add a service: Take mysqld as an Example
(1) Service scripts must be stored in the/etc/init. d/directory;
(2), chkconfig -- add mysqld # add service, add this service in the chkconfig tool service list, the service will be in/etc/rc. d/rcN. d. Assign the K/S entry;
(3), chkconfig -- level 35 mysqld on # modify the default Service Startup level.

Ii. Service Startup/Shutdown

1. System Service: a service that is always running in the memory and providing services is called a service;

2. The service is also a running program, and the running program is called daemons;

3. the startup scripts of these services are generally stored in:/etc/init. d.

4. In centos, the Service Startup Script is placed in:/etc/rc. d/init. d and/etc/init. d This directory is a recognized directory, in centos/etc/init. d is a link file.

5. The configuration of environment variables initialized by the/etc/sysconfig service is in this file.

6. The databases generated by various services of/var/lib are in this directory. The simplest way is to find mysql and use vim to open it, the name of the database you created and the default database generated by the system are all included here!

7,

8. start/stop/restart the service:/etc/init. d/serverName start/stop/restart/status

9. start/stop/restart the service: service serverName start/stop/restart. Why can I write this?

10. The service is a script that can analyze the parameters you post and get the correct service to stop start restart according to your parameters at/etc/init. d.

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.