Redhat9.0/etc/rc. d/RC program Annotation

Source: Internet
Author: User

#! /Bin/bash

#

# RC this file is responsible for starting/stopping

# Services when the runlevel changes.

#

# Original Author:

# Miquel van smoorenburg, <miquels@drinkel.nl.mugnet.org>

#

 

# Check a file to be a correct runlevel script

Check_runlevel ()

{

# Check ifthe file exists at all.-X: checks whether the file name has executable attributes.

[-X "$1"] | return 1

 

# Rejectbackup files and files generated by rpm.

Case "$1" in

*. Rpmsave | *. rpmorig | *. rpmnew | *~ | *. Orig)

Return1

;;

Esac

Return 0

}

 

# Now find out what the current and what the previusrunlevel are.

Argv1 = "$1"

Set '/sbin/runlevel' # Set a B: $1 = A, $2 = B, $ # = 2

# Runlevel result: N 5, indicating the previous running level N (none), the current running level is 5

# In addition, '/sbin/runlevel' can be replaced by $ (/sbin/runlevel ).

Runlevel = $2

Previous = $1

Export runlevel previous

 

./Etc/init. d/functions

# The functions file defines some functions, such as checkpid (), daemon (), killproc (),

# Pidfileofproc (), pidofproc (), status (), echo_success (), echo_failure ()

# Echo_passed (), echo_waring (), success (), failure (), passed (), warning ()

# Action (), strstr (), confirm (),

#./Etc/init. d/functions indicates to execute the functions command in the current shell.

# The function definition in the file is read to the current shell.

 

# See if we want to be in user confirmation Mode

#-F whether the "file name" is a file | if the previous execution fails, continue with the execution next to it; otherwise, do not execute

# Grep-I indicates that the case sensitivity is ignored.

If ["$ previous" = "N"]; then

If [-F/var/run/confirm] \

| Grep-I confirm/proc/cmdline>/dev/NULL; then

Rm-F/var/run/confirm

Confirm = Yes

Exportconfirm

Echo $ "entering interactive startup"

Else

Echo $ "entering non-interactive startup"

Fi

Fi

 

# Get first argument. Set new runlevel to thisargument.

#-N: determines whether the string is not 0. If it is null, it is false.

[-N "$ argv1"] & runlevel = "$ argv1"

 

# Is there an RC directory for this new runlevel?

#-D determine whether the file name is a directory file

[-D/etc/rc $ runlevel. d] | exit 0

 

# First, run the kill scripts.

#/Var/lock some devices have the one-time write feature. In this case, the device will be locked to avoid being disturbed by others in operations in the field of operation, to determine that the device can only be used by a single program

# $ {Var # pattern}: removes the minimum matching string from the left of var.

# $ {I #/etc/rc $ runlevel. d/K ??} : Removes "K?" from the far left of I ??" Three characters, "?" The table matches any character.

#-Q disables all outputs to the standard output regardless of matching rows. If the input row is selected, it exits as 0.

For I in/etc/rc $ runlevel. d/K *; do

Check_runlevel "$ I" | continue

 

# Check ifthe subsystem is already up.

Subsys =$ {I #/etc/rc $ runlevel. d/K ??}

[-F/var/lock/subsys/$ subsys-o-F/var/lock/subsys/$ subsys. init] \

| Continue

 

# Bring thesubsystem down.

If egrep-Q "(killproc | action)" $ I; then

$ I stop

Else

Action $ "Stopping $ subsys:" $ I stop

Fi

Done

 

# Now run the start scripts.

For I in/etc/rc $ runlevel. D/S *; do

Check_runlevel "$ I" | continue

 

# Check ifthe subsystem is already up.

Subsys =$ {I #/etc/rc $ runlevel. D/S ??}

[-F/var/lock/subsys/$ subsys-o-F/var/lock/subsys/$ subsys. init] \

& Continue

# If we're re inconfirmation mode, get user confirmation

# $? : Indicates the result returned by the previous command. If the execution is successful, 0 is returned.

If [-n "$ confirm"]; then

Confirm $ subsys

Case $? In

0 ):;;

2) Confirm = ;;

*) Continue ;;

Esac

Fi

 

# Bring thesubsystem up.

If ["$ subsys" = "halt"-o "$ subsys" = "reboot"]; then

Exportlc_all = C

Exec $ istart

Fi

If egrep-Q "(daemon | action | Success | failure)" $ I 2>/dev/null \

| ["$ Subsys" = "single"-o "$ subsys" = "local"]; then

$ I start

Else

Action $ "Starting $ subsys:" $ I start

Fi

Done

 

 

 

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.