Linux Chkconfig startup program order

Source: Internet
Author: User
Tags data structures file system reset stop script

1 The starting mode and execution order of Redhat are:

Loading the kernel to execute the INIT program

/etc/rc.d/rc.sysinit # The first script executed by Init

/ETC/RC.D/RC $RUNLEVEL # $RUNLEVEL is the default run mode

/etc/rc.d/rc.local #相应级别服务启动之后, executing the file (you can actually write the command you want to execute into the file)/sbin/mingetty # Waiting for the user to log in

In Redhat,/etc/rc.d/rc.sysinit mainly do the same initialization work in various running modes, including: Dial in Keymap and system font startup swapping setting hostname setting NIS domain name

Check (fsck) and Mount file system open Quota load sound module set system clock and so on.

/ETC/RC.D/RC the running mode (run level, which you can set in the Inittab file) according to its parameters to execute the script in the corresponding directory.

Those who start with the kxx are called by the Stop argument, and all start with the sxx as arguments.

The order of the calls is performed in XX from small to large.

(where xx is a number, indicating the boot order) For example, suppose that the default mode of operation is 3,/ETC/RC.D/RC, which is invoked as described above

/etc/rc.d/rc3.d/under the script.

It is worth mentioning that the operating modes in Redhat 2, 3, and 5 all have/etc/rc.d/rc.local as initialization scripts

, so the user can add some commands to the file that need to be executed before they log on after other initialization work. Init waits for/ETC/RC.D/RC execution (because the/ETC/RC.D/RC in/etc/inittab

Action is wait), the/sbin/mingetty will be run on each virtual terminal specified, waiting for the user to log on. At this point, Linux startup is over.

2 init run level and instruction one, what is init:

Init is one of the most indispensable programs in Linux system operations.

The so-called init process, which is a user-level process initiated by the kernel.

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

The kernel finds it in several places in the past that have used Init, and its correct location (for Linux systems) is/sbin/init. If the kernel cannot find Init, it will try to run/bin/sh, and if the operation fails, the system will fail to start.

Second, the operation level

So, what is the run level?

Simply put, the run level is the level of functionality that the operating system is currently running.

This level, from 1 to 6, has different functions. The different run levels are defined as follows

# 0-Downtime (never set the Initdefault to 0)

# 1-Single user mode # s init s = init 1

# 2-Multiuser, no NFS

# 3-Full multiuser mode (standard run level)

# 4-No use

# 5-x11 Multi-user graphics mode (xwindow)

# 6-Reboot (don't set the Initdefault to 6)

These levels are specified in the/etc/inittab file.

This file is the primary file that the INIT program is looking for, and the first service to run is

Files in the/ETC/RC.D directory.

In most Linux distributions, startup scripts are located in/etc/rc.d/init.d.

These scripts are connected to the/ETC/RC.D/RCN.D directory using the ln command. (Here's n is run level 0-6) 3):

---------------------------

The Chkconfig command is used primarily to update (start or stop) and to 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 Services] or Chkconfig [--level < rank code >][system Services][on/off/reset]

Chkconfig Displays the usage when no parameters are running. If you add a service name, check to see if the service is starting at the current run level. Returns true if it is, or false. If On,off or reset is specified after the service name, CHKCONFI changes the startup information for the specified service. On and off means that the service is started and stopped, and reset refers to resetting the service's startup information, regardless of what the initialization script for the problem specifies. On and off switches, the system defaults to run-level 3,4,5 only, but reset can be valid for all run levels.

Parameter usage:

--add adds the specified system service, allows the chkconfig instruction to manage it, and adds the relevant data to the system-initiated narrative file.

--del deletes the specified system service, is no longer managed by the Chkconfig command, and deletes the relevant data in the system-initiated narration file.

--level< Level Code > Specify the system service to be opened or closed in which execution level.

Level 0 means: the shutdown

Level 1: Single user mode

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

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

Level 4 indicates: Not available

Level 5 means: Multi-user mode with graphical interface

Level 6 indicates: reboot

It is necessary to note that the level option can specify the run levels to view, not necessarily the current run level. For each run level, there can be only one startup script or stop script. When the run level is switched, Init does not restart the service that has started, nor does it stop the service that has stopped.

Chkconfig--list [name]: Displays the running status information (on or off) for all run-level system services. If name is specified, only the state of the specified service at a different run level is displayed.

Chkconfig--add Name: Add a new service. Chkconfig ensure that each run level has a start (S) or Kill (K) entry. If it is missing, it is automatically created from the default init script.

Chkconfig--del Name: Deletes the service and deletes the associated symbol connection 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 files:

Each service managed by Chkconfig needs to be annotated with two or more lines of script under the corresponding INIT.D. The first line tells Chkconfig the run level of the default boot and the priority of start and stop. If a service does not start at any run level by default, then use-instead of run level. The second line describes the service, and you can use a cross row annotation.

For example, Random.init contains three lines:

# chkconfig:2345 20 80

# description:saves and restores system entropy pool for

# higher quality random number generation.

Use Example:

Chkconfig--list #列出所有的系统服务

Chkconfig--add httpd #增加httpd服务

Chkconfig--del httpd #删除httpd服务

Chkconfig--level httpd 2345 on #设置httpd在运行级别为2, 3, 4, 5 in the case of the on (open) state

Chkconfig--list #列出系统所有的服务启动情况

Chkconfig--list mysqld #列出mysqld服务设置情况

Chkconfig--level mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35 indicates that operations are performed only on levels 3 and 5, on is started, off is off

Chkconfig mysqld on #设定mysqld在各等级为on, "each level" includes 2, 3, 4, 5 levels

How to add a service:

1. Service scripts must be stored in the/etc/ini.d/directory;

2.chkconfig--add ServiceName

Add this service to the Chkconfig tool Services list, at which point the service is given a k/s entry in the/ETC/RC.D/RCN.D;

3.chkconfig--level mysqld on

Modify the default boot level for the service.

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.