chkconfig


Detailed explanation of the chkconfig command under Linux The chkconfig

command is mainly used to update (start or stop) and query the run-level information of system services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symlink.

Usage syntax:
chkconfig [--add][--del][--list][system service] or chkconfig [--level <level code>][system service][on/off/reset]

chkconfig is run without parameters When the usage is displayed. If you add a service name, then check if the service is started in the current runlevel. If yes, return true, otherwise return false. If on, off or reset is specified after the service name, chkconfi will change the startup information for the specified service. on and off refer to the service being started and stopped, respectively, and reset refers to resetting the service's startup information, regardless of what the init script in question specifies. The on and off switches are only valid for run levels 3, 4, and 5 by default, but reset can be valid for all run levels.

Parameter usage:
   --add adds the specified system service, allows the chkconfig command to manage it, and adds related data to the system startup narrative file.
   --del Deletes the specified system service, which is no longer managed by the chkconfig command, and deletes related data in the system startup narrative file.
   --level<level code> Specifies in which execution level the read system service should be enabled or disabled.
      Level 0 means: Indicates 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 with network connection
      Level 4 means: Unavailable
      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, 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.

    chkconfig --list [name]: Displays running status information (on or off) of all run-level system services. If name is specified, then only the status of the specified service at different runlevels is displayed.
    chkconfig --add name: Add a new service. chkconfig ensures that each runlevel has a start (S) or kill (K) entry. If missing, it will be created automatically from the default init script.
    chkconfig --del name: Delete the service and delete the related symbolic link from /etc/rc[0-6].d.
    chkconfig [--level levels] name: Sets whether a service is started, stopped or reset at the specified run level.

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 by default in any runlevel, 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 run level is 2, 3, 4, and 5
chkconfig --list #List all the system service startup status
chkconfig --list mysqld #List mysqld service settings
chkconfig --level 35 mysqld on #Set mysqld to run at level 3 and 5 as the startup service, --level 35 means that the operation is only performed at levels 3 and 5, on means start, off means close
chkconfig mysqld on #Set mysqld to be on at each level, and "levels" include levels 2, 3, 4, and 5.

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033224&siteId=291194637