Shell script installed as service join system boot-service XX does not support Chkconfig

Source: Internet
Author: User


Background: Shell scripting is an essential tool for Linux OPS, and it is important to install shell scripts as a service and join the system to start and then manage them using services.


When we run the command to install the service, assume that the service name is MyService

#chkconfig--add MyService

Will often appear

Service MyService does not support Chkconfig



The correct method is explained below:



1.1 Add a comment to the service script.


#vim/etc/init.d/myservice

Add the following two sentences to #!/bin/bash.

# chkconfig:2345 # Description:myservice .... The first line tells Chkconfig the run level of the default startup and the priority of 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 you can annotate with \ cross-line.

Where 2345 is the default boot level, with a level of 0-6 and a total of 7 levels.

Level 0 means: shutdown

Level 1 means: Single user mode

Level 2: Multi-user command line mode with no network connection

Level 3 means: Multi-user command line mode with network connection

Level 4 means: not available

Level 5 means: Multi-user mode with graphical interface

Level 6 means: reboot

10 is the start priority, 90 is the stop priority, the priority range is 0-100, the greater the number, the lower the priority.


1.2 Service scripts must be stored in the/etc/ini.d/directory; 1.3 chkconfig--add ServiceName Add this service to the Chkconfig tool Services list, where the service is given/ETC/RC.D/RCN.D entry in k/s; 1.4 Chkconfig--level 2345 ServiceName on modifies the default boot level of the service.




Second, there are several issues to note:


1) standard structure of the startup script:


Case "$" in start) do start-thing;    ;;        stop) do stop-thing;    ;;        restart) do restart-thing;    ;; ... esac If you use this structure to write a startup script test, you will find that if the script's soft connection starts with S, then the system starts execution of the start-thing code snippet, if the script's soft connection starts with K, The stop-thing code snippet is executed at system startup (with the exception of run level 0, because the 0 level is to shut down the system, so a soft connection starting with S in/etc/rc0.d/also executes the stop-thing segment). is not very intelligent, so if you can start the script is best to write standard some. If you are not written as a normal script, just a few commands, without the structure above, how do you create a soft connection that starts with K or S? The answer is to do it all. 2) Chkconfig

the Chkconfig command is primarily used to update (start or stop) and query run-level information for system services. keep in mind that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection.

Use syntax:

chkconfig [--add][--del][--list][ system service ] or chkconfig[--level < level code >][ system service ] [On/off/reset]

Chkconfig Displays the usage when no parameters are running. If the service name is added, check that the service is started at the current run level. If yes, returns true, otherwise false is returned. If on ,off or reset is specified after the service name, then chkconfig Changes the startup information for the specified service. on and off refers to the service being started and stopped,and reset refers to the boot information of the reset service, regardless of what is specified by the problematic initialization script. on and off , the system is only valid for run-level 3,4,5 by default , but reset Can be valid for all run levels.

Examples of Use:

Chkconfig--list # List of all system services

Chkconfig--add httpd # Add httpd service

Chkconfig--del httpd # Delete httpd service

Chkconfig--level httpd 2345 on # set httpd at run level 2,3,4,5 on (open) State

Chkconfig--list # Lists all service startup conditions for the system

Chkconfig--list mysqld # list of mysqld service settings

Chkconfig--level mysqld on # set mysqld at levels 3 and 5 for power -on service,--level35 indicates that the operation is only in the rank 3 and 5 Execute,on indicates start,off indicates off

Chkconfig mysqld on # settings mysqld on each level , "Each level" includes 2,3,4, 5 Ratings

The/etc Directory has a set of RC start-up directories , which are used to store services that are automatically started by Linux at various operating levels :

/etc/rc0.d/# services that need to be started in run mode 0

/etc/rc1.d/# services that need to be started in run mode 1

/etc/rc2.d/# services that need to be started in run mode 2

/etc/rc3.d/# services that need to be started in run mode 3

/etc/rc4.d/# services that need to be started in run mode 4

/etc/rc5.d/# services that need to be started in run mode 5

/etc/rc6.d/# services that need to be started in run mode 6

These directories are in addition to the README documentation is all about soft links ( Symbolic Links ) that point to the process management scripts for each service , which are placed in the/ETC/INIT.D directory .

with chkconfig command operation add or remove boot automatically start the service program , . " uppercase S+ script name ', There's a link in it " S20rc.local. /init.d/rc.local ". Open the script it points to /etc/init.d/rc.local look , found it called /etc/rc.local this script . .

If you put the startup command for the MySQL service into /etc/rc.local, the operating system will execute it when the list is executed , but the order of execution is 20, than in the front row S17mysql is a bit late .

Chconfig--level 2345 puppet off is equivalent to chkconfig puppet off ( default is--level when not 2345 specified level)

This command is to set the puppet service to not start automatically at the 2345 level, and when this command is executed, the

RC2.D rc3.d rc4.d rc5.d These directories new soft connect k02puppet script from /etc/rc.d/init/puppet

Chkconfig puppet on this is when the 2345 level, boot automatically start

When this command is executed, the

RC2.D rc3.d rc4.d rc5.d These directories new soft connect s98puppet script from /etc/rc.d/init/puppet

then this How did K02puppet and 98 in the S98puppet ?

Open /etc/rc.d/init.d/puppet This script file to see the first few lines as follows:

#!/bin/bash

# puppet Init script for running the puppetclient daemon

#

# Author:duane Griffin

# David Lutterkort

#

# Chkconfig:-98 02

#

# Description:enables Periodic systemconfiguration checks through puppet.

# Processname:puppet

# config:/etc/sysconfig/puppet

Especially in this line.

# Chkconfig:-98 02

The Chkconfig command reads this line to get the RunLevel and the 2 numbers in this script





This article is from the "Technical Achievement Dream" blog, please be sure to keep this source http://pizibaidu.blog.51cto.com/1361909/1795909

Shell script installed as service join system boot-service XX does not support Chkconfig

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.