linux chkconfig manually create a self-starting script

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 shows usage when run with no arguments. 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 at the same time adds related data to the system startup description 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: With The multi-user mode level 6 of the graphical interface
      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.

    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 of use:
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 run level 2, 3, In the cases of 4 and 5, they are all on (open)
chkconfig --list #List all the service startups of the system
chkconfig --list mysqld #List the mysqld service settings
chkconfig --level 35 mysqld on #Set mysqld At levels 3 and 5, it is the startup service, --level 35 means that the operation is only performed at levels 3 and 5, on means to start, off means to close
chkconfig mysqld on #Set mysqld to on at each level, and "each level" includes 2 , 3, 4, 5 grades

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, and the service will be listed in /etc/rc. The K/S entry is given in d/rcN.d;
3.chkconfig --level 35 mysqld on
    modifies the default startup level of the service.

Guess you like

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