Add a self-made STARTUP script to chkconfig for Automatic startup

Source: Internet
Author: User
Tags stop script

Through the on-site commissioning of the Tianjin IPTV Demo project, a better understanding and understanding of the IPTV system, the IPTV itself needs to install a lot of services, and whether these needs to be started during the on-site implementation add the service script to the automatic running upon startup. If the server needs to be manually restarted...

Connect
On-site access to Tianjin IPTV
Demo project commissioning, a better understanding and understanding of the IPTV system, because IPTV itself needs to install a lot of services, and whether these scripts for starting services are added to the on-site implementation
During automatic machine running, if many services need to be manually started after the server is restarted, and the work and future maintenance are relatively cumbersome, the knowledge and methods involved in the script for Automatic startup of Linux are summarized.,
As follows:

1. Basic knowledge points

1) The RedHat Startup Mode and execution sequence are as follows:

Load the kernel

Run the INIT program

/Etc/rc. d/rc. sysinit # The first script executed by init

/Etc/rc. d/RC $ runlevel # $ runlevel is the default running mode.

/Etc/rc. d/rc. Local # after the corresponding level of service is started, execute the file (in fact, you can also write the command to be executed to this file)

/Sbin/mingetty # Wait for User Login

 

In RedHat,/etc/rc. d/rc. sysinit mainly performs the same initialization in each running mode, including:

Incoming keymap and system font

Start swapping

Set Host Name

Set the NIS domain name

Check (fsck) and mount the File System

Open quota

Mount sound card module

Set system clock

And so on.

/Etc/rc. d/RC executes scripts in the corresponding directory according to the running mode specified by its parameters (the running level, which can be set in the inittab file. Anything that starts with kxx

All are called with the Stop parameter. All parameters starting with sxx are called with the start parameter. The call order is XX.

From small to large. (XX indicates the Starting sequence.) For example, if the default running mode is 3,/etc/rc. d/RC calls

Scripts under/etc/rc. d/rc3.d.

It is worth mentioning that the running Modes 2, 3, and 5 in RedHat use/etc/rc. d/rc. Local as the initialization script.

The last one, so you can add some commands that need to be executed before logging on to the file.

 

Init is waiting for/etc/rc. d/RC to complete the execution (because/etc/inittab/etc/rc. d/RC

The action is wait). It runs/sbin/mingetty on the specified virtual terminal and waits for the user to log on.

So far, the Linux Startup has ended.

2) Init running level and command

1. What is INIT:

Init is an indispensable program in Linux.

The INIT process is a user-level process started by the kernel.

After the kernel is started by itself (it has been loaded into the memory, started to run, and initialized to all the device drivers and data structures), it starts a user-level program init, complete the boot process. Therefore, init is always the first process (its process number is always 1 ).

In the past, the kernel used init to find it. The correct position (for Linux) is/sbin/init. If the kernel cannot find init, it will try to run/bin/sh. If the run fails, the system will also fail to start.

Ii. Operation Level

So what is the runtime level?

Simply put, the running level is the function level currently running in the operating system. This level ranges from 1 to 6 and has different functions.

Different runtime levels are defined as follows:

#0-stop (never set initdefault to 0)

#1-single-user mode # s init S = init 1

#2-multiple users without NFS

#3-full multi-user mode (Standard Operation Level)

#4-useless

#5-X11 multi-user graphic mode (XWindow)

#6-Restart (do not set initdefault to 6)

This
Some levels are specified in the/etc/inittab file. This file is the main file found by the INIT program. The first service to run is put in/etc/rc. d.
Directory. In most Linux releases, the startup script is located in/etc/rc. d/init. d. These scripts are connected with LN commands.
/Etc/rc. d/rcN. d directory. (Here N is the running level 0-6)

3): The chkconfig command (in the RedHat operating system)

Unlike DoS or windows, Linux can have multiple running levels. Common examples are 2, 3, 4, and 5 of multiple users. Many people know that 5 is running X-Windows.
And 0 is shut down. You can use the init command to change the running level. For example, if you want to maintain the system to enter the single-user status, you can use init 1
To switch. During the Linux running-level switch process, the system will automatically find the corresponding running-level directory K and S under/etc/rc [0-6]. d
Execute the scripts in the numerical order. The maintenance of these scripts is very cumbersome. Linux provides chkconfig
Command is used to update and query system services at different running levels.

Syntax:

 

Chkconfig -- list [name]

Chkconfig -- add name

Chkconfig -- del name

Chkconfig [-- level levels] Name

Chkconfig [-- level levels] Name

 

Chkconfig has five functions: Add a service, delete a service, list a service, change the startup information, and check the startup status of a specific service.

 

When chkconfig does not have a parameter for running, the usage is displayed. If the service name is added, check whether the service is started at the current running level. If yes, true is returned; otherwise, false is returned. The -- level option specifies the running level to be viewed, not necessarily the current running level.

 

If on, off, or reset is specified after the service name, chkconfig changes the startup information of the specified service. On and off indicate the start and stop of the service when the running level is changed. Reset refers to the initialization service information, no matter what is specified by the problematic initialization script.

 

For ON and OFF switches, the system is only valid for 3, 4, and 5 by default, but the reset can be valid for all running levels. You can select a specific running level when the -- level option is specified.

 

It must be noted that for each running level, there can be only one start script or stop script. When you switch to the running level, init does not restart the started service or stop the stopped service again.

 

Options:

 

-- Level levels

A running-level string consisting of numbers 0 to 7, for example:

 

-- Level 35 indicates the running level 3 and 5.

To stop the NFS service at running levels 3, 4, and 5, run the following command: chkconfig -- level 345 NFS off.

 

-- Add name

This option adds a new service. chkconfig ensures that each running level has a startup (s) or kill (k) entry. If the init script is missing, it is automatically created from the default init script.

 

-- Del name

Delete a service and delete the connection from/etc/rc [0-6]. D.

 

-- List name

List. If the name is specified, only the specified service name is displayed. Otherwise, the status of all services at different running levels is listed.

 

Running files

 

Each service managed by chkconfig needs to add two or more lines of comments to the script in the corresponding init. d.

The first line tells chkconfig the default startup running level and the priority of start and stop. If a service is not started at any running level by default, use-to replace the running level.

The second line describes the service and can be annotated across rows.

 

For example, random. init contains three rows:

# Chkconfig: 2345 20 80

# Description: saves and restores system entropy pool

# Higher quality random number generation.

It indicates that the random script should be started at runtime Level 2, 3, 4, 5. The start priority is 20, and the Stop priority is 80.

 

Now, let's take a look at the script under/etc/rc. d/init. d In your directory.

 

Set auto-start service: chkconfig -- level 345 NFS on

 

2. instance introduction:

1. Install the apache service (by downloading binary files for economical compilation and installation, rather than RPM packages) and the apache service startup command in Linux:
/Server/Apache/bin/apachectl start. Run the apache service under runlevel 3. The command is as follows:

 

1) Touch/etc/rc. d/init. d/Apache

VI/etc/rc. d/init. d/Apache

Chown-r root/etc/rc. d/init. d/Apache

Chmod 700/etc/rc. d/init. d/Apache

Ln-S/etc/rc. d/init. d/Apache/etc/rc. d/rc3.d/s60apache # s
Is short for START, indicates start, K is short for kill, and indicates to close. 60 digits
Indicates the order of startup. (For the IPTV system, many services can be started normally only when the database is started. You can adjust the script startup sequence with this number ))

 

Apache content:

#! /Bin/bash

# Start HTTPd service

/Server/Apache/bin/apachectl start

 

Now the apache service can be automatically started at random under runtime Level 3. (You can adjust the startup service with chkconfig)

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.