Linux under the Chkconfig command to add services and two ways to start shutdown system services

Source: Internet
Author: User
Tags stop script


the Chkconfig command is primarily used to update (start or stop) and query run-level information for system services. Keep in mind that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection. first, the use of Chkconfig grammar

1. chkconfig [--add][--del][--list][system service] or Chkconfig [--level <levels Class Code >][system service][on/off/reset]

2. Parameter usage:
--add adds the specified system service, allows the CHKCONFIG directive to manage it, and adds relevant data to the system-initiated narrative file.
--del deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data within the system-initiated narrative file.
--level< Class code > Specify which execution level the system service should be opened or closed.
Level 0 means: shutdown
Level 1 means: Single user mode
Level 2: Multi-user command line mode with no network connection
Level 3 means: Multi-user command line mode with network connection
Level 4 means: System reserved
Level 5 means: Multi-user mode with graphical interface
Level 6 means: reboot
3. It is necessary to note that the level option can specify the run levels to view and not necessarily the current run level. For each run level, there can be only one startup script or stop script. When you switch the run level, Init does not restart the service that is already started, nor does it stop the service that has stopped.

4, chkconfig--list [name] : Displays the health status information (on or off) for all run-level system services. If name is specified, only the state of the specified service at a different run level is displayed.
5, chkconfig--add name: Add a new service. Chkconfig ensure that each run level has a start (S) or Kill (K) entry. If one is missing, it is automatically created from the default init script.
    chkconfig--del Name: Delete the service and remove the associated symbolic connection from/ETC/RC[0-6].D.
    chkconfig [--level levels] Name: Sets whether a service is started, stopped, or reset at the specified run level.

6. Operation 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 run level of the default startup and the priority of start and stop. If a service does not start at any run level by default, use-instead of run-level. The second line describes the service, which you can annotate with \ cross-line.
For example, Random.init contains three rows:
# chkconfig:2345 20 80
# description:saves and restores system entropy pool for \
# higher quality random number generation.

Examples of Use:
Chkconfig--list #列出所有的系统服务
Chkconfig--add httpd #增加httpd服务
Chkconfig--del httpd #删除httpd服务
Chkconfig--level 2345httpdOn #设置httpd在运行级别为2, 3, 4, 5 in the case of On (open) state
Chkconfig--list #列出系统所有的服务启动情况
Chkconfig--list mysqld #列出mysqld服务设置情况
Chkconfig--level mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35 means that the operation is performed only on levels 3 and 5, on means start, off means off
Chkconfig mysqld on #设定mysqld在各等级为on, "each level" includes 2, 3, 4, 5 ratings

7, how to add a service: Take mysqld as an example
(1), the service script must be stored in the/etc/init.d/directory;
(2), Chkconfig--add mysqld #添加服务, in the Chkconfig tool Service list to add this service, at this time the service will be in/ETC/RC.D/RCN.D to give k/s entrance;
(3), Chkconfig--level mysqld on # Modify the default boot level for the service.


Second, the start/close of the service

1, System services: has been in memory, and has been running, and provide services are called services;

2, and the service is also a running program, then this running program is called daemons;

3, The startup scripts for these services are generally placed in: / etc/init.d

4. service startup Scripts in CentOS are 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,/etc/sysconfig Service initialization environment variable configuration is in this file.

6,/var/lib each service generated database in this directory, the simplest here to find MySQL using vim to open can see, you build the database and the system generated by default database name are in here!

7.

8. Start/Stop/Restart service:/etc/init.d/servername start/stop/restart/status

9. Start/Stop/restart Services: Service ServerName Start/stop/restart Why do you write this?

10, the service is a script he can analyze the parameters you issued later, and then according to your parameters in the/ETC/INIT.D down to get the right service to stop start restart

Linux under the Chkconfig command to add services and two ways to start shutdown system services

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.