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:

Detailed explanation of each run level:

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: