Linux Custom boot service and Chkconfig usage

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.

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/-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc3.d/-S/ etc/rc.d/init.d/auto_run/etc/rc.d/rc5.d/-s/etc/rc.d/init.d/auto_run/etc/rc.d/rc0.d/-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. The A – will be used instead of the run-level list. 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/2345#description: Auto_run


The first line tells the system to use the shell, and all shell scripts are 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/ The Auto_run script under 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. At the same time in the RC0.D and RC6.D directory, create a file connection named K90auto_run, the first character is K, when the system shuts down the system, it will run Auto_run, add a stop, tell the script, is now off mode.
Note that in the above three rows, the second, the third line is required, otherwise, when running Chkconfig--add Auto_run, an error will be shown.

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.

Linux Custom boot service and Chkconfig usage

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.