Linux common commands: chkconfig command

  The chkconfig command is used to install, view or modify the settings of the startup options that the services start with the system. It is a program developed by Red Hat in accordance with the GPL rules. It can query which system services the operating system will execute in each execution level, including various resident services.
  Note:  keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symlink.
  Every service managed by chkconfig must first add them in /etc/init.d.

1. Command format:

  chkconfig [required parameter] [service]

2. Command function:

  View or modify the settings of the startup options that services start with the system

3. Command parameters:

1) --add opens the specified service program
2) --del closes the specified service program
3) --list lists all services known by chkconfig
4) --level<code> Set the level code of the service program, which is a A string of numbers from 0 to 7

4. Example of use:

Example 1: View the list of system programs

[root@localhost ~]# chkconfig --list

Note: This output only shows SysV services, not native systemd services. SysV configuration data may be overwritten by native systemd configuration.
      If you want to list systemd services, execute ' systemctl list-unit-files ' .
      To see the services enabled for a specific target execute
      'systemctl list-dependencies [target]'

netconsole          0 :     off1 : off2 : off3 :     off4 :     off5 :     off6 :     off    
network             0 : off     1 : off     2 : on     3 : on     4 : on     5 : on     6 : off

xinetd-based services:
    chargen - dgram: off
    chargen - stream: off
    daytime-dgram:     关
    daytime - stream: off
    discard - dgram: off
    discard - stream: off
     echo - dgram: off
     echo - stream: off
    tcpmux - server: off
     time - dgram: off
     time -stream: off

 



Example 2: Check the setting of the service's startup options in a shell script

[root@localhost ~]# chkconfig network && echo "Network service is configured"
Network service is configured

 

      When you execute chkconfig with the service name, it will return true if the service is configured to start automatically.

[root@localhost ~]# chkconfig xinetd
Note: Requests are being forwarded to "systemctl is - enabled xinetd.service".
enabled
[root@localhost ~]# chkconfig xinetd
Note: Requests are being forwarded to "systemctl is - enabled xinetd.service".
enabled

 


Example 3: Add or remove specified services

[root@localhost /]# chkconfig --del netconsole
[root@localhost /]# chkconfig --add netconsole

 


5. Others:
1) Level code list:
  Level 0 means: shutdown
  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   level
  with network connection
4 means: not available
  Level 5 means: multi-user mode with graphical interface
  Level 6 means: restart
    It should be noted that the level option can specify the run level to be viewed and not necessarily the current run level. For each runlevel, there can be only one start script or stop script. When switching runlevels, init will not restart services that have already been started, nor will it stop services that have been stopped again.
2) 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 startup runlevel and start and stop priorities. If a service is not started in any runlevel by default, use - instead of runlevel. The second line describes the service and can be commented with \ across lines.









Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325944910&siteId=291194637