TrumanWong

chkconfig

Check or set various services of the system

Supplementary instructions

chkconfig command Check and set various services of the system. This is a program developed by Red Hat in compliance with GPL rules. It can query what system services the operating system will execute in each execution level, including various resident services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symbolic link.

grammar

chkconfig(options)

Options

--add: Add the specified system service so that the chkconfig command can manage it, and at the same time add relevant data to the system startup narrative file;
--del: Delete the specified system service, which is no longer managed by the chkconfig command, and delete related data in the system startup narrative file at the same time;
--level <level code>: Specify the execution level in which the read system service should be turned on or off.

The default runlevels used by RHS are as follows:

  • 0: Shut down *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

Detailed explanation of each run level:

  • 0 means shutdown, the machine is shut down.
  • 1 is single-user mode, similar to the safe mode under Win9x.
  • 2 is multi-user mode, but does not support NFS.
  • 3 is the complete multi-user mode and is the standard run level.
  • 4 Generally not used, you can use it to do some things in some special circumstances. For example, when the laptop battery is exhausted, you can switch to this mode to make some settings.
  • 5 is X11, entering the X Window system.
  • 6 is a restart, the machine will restart after running init 6.

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 run levels, init will not restart already started services, nor will it stop stopped services again.

Run-level files:

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

For example random.init contains three lines:

# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.

Example

chkconfig --list #List all system services.
chkconfig --add httpd #Add httpd service.
chkconfig --del httpd #Delete httpd service.
chkconfig --level httpd 2345 on #Set httpd to be on (open) when the running level is 2, 3, 4, or 5.
chkconfig --list # List all service startup status of the system.
chkconfig --list mysqld # List the mysqld service settings.
chkconfig --level 35 mysqld on # Set mysqld to run services on startup at levels 3 and 5. --level 35 means that the operation will only be executed at levels 3 and 5. On means startup, and off means shutdown.
chkconfig mysqld on # Set mysqld to on at each level. "Each level" includes levels 2, 3, 4, and 5.

chkconfig –level redis 2345 on # Turn redis on when the running level is 2, 3, 4, or 5.

How to add a service:

  1. The service script must be stored in the /etc/ini.d/ directory;
  2. chkconfig --add servicename adds this service to the chkconfig tool service list. At this time, the service will be given a K/S entry in /etc/rc.d/rcN.d;
  3. chkconfig --level 35 mysqld on modifies the default startup level of the service.