Learn a Linux command every day (92): chkconfig

Time:2021-4-27

Recommended reading:Learn a Linux command every day (91): NC

Command introduction

Chkconfig command is used to manage the boot items of Linux system

Grammatical format

chkconfig [options] 

Option description

--add    # Add the specified system service
--del   # Delete the specified system service
--Level < level code >   # Specifies the execution level at which the read system service should be turned on or off

The default run level, which is used by RHS, is as follows:

  • 0: power off
  • 1: Single user mode
  • 2: Multi user mode without network support
  • 3: Multi user mode with network support
  • 4: Reserved, not used
  • 5: Multi user mode with network support and X-window support
  • 6: Reboot the system, that is, restart

Run level file

Each service managed by chkconfig needs two or more lines of comments in the corresponding init. D script. The first line tells chkconfig which run level to start by default and which priority to 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 can be annotated across lines.

# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to 
#       start at boot time.

Application examples

List all system services

[[email protected] ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
netconsole      0:off 1:off 2:off 3:off 4:off 5:off 6:off
network         0:off 1:off 2:on 3:on 4:on 5:on 6:off

Other examples

[ [email protected]  ~]#  chkconfig  -- add   httpd         # Add httpd service
[ [email protected]  ~]#  chkconfig  -- del   httpd         # Delete httpd service
[ [email protected]  ~]#  chkconfig  -- level   httpd   two thousand three hundred and forty-five   on     # Set httpd to be on when running level is 2, 3, 4 and 5
[ [email protected]  ~]#  chkconfig  -- list   httpd        # List the httpd service settings
[ [email protected]  ~]#  chkconfig  -- level   thirty-five   httpd   on  # Set httpd at Level 3 and level 5 as the startup service
[ [email protected]  ~]#  chkconfig   httpd   on     # Set httpd to on at each level
 
[ [email protected]  ~]#  chkconfig  – level   redis   two thousand three hundred and forty-five   on  # When the running level of redis is 2, 3, 4 and 5, it is on

Note: when adding a service, the service startup script must be stored in / etc / init.d/directory.

Learn a Linux command every day (90): Kill / kill

Learn a Linux command every day (86): time

Learn a Linux command every day (85): watch