Linux boot service and Chkconfig use method (custom service path start)

Source: Internet
Author: User

  1. Service Overview
    Under the Linux operating system, it is often necessary to create services that are made into shell scripts that need to be started automatically when the system is started and shut down automatically when it is shut down.
    You will need to automatically start the script in the/ETC/RC.D/INIT.D directory and then use the command chkconfig--add filename to automatically register the boot and shutdown shutdown. The essence is to generate some file connections in the RC0.D-RC6.D directory that connect to the shell script for the specified file in the/ETC/RC.D/INIT.D directory.

    Oracle Auto Start and stop under article Linux (i),Oracle Auto Start and stop under Linux (ii) There are some descriptions for creating services.
  2. Create a service manually
    Create a shell script under the/ETC/RC.D/INIT.D directory, with the file name Auto_run.
    Set the script's run permissions chmod +x auto_run.
    The file connection is then created separately under the RC0.D-RC6.D directory.
    Ln-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc2.d/s99auto_run
    Ln-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc3.d/s99auto_run
    Ln-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc5.d/s99auto_run
    Ln-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc0.d/k01auto_run
    Ln-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc6.d/k01auto_run

    When the system starts, it runs the Auto_run and adds the start parameter, which is equivalent to executing the command auto_run start.
    When the system shuts down, Auto_run is run and the stop parameter is added, which is equivalent to running the command Auto_run stop.

    The 6 commands for creating a connection can be done with the command chkconfig--add Auto_run, which is much simpler and less prone to error.
    Here's an introduction to the Chkconfig command.
  3. Chkconfig command Usage
    Grammar:
    Chkconfig--list [Name]
    Chkconfig--add Name
    Chkconfig--del Name
    Chkconfig [--level levels] name <on|off|reset>
    Chkconfig [--level levels] Name

    Description
    Chkconfig provides a simple command-line tool to help administrators directly manipulate numerous symbolic links under the/ETC/RC[0-6].D directory hierarchy.
    This command is used by the Chkconfig command to provide authorization on the IRIX operating system. Instead of maintaining configuration information directly under the/ETC/RC[0-6].D directory, you manage the linked files directly under/etc/rc[0-6]. The configuration information in the run-level directory notifies you of which services will be started initially.
    Chkconfig has five distinct features: Adding a new feature to the management, removing a feature, listing the startup information for the current service, changing the startup information for a service, and detecting the startup status of a particular service.
    When Chkconfig runs without parameters, it displays how it is used. If only one service name is given, it will detect if the service name has been configured to the current runlevel. If it is already configured, returns TRUE, otherwise false. The--level option can be used to query multiple runlevel rather than just one.
    If on is specified after the service name, off or reset,chkconfig changes the startup information for the specified service. The on or off flag service is opened or stopped, especially when the runlevel is changed. The reset flag resets the service's startup information.
    By default, the on or off option affects only 2, 3, 4, and 5, and reset affects all run levels. The--level option can be used to specify which RunLevel receives the impact.
    Note: For each service, there is a start and an end angle for each run level. When a run level is on or off, Init does not restart a service that is already running and does not stop a service that is not running.
    Options:
    --level levels
    Specifies an operation that is appropriate for the run level. The range is 0-7.
    --add Name
    Add a new service.
    --del Name
    Delete a service
    --list Name
    Display the service situation
    RUNLEVEL FILES
    Each service managed by Chkconfig requires two or more lines of comments in the corner book under its INIT.D directory. The first line tells Chkconfig what run-level services can start by default, that is, the start or end priority level. If the service does not have a default level, the build will start at all RunLevel. A– will be used instead of Run level list (not quite sure, test Zabbix startup script, K only in 0/1/6, s only in 2/3/4/5)。 The second comment line includes a description of the service, which can be expanded to multiple lines by means of a backslash symbol.

    Example, the first three lines of Auto_run are as follows:
    #!/bin/sh
    #chkconfig: 2345
    #description: Auto_run
    The first line tells the system to use the shell, so the shell script is like this.
    the second line, chkconfig after the three parameters 2345,80 and 90 tells the Chkconfig program, need to RC2.D~RC5.D directory, create a file name S80auto_run, connect to/etc/rc.d/ Auto_run script in the INIT.D directory。The first character is S, when the system starts , run the script auto_run, it will add a start parameter, tell the script, is now the startup mode。 Also in the RC0.D and RC6.D directories,Create a file connection named K90auto_run, the first character is K, a system shuts down the system, it runs Auto_run, adds a stop, tells the script, is now off mode.
    Note that the above three lines are in, the ground two, the third row is necessary, otherwise when running Chkconfig--add Auto_run, will be error.
  4. Common Mistakes
    " service does not support Chkconfig":
    Please note that there are two full lines in front of the check script:
    #chkconfig: 2345 80 90
    #description: Auto_run
    In front of the script these two lines are not few, otherwise cannot chkconfig the command will report the error.
    If the running Chkconfig always error, if the script is not a problem, I suggest, directly under RC0.D~RC6.D to create a file connection to the script to resolve, the principle is the same.
  5. --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------
  6. The first part is the comment section, which shows that this script can be managed by the Chkconfig tool. Here is an example:
    #!/bin/bash## chkconfig 345 10 90
    # Description This was where you put a description of your service
    In this example, the number 345 after Chkconfig represents the level at which the default runs. In this example, the service will start at Level 3, 4, and 5.
    The number 10 represents the priority level of the startup. The lower the number, the higher the priority. The number 90 represents the priority level of the shutdown. The lower the number, the higher the priority.

Linux boot service and Chkconfig use method (custom service path start)

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.