Рейтинг@Mail.ru
[Войти] [Зарегистрироваться]

Наши друзья и партнеры

UnixForum
Беспроводные выключатели nooLite

Lines Club

Ищем достойных соперников.

Книги по Linux (с отзывами читателей)

Библиотека сайта или "Мой Linux Documentation Project"

На главную -> MyLDP -> Электронные книги по ОС Linux
Linux From Scratch (version 6.8)
Назад Приложения Вперед

D. Загрузочные и конфигурационные скрипты версии 20100627

Скрипты, приведенные в этом приложении, перечисляются в соответствии с тем, как они обычно размещены в директориях. Прядок следующий: /etc/rc.d/init.d, /etc/sysconfig, /etc/sysconfig/network-devices и /etc/sysconfig/network-devices/services. Внутри каждого раздела, файлы перечислены в том порядке, в котором они обычно вызываются.



D.1. /etc/rc.d/init.d/rc

Скрипт rc является первым скриптом, который вызывается из init и инициирует процедуру загрузки.

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/rc
#
# Description : Main Run Level Control Script
#
# Authors     : Gerard Beekmans  - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

# This sets a few default terminal options.
stty sane

# These 3 signals will not cause our script to exit
trap "" INT QUIT TSTP

[ "${1}" != "" ] && runlevel=${1}

if [ "${runlevel}" = "" ]; then
    echo "Usage: ${0} <runlevel>" >&2
    exit 1
fi

previous=${PREVLEVEL}
[ "${previous}" = "" ] && previous=N

if [ ! -d ${rc_base}/rc${runlevel}.d ]; then
    boot_mesg "${rc_base}/rc${runlevel}.d does not exist." ${WARNING}
    boot_mesg_flush
    exit 1
fi

# Attempt to stop all service started by previous runlevel,
# and killed in this runlevel
if [ "${previous}" != "N" ]; then
    for i in $(ls -v ${rc_base}/rc${runlevel}.d/K* 2> /dev/null)
    do
        check_script_status

        suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
        prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
        sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix

        if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
            if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
                boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING}
                boot_mesg -n " executed because it was not"
                boot_mesg -n " not started in the previous"
                boot_mesg -n " runlevel (${previous})."
                boot_mesg "" ${NORMAL}
                boot_mesg_flush
                continue
            fi
        fi
        ${i} stop
        error_value=${?}

        if [ "${error_value}" != "0" ]; then
            print_error_msg
        fi
    done
fi

#Start all functions in this runlevel
for i in $( ls -v ${rc_base}/rc${runlevel}.d/S* 2> /dev/null)
do
    if [ "${previous}" != "N" ]; then
        suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
        stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
        prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix

        [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
    fi

    check_script_status

    case ${runlevel} in
        0|6)
            ${i} stop
            ;;
        *)
            ${i} start
            ;;
    esac
    error_value=${?}

    if [ "${error_value}" != "0" ]; then
        print_error_msg
    fi
done

# End $rc_base/init.d/rc


D.2. /etc/rc.d/init.d/functions

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/functions
#
# Description : Run Level Control Functions
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       : With code based on Matthias Benkmann's simpleinit-msb
#        http://winterdrache.de/linux/newboot/index.html
#
########################################################################

## Environmental setup
# Setup default values for environment
umask 022
export PATH="/bin:/usr/bin:/sbin:/usr/sbin"

# Signal sent to running processes to refresh their configuration
RELOADSIG="HUP"

# Number of seconds between STOPSIG and FALLBACK when stopping processes
KILLDELAY="3"

## Screen Dimensions
# Find current screen size
if [ -z "${COLUMNS}" ]; then
    COLUMNS=$(stty size)
    COLUMNS=${COLUMNS##* }
fi

# When using remote connections, such as a serial port, stty size returns 0
if [ "${COLUMNS}" = "0" ]; then 
    COLUMNS=80
fi

## Measurements for positioning result messages
COL=$((${COLUMNS} - 8))
WCOL=$((${COL} - 2))

## Provide an echo that supports -e and -n
# If formatting is needed, $ECHO should be used
case "`echo -e -n test`" in
    -[en]*)
        ECHO=/bin/echo
        ;;
    *)
        ECHO=echo
        ;;
esac

## Set Cursor Position Commands, used via $ECHO
SET_COL="\\033[${COL}G"      # at the $COL char
SET_WCOL="\\033[${WCOL}G"    # at the $WCOL char
CURS_UP="\\033[1A\\033[0G"   # Up one line, at the 0'th char

## Set color commands, used via $ECHO
# Please consult `man console_codes for more information
# under the "ECMA-48 Set Graphics Rendition" section
#
# Warning: when switching from a 8bit to a 9bit font,
# the linux console will reinterpret the bold (1;) to
# the top 256 glyphs of the 9bit font.  This does
# not affect framebuffer consoles
NORMAL="\\033[0;39m"         # Standard console grey
SUCCESS="\\033[1;32m"        # Success is green
WARNING="\\033[1;33m"        # Warnings are yellow
FAILURE="\\033[1;31m"        # Failures are red
INFO="\\033[1;36m"           # Information is light cyan
BRACKET="\\033[1;34m"        # Brackets are blue

STRING_LENGTH="0"   # the length of the current message

#*******************************************************************************
# Function - boot_mesg()
#
# Purpose:      Sending information from bootup scripts to the console
#
# Inputs:       $1 is the message
#               $2 is the colorcode for the console
#
# Outputs:      Standard Output
#
# Dependencies: - sed for parsing strings.
#            - grep for counting string length.
#               
# Todo:         
#*******************************************************************************
boot_mesg()
{
    local ECHOPARM=""

    while true
    do
        case "${1}" in
            -n)
                ECHOPARM=" -n "
                shift 1
                ;;
            -*)
                echo "Unknown Option: ${1}"
                return 1
                ;;
            *)
                break
                ;;
        esac
    done

    ## Figure out the length of what is to be printed to be used
    ## for warning messages. 
    STRING_LENGTH=$((${#1} + 1))

    # Print the message to the screen
    ${ECHO} ${ECHOPARM} -e "${2}${1}"
    
}

boot_mesg_flush()
{
    # Reset STRING_LENGTH for next message
    STRING_LENGTH="0"
}

boot_log()
{
    # Left in for backwards compatibility
    :
}

echo_ok()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS}  OK  ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

echo_failure()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

echo_warning()
{
    ${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]"
    ${ECHO} -e "${NORMAL}"
        boot_mesg_flush
}

print_error_msg()
{
    echo_failure
    # $i is inherited by the rc script
    boot_mesg -n "FAILURE:\n\nYou should not be reading this error message.\n\n" ${FAILURE}
    boot_mesg -n " It means that an unforeseen error took"
    boot_mesg -n " place in ${i}, which exited with a return value of"
    boot_mesg " ${error_value}.\n"
    boot_mesg_flush
    boot_mesg -n "If you're able to track this"
    boot_mesg -n " error down to a bug in one of the files provided by"
    boot_mesg -n " the LFS book, please be so kind to inform us at"
    boot_mesg " lfs-dev@linuxfromscratch.org.\n"
    boot_mesg_flush
    boot_mesg -n "Press Enter to continue..." ${INFO}
    boot_mesg "" ${NORMAL}
    read ENTER
}

check_script_status()
{
    # $i is inherited by the rc script
    if [ ! -f ${i} ]; then
        boot_mesg "${i} is not a valid symlink." ${WARNING}
        echo_warning
        continue
    fi

    if [ ! -x ${i} ]; then
        boot_mesg "${i} is not executable, skipping." ${WARNING}
        echo_warning
        continue
    fi
}

evaluate_retval()
{
    error_value="${?}"

    if [ ${error_value} = 0 ]; then
        echo_ok
    else
        echo_failure
    fi

    # This prevents the 'An Unexpected Error Has Occurred' from trivial
    # errors.
    return 0
}

print_status()
{
    if [ "${#}" = "0" ]; then
        echo "Usage: ${0} {success|warning|failure}"
        return 1
    fi

    case "${1}" in

        success)
            echo_ok
            ;;

        warning)
            # Leave this extra case in because old scripts
            # may call it this way.
            case "${2}" in
                running)
                    ${ECHO} -e -n "${CURS_UP}"
                    ${ECHO} -e -n "\\033[${STRING_LENGTH}G   "
                    boot_mesg "Already running." ${WARNING}
                    echo_warning
                    ;;
                not_running)
                    ${ECHO} -e -n "${CURS_UP}"
                    ${ECHO} -e -n "\\033[${STRING_LENGTH}G   "
                    boot_mesg "Not running." ${WARNING}
                    echo_warning
                    ;;
                not_available)
                    ${ECHO} -e -n "${CURS_UP}"
                    ${ECHO} -e -n "\\033[${STRING_LENGTH}G   "
                    boot_mesg "Not available." ${WARNING}
                    echo_warning
                    ;;
                *)
                    # This is how it is supposed to
                    # be called
                    echo_warning
                    ;;
            esac
        ;;

        failure)
            echo_failure
        ;;

    esac

}

reloadproc()
{
    local pidfile=""
    local failure=0

    while true
    do
        case "${1}" in
            -p)
                pidfile="${2}"
                shift 2
                ;;
            -*)
                log_failure_msg "Unknown Option: ${1}"
                return 2
                ;;
            *)
                break
                ;;
        esac
    done

    if [ "${#}" -lt "1" ]; then
        log_failure_msg "Usage: reloadproc [-p pidfile] pathname"
        return 2
    fi

    # This will ensure compatibility with previous LFS Bootscripts
    if [ -n "${PIDFILE}" ];    then
        pidfile="${PIDFILE}"
    fi

    # Is the process running?
    if [ -z "${pidfile}" ];    then
        pidofproc -s "${1}"
    else
        pidofproc -s -p "${pidfile}" "${1}"
    fi

    # Warn about stale pid file
    if [ "$?" = 1 ]; then
        boot_mesg -n "Removing stale pid file: ${pidfile}. " ${WARNING}
        rm -f "${pidfile}"
    fi

    if [ -n "${pidlist}" ];    then
        for pid in ${pidlist}
        do
            kill -"${RELOADSIG}" "${pid}" || failure="1"
        done

        (exit ${failure})
        evaluate_retval

    else
        boot_mesg "Process ${1} not running." ${WARNING}
        echo_warning
    fi
}

statusproc()
{
    local pidfile=""
    local base=""
    local ret=""

    while true
    do
        case "${1}" in
            -p)
                pidfile="${2}"
                shift 2
                ;;
            -*)
                log_failure_msg "Unknown Option: ${1}"
                return 2
                ;;
            *)
                break
                ;;
        esac
    done

    if [ "${#}" != "1" ]; then
        shift 1
        log_failure_msg "Usage: statusproc [-p pidfile] pathname"
        return 2
    fi

    # Get the process basename
    base="${1##*/}"

    # This will ensure compatibility with previous LFS Bootscripts
    if [ -n "${PIDFILE}" ];    then
        pidfile="${PIDFILE}"
    fi

    # Is the process running?
    if [ -z "${pidfile}" ];    then
        pidofproc -s "${1}"
    else
        pidofproc -s -p "${pidfile}" "${1}"
    fi

    # Store the return status
    ret=$?

    if [ -n "${pidlist}" ];    then
        ${ECHO} -e "${INFO}${base} is running with Process"\
            "ID(s) ${pidlist}.${NORMAL}"
    else
        if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
            ${ECHO} -e "${WARNING}${1} is not running but"\
                "/var/run/${base}.pid exists.${NORMAL}"
        else
            if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
                ${ECHO} -e "${WARNING}${1} is not running"\
                    "but ${pidfile} exists.${NORMAL}"
            else
                ${ECHO} -e "${INFO}${1} is not running.${NORMAL}"
            fi
        fi
    fi

    # Return the status from pidofproc
    return $ret
}

# The below functions are documented in the LSB-generic 2.1.0

#*******************************************************************************
# Function - pidofproc [-s] [-p pidfile] pathname
#
# Purpose: This function returns one or more pid(s) for a particular daemon
#
# Inputs: -p pidfile, use the specified pidfile instead of pidof
#         pathname, path to the specified program
#
# Outputs: return 0 - Success, pid's in stdout
#          return 1 - Program is dead, pidfile exists
#          return 2 - Invalid or excessive number of arguments, 
#                     warning in stdout
#          return 3 - Program is not running
#
# Dependencies: pidof, echo, head
#
# Todo: Remove dependency on head
#       This replaces getpids
#       Test changes to pidof
#
#*******************************************************************************
pidofproc()
{
    local pidfile=""
    local lpids=""
    local silent=""
    pidlist=""
    while true
    do
        case "${1}" in
            -p)
                pidfile="${2}"
                shift 2
                ;;

            -s)
                # Added for legacy opperation of getpids
                # eliminates several '> /dev/null'
                silent="1"
                shift 1
                ;;
            -*)
                log_failure_msg "Unknown Option: ${1}"
                return 2
                ;;
            *)
                break
                ;;
        esac
    done

    if [ "${#}" != "1" ]; then
        shift 1
        log_failure_msg "Usage: pidofproc [-s] [-p pidfile] pathname"
        return 2
    fi

    if [ -n "${pidfile}" ]; then
        if [ ! -r "${pidfile}" ]; then
            return 3 # Program is not running
        fi

        lpids=`head -n 1 ${pidfile}`
        for pid in ${lpids}
        do
            if [ "${pid}" -ne "$$" -a "${pid}" -ne "${PPID}" ]; then
                kill -0 "${pid}" 2>/dev/null &&
                pidlist="${pidlist} ${pid}"
            fi
            
            if [ "${silent}" != "1" ]; then
                echo "${pidlist}"
            fi

            test -z "${pidlist}" && 
            # Program is dead, pidfile exists
            return 1
            # else
            return 0
        done

    else
        pidlist=`pidof -o $$ -o $PPID -x "$1"`
        if [ "${silent}" != "1" ]; then
            echo "${pidlist}"
        fi

        # Get provide correct running status
        if [ -n "${pidlist}" ]; then
            return 0
        else
            return 3
        fi

    fi

    if [ "$?" != "0" ]; then
        return 3 # Program is not running
    fi
}

#*******************************************************************************
# Function - loadproc [-f] [-n nicelevel] [-p pidfile] pathname [args]
#
# Purpose: This runs the specified program as a daemon
#
# Inputs: -f, run the program even if it is already running
#         -n nicelevel, specifies a nice level. See nice(1).
#         -p pidfile, uses the specified pidfile
#         pathname, pathname to the specified program
#         args, arguments to pass to specified program
#
# Outputs: return 0 - Success
#          return 2 - Invalid of excessive number of arguments, 
#                     warning in stdout
#          return 4 - Program or service status is unknown
#
# Dependencies: nice, rm
#
# Todo: LSB says this should be called start_daemon
#       LSB does not say that it should call evaluate_retval
#       It checks for PIDFILE, which is deprecated.
#         Will be removed after BLFS 6.0
#       loadproc returns 0 if program is already running, not LSB compliant
#
#*******************************************************************************
loadproc()
{
    local pidfile=""
    local forcestart=""
    local nicelevel="10"

# This will ensure compatibility with previous LFS Bootscripts
    if [ -n "${PIDFILE}" ];    then
        pidfile="${PIDFILE}"
    fi

  while true
    do
        case "${1}" in
            -f)
                forcestart="1"
                shift 1
                ;;
            -n)
                nicelevel="${2}"
                shift 2
                ;;
            -p)
                pidfile="${2}"
                shift 2
                ;;
            -*)
                log_failure_msg "Unknown Option: ${1}"
                return 2 #invalid or excess argument(s)
                ;;
            *)
                break
                ;;
        esac
    done

    if [ "${#}" = "0" ]; then
        log_failure_msg "Usage: loadproc [-f] [-n nicelevel] [-p pidfile] pathname [args]"
        return 2 #invalid or excess argument(s)
    fi

    if [ -z "${forcestart}" ]; then
        if [ -z "${pidfile}" ];    then
            pidofproc -s "${1}"
        else
            pidofproc -s -p "${pidfile}" "${1}"
        fi

        case "${?}" in
            0)
                log_warning_msg "Unable to continue: ${1} is running"
                return 0 # 4
                ;;
            1)
                boot_mesg "Removing stale pid file: ${pidfile}" ${WARNING}
                rm -f "${pidfile}"
                ;;
            3)
                ;;
            *)
                log_failure_msg "Unknown error code from pidofproc: ${?}"
                return 4
                ;;
        esac
    fi

    nice -n "${nicelevel}" "${@}"
    evaluate_retval # This is "Probably" not LSB compliant,
#                         but required to be compatible with older bootscripts
    return 0
}

#*******************************************************************************
# Function - killproc  [-p pidfile] pathname [signal]
#
# Purpose:
#
# Inputs: -p pidfile, uses the specified pidfile
#         pathname, pathname to the specified program
#         signal, send this signal to pathname
#
# Outputs: return 0 - Success
#          return 2 - Invalid of excessive number of arguments, 
#                     warning in stdout
#          return 4 - Unknown Status
#
# Dependencies: kill, rm
#
# Todo: LSB does not say that it should call evaluate_retval
#       It checks for PIDFILE, which is deprecated.
#         Will be removed after BLFS 6.0
#
#*******************************************************************************
killproc()
{
    local pidfile=""
    local killsig=TERM # default signal is SIGTERM
    pidlist=""

    # This will ensure compatibility with previous LFS Bootscripts
    if [ -n "${PIDFILE}" ];    then
        pidfile="${PIDFILE}"
    fi

    while true
    do
        case "${1}" in
            -p)
                pidfile="${2}"
                shift 2
                ;;
            -*)
                log_failure_msg "Unknown Option: ${1}"
                return 2
                ;;
            *)
                 break
                ;;
        esac
    done

    if [ "${#}" = "2" ]; then
        killsig="${2}"
    elif [ "${#}" != "1" ];    then
        shift 2
        log_failure_msg "Usage: killproc  [-p pidfile] pathname [signal]"
        return 2
    fi

    # Is the process running?
    if [ -z "${pidfile}" ];    then
        pidofproc -s "${1}"
    else
        pidofproc -s -p "${pidfile}" "${1}"
    fi

    # Remove stale pidfile
    if [ "$?" = 1 ]; then
        boot_mesg "Removing stale pid file: ${pidfile}." ${WARNING}
        rm -f "${pidfile}"
    fi

    # If running, send the signal
    if [ -n "${pidlist}" ]; then
    for pid in ${pidlist}
    do
        kill -${killsig} ${pid} 2>/dev/null

        # Wait up to 3 seconds, for ${pid} to terminate
        case "${killsig}" in
        TERM|SIGTERM|KILL|SIGKILL)
            # sleep in 1/10ths of seconds and
            # multiply KILLDELAY by 10
            local dtime="${KILLDELAY}0"
            while [ "${dtime}" != "0" ]
            do
                kill -0 ${pid} 2>/dev/null || break
                sleep 0.1
                dtime=$(( ${dtime} - 1))
            done
            # If ${pid} is still running, kill it
            kill -0 ${pid} 2>/dev/null && kill -KILL ${pid} 2>/dev/null
            ;;
        esac
    done

    # Check if the process is still running if we tried to stop it
    case "${killsig}" in
    TERM|SIGTERM|KILL|SIGKILL)
        if [ -z "${pidfile}" ];    then
            pidofproc -s "${1}"
        else
            pidofproc -s -p "${pidfile}" "${1}"
        fi

        # Program was terminated
        if [ "$?" != "0" ]; then
            # Remove the pidfile if necessary
            if [ -f "${pidfile}" ];    then
                rm -f "${pidfile}"
            fi
            echo_ok
            return 0
        else # Program is still running
            echo_failure
            return 4 # Unknown Status
        fi
        ;;
    *)
        # Just see if the kill returned successfully
        evaluate_retval
        ;;
    esac
    else # process not running
    print_status warning not_running
    fi
}


#*******************************************************************************
# Function - log_success_msg "message"
#
# Purpose: Print a success message
#
# Inputs: $@ - Message
#
# Outputs: Text output to screen
#
# Dependencies: echo
#
# Todo: logging
#
#*******************************************************************************
log_success_msg()
{
    ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}"
    ${ECHO} -e "${SET_COL}""${BRACKET}""[""${SUCCESS}""  OK  ""${BRACKET}""]""${NORMAL}"
    return 0
}

#*******************************************************************************
# Function - log_failure_msg "message"
#
# Purpose: Print a failure message
#
# Inputs: $@ - Message
#
# Outputs: Text output to screen
#
# Dependencies: echo
#
# Todo: logging
#
#*******************************************************************************
log_failure_msg() {
    ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}"
    ${ECHO} -e "${SET_COL}""${BRACKET}""[""${FAILURE}"" FAIL ""${BRACKET}""]""${NORMAL}"
    return 0
}

#*******************************************************************************
# Function - log_warning_msg "message"
#
# Purpose: print a warning message
#
# Inputs: $@ - Message
#
# Outputs: Text output to screen
#
# Dependencies: echo
#
# Todo: logging
#
#*******************************************************************************
log_warning_msg() {
    ${ECHO} -n -e "${BOOTMESG_PREFIX}${@}"
    ${ECHO} -e "${SET_COL}""${BRACKET}""[""${WARNING}"" WARN ""${BRACKET}""]""${NORMAL}"
    return 0
}

# End $rc_base/init.d/functions


D.3. /etc/rc.d/init.d/mountkernfs

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/mountkernfs
#
# Description : Mount proc and sysfs
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg -n "Mounting kernel-based file systems:" ${INFO}

        if ! mountpoint /proc >/dev/null; then
            boot_mesg -n " /proc" ${NORMAL}
            mount -n /proc || failed=1
        fi

        if ! mountpoint /sys >/dev/null; then
            boot_mesg -n " /sys" ${NORMAL}
            mount -n /sys || failed=1
        fi

        boot_mesg "" ${NORMAL}

        (exit ${failed})
        evaluate_retval
        ;;

    *)
        echo "Usage: ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/mountkernfs


D.4. /etc/rc.d/init.d/consolelog

#!/bin/sh
# Begin $rc_base/init.d/consolelog

########################################################################
#
# Description : Set the kernel log level for the console
#
# Authors     : Dan Nicholson - dnicholson@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       : /proc must be mounted before this can run
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

# set the default loglevel
LOGLEVEL=7
if [ -r /etc/sysconfig/console ]; then
    . /etc/sysconfig/console
fi

case "${1}" in
    start)
        case "$LOGLEVEL" in
        [1-8])
            boot_mesg "Setting the console log level to ${LOGLEVEL}..."
            dmesg -n $LOGLEVEL
            evaluate_retval
            ;;
        *)
            boot_mesg "Console log level '${LOGLEVEL}' is invalid" ${FAILURE}
            echo_failure
            ;;
        esac
        ;;
    status)
        # Read the current value if possible
        if [ -r /proc/sys/kernel/printk ]; then
            read level line < /proc/sys/kernel/printk
        else
            boot_mesg "Can't read the current console log level" ${FAILURE}
            echo_failure
        fi

        # Print the value
        if [ -n "$level" ]; then
            ${ECHO} -e "${INFO}The current console log level" \
                "is ${level}${NORMAL}"
        fi
        ;;

    *)
        echo "Usage: ${0} {start|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/consolelog


D.5. /etc/rc.d/init.d/modules

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/modules
#
# Description : Module auto-loading script
#
# Authors     : Zack Winkles
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

# Assure that the kernel has module support.
[ -e /proc/ksyms -o -e /proc/modules ] || exit 0

case "${1}" in
    start)

        # Exit if there's no modules file or there are no
        # valid entries
        [ -r /etc/sysconfig/modules ] &&
            egrep -qv '^($|#)' /etc/sysconfig/modules ||
            exit 0

        boot_mesg -n "Loading modules:" ${INFO}

        # Only try to load modules if the user has actually given us
        # some modules to load.
        while read module args; do

            # Ignore comments and blank lines.
            case "$module" in
                ""|"#"*) continue ;;
            esac

            # Attempt to load the module, making
            # sure to pass any arguments provided.
            modprobe ${module} ${args} >/dev/null

            # Print the module name if successful,
            # otherwise take note.
            if [ $? -eq 0 ]; then
                boot_mesg -n " ${module}" ${NORMAL}
            else
                failedmod="${failedmod} ${module}"
            fi
        done < /etc/sysconfig/modules

        boot_mesg "" ${NORMAL}
        # Print a message about successfully loaded
        # modules on the correct line.
        echo_ok

        # Print a failure message with a list of any
        # modules that may have failed to load.
        if [ -n "${failedmod}" ]; then
            boot_mesg "Failed to load modules:${failedmod}" ${FAILURE}
            echo_failure
        fi
        ;;
    *)
        echo "Usage: ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/modules


D.6. /etc/rc.d/init.d/udev

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/udev
#
# Description : Udev cold-plugging script
#
# Authors     : Zack Winkles, Alexander E. Patrakov
#
# Version     : 00.02
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Populating /dev with device nodes..."
        if ! grep -q '[[:space:]]sysfs' /proc/mounts; then
            echo_failure
            boot_mesg -n "FAILURE:\n\nUnable to create" ${FAILURE}
            boot_mesg -n " devices without a SysFS filesystem"
            boot_mesg -n "\n\nAfter you press Enter, this system"
            boot_mesg -n " will be halted and powered off."
            boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
            boot_mesg "" ${NORMAL}
            read ENTER
            /etc/rc.d/init.d/halt stop
        fi

        # Mount a temporary file system over /dev, so that any devices
        # made or removed during this boot don't affect the next one.
        # The reason we don't write to mtab is because we don't ever
        # want /dev to be unavailable (such as by `umount -a').
        if ! mountpoint /dev > /dev/null; then
            mount -n -t tmpfs tmpfs /dev -o mode=755
        fi
        if [ ${?} != 0 ]; then
            echo_failure
            boot_mesg -n "FAILURE:\n\nCannot mount a tmpfs" ${FAILURE}
            boot_mesg -n " onto /dev, this system will be halted."
            boot_mesg -n "\n\nAfter you press Enter, this system"
            boot_mesg -n " will be halted and powered off."
            boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
            boot_mesg "" ${NORMAL}
            read ENTER
            /etc/rc.d/init.d/halt stop
        fi

        # Udev handles uevents itself, so we don't need to have
        # the kernel call out to any binary in response to them
        echo > /proc/sys/kernel/hotplug

        # Copy the only static device node that Udev >= 155 doesn't
        # handle to /dev
        cp -a /lib/udev/devices/null /dev

        # Start the udev daemon to continually watch for, and act on,
        # uevents
        /sbin/udevd --daemon

        # Now traverse /sys in order to "coldplug" devices that have
        # already been discovered
        /sbin/udevadm trigger --action=add

        # Now wait for udevd to process the uevents we triggered
        /sbin/udevadm settle
        evaluate_retval

        ;;

    *)
        echo "Usage ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/udev


D.7. /etc/rc.d/init.d/swap

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/swap
#
# Description : Swap Control Script
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Activating all swap files/partitions..."
        swapon -a
        evaluate_retval
        ;;

    stop)
        boot_mesg "Deactivating all swap files/partitions..."
        swapoff -a
        evaluate_retval
        ;;

    restart)
        ${0} stop
        sleep 1
        ${0} start
        ;;

    status)
        boot_mesg "Retrieving swap status." ${INFO}
        echo_ok
        echo
        swapon -s
        ;;

    *)
        echo "Usage: ${0} {start|stop|restart|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/swap


D.8. /etc/rc.d/init.d/setclock

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/setclock
#
# Description : Setting Linux Clock
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}
. /etc/sysconfig/clock

case "${UTC}" in
    yes|true|1)
        CLOCKPARAMS="${CLOCKPARAMS} --utc"
        ;;

    no|false|0)
        CLOCKPARAMS="${CLOCKPARAMS} --localtime"
        ;;

esac

case ${1} in
    start)
        boot_mesg "Setting system clock..."
        hwclock --hctosys ${CLOCKPARAMS} >/dev/null
        evaluate_retval
        ;;

    stop)
        boot_mesg "Setting hardware clock..."
        hwclock --systohc ${CLOCKPARAMS} >/dev/null
        evaluate_retval
        ;;

    *)
        echo "Usage: ${0} {start|stop}"
        ;;

esac


D.9. /etc/rc.d/init.d/checkfs

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/checkfs
#
# Description : File System Check
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#               A. Luebke - luebke@users.sourceforge.net
#
# Version     : 00.00
#
# Notes       :
#
# Based on checkfs script from LFS-3.1 and earlier.
#
# From man fsck
# 0    - No errors
# 1    - File system errors corrected
# 2    - System should be rebooted
# 4    - File system errors left uncorrected
# 8    - Operational error
# 16   - Usage or syntax error
# 32   - Fsck canceled by user request
# 128  - Shared library error
#
#########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        if [ -f /fastboot ]; then
            boot_mesg -n "/fastboot found, will not perform" ${INFO}
            boot_mesg " file system checks as requested."
            echo_ok
            exit 0
        fi

        boot_mesg "Mounting root file system in read-only mode..."
        mount -n -o remount,ro / >/dev/null
        evaluate_retval

        if [ ${?} != 0 ]; then
            echo_failure
            boot_mesg -n "FAILURE:\n\nCannot check root" ${FAILURE}
            boot_mesg -n " filesystem because it could not be mounted"
            boot_mesg -n " in read-only mode.\n\nAfter you"
            boot_mesg -n " press Enter, this system will be"
            boot_mesg -n " halted and powered off."
            boot_mesg -n "\n\nPress enter to continue..." ${INFO}
            boot_mesg "" ${NORMAL}
            read ENTER
            ${rc_base}/init.d/halt stop
        fi

        if [ -f /forcefsck ]; then
            boot_mesg -n "/forcefsck found, forcing file" ${INFO}
            boot_mesg " system checks as requested."
            echo_ok
            options="-f"
        else
            options=""
        fi

        boot_mesg "Checking file systems..."
        # Note: -a option used to be -p; but this fails e.g.
        # on fsck.minix
        fsck ${options} -a -A -C -T
        error_value=${?}

        if [ "${error_value}" = 0 ]; then
            echo_ok
        fi

        if [ "${error_value}" = 1 ]; then
            echo_warning
            boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
            boot_mesg -n " were found and have been corrected."
            boot_mesg -n "  You may want to double-check that"
            boot_mesg -n " everything was fixed properly."
            boot_mesg "" ${NORMAL}
        fi

        if [ "${error_value}" = 2 -o "${error_value}" = 3 ]; then
            echo_warning
            boot_mesg -n "WARNING:\n\nFile system errors" ${WARNING}
            boot_mesg -n " were found and have been been"
            boot_mesg -n " corrected, but the nature of the"
            boot_mesg -n " errors require this system to be"
            boot_mesg -n " rebooted.\n\nAfter you press enter,"
            boot_mesg -n " this system will be rebooted"
            boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
            boot_mesg "" ${NORMAL}
            read ENTER
            reboot -f
        fi

        if [ "${error_value}" -gt 3 -a "${error_value}" -lt 16 ]; then
            echo_failure
            boot_mesg -n "FAILURE:\n\nFile system errors" ${FAILURE}
            boot_mesg -n " were encountered that could not be"
            boot_mesg -n " fixed automatically.  This system"
            boot_mesg -n " cannot continue to boot and will"
            boot_mesg -n " therefore be halted until those"
            boot_mesg -n " errors are fixed manually by a"
            boot_mesg -n " System Administrator.\n\nAfter you"
            boot_mesg -n " press Enter, this system will be"
            boot_mesg -n " halted and powered off."
            boot_mesg -n "\n\nPress Enter to continue..." ${INFO}
            boot_mesg "" ${NORMAL}
            read ENTER
          ${rc_base}/init.d/halt stop
        fi

        if [ "${error_value}" -ge 16 ]; then
            echo_failure
            boot_mesg -n "FAILURE:\n\nUnexpected Failure" ${FAILURE}
            boot_mesg -n " running fsck.  Exited with error"
            boot_mesg -n " code: ${error_value}."
            boot_mesg "" ${NORMAL}
            exit ${error_value}
        fi
        ;;
    *)
        echo "Usage: ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/checkfs


D.10. /etc/rc.d/init.d/mountfs

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/mountfs
#
# Description : File System Mount Script
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Remounting root file system in read-write mode..."
        mount -n -o remount,rw / >/dev/null
        evaluate_retval

        # Remove fsck-related file system watermarks.
        rm -f /fastboot /forcefsck

        boot_mesg "Recording existing mounts in /etc/mtab..."
        > /etc/mtab
        mount -f / || failed=1
        mount -f /proc || failed=1
        mount -f /sys || failed=1
        (exit ${failed})
        evaluate_retval

        # This will mount all filesystems that do not have _netdev in
        # their option list.  _netdev denotes a network filesystem.
        boot_mesg "Mounting remaining file systems..."
        mount -a -O no_netdev >/dev/null
        evaluate_retval
        ;;

    stop)
        boot_mesg "Unmounting all other currently mounted file systems..."
        umount -a -d -r >/dev/null
        evaluate_retval
        ;;

    *)
        echo "Usage: ${0} {start|stop}"
        exit 1
        ;;
esac

# End $rc_base/init.d/mountfs


D.11. /etc/rc.d/init.d/udev_retry

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/udev_retry
#
# Description : Udev cold-plugging script (retry)
#
# Authors     : Alexander E. Patrakov
#
# Version     : 00.02
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Retrying failed uevents, if any..."

        # From Debian: "copy the rules generated before / was mounted
        # read-write":
        for file in /dev/.udev/tmp-rules--*; do
            dest=${file##*tmp-rules--}
            [ "$dest" = '*' ] && break
            cat $file >> /etc/udev/rules.d/$dest
            rm -f $file
        done

        # Re-trigger the failed uevents in hope they will succeed now
        /sbin/udevadm trigger --type=failed --action=add
        
        # Now wait for udevd to process the uevents we triggered
        /sbin/udevadm settle
        evaluate_retval
        ;;

    *)
        echo "Usage ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/udev_retry


D.12. /etc/rc.d/init.d/cleanfs

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/cleanfs
#
# Description : Clean file system
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

# Function to create files/directory on boot.
create_files() {
    # Read in the configuration file.
    exec 9>&0 < /etc/sysconfig/createfiles
        while read name type perm usr grp dtype maj min junk
        do

            # Ignore comments and blank lines.
                   case "${name}" in
                ""|\#*) continue ;;
            esac

            # Ignore existing files.
            if [ ! -e "${name}" ]; then
                # Create stuff based on its type.
                case "${type}" in
                    dir)
                        mkdir "${name}"
                        ;;
                    file)
                        :> "${name}"
                        ;;
                    dev)
                        case "${dtype}" in
                            char)
                                mknod "${name}" c ${maj} ${min}
                                ;;
                            block)
                                mknod "${name}" b ${maj} ${min}
                                ;;
                            pipe)
                                mknod "${name}" p
                                ;;
                            *) 
                                boot_mesg -n "\nUnknown device type: ${dtype}" ${WARNING}
                                boot_mesg "" ${NORMAL}
                                ;;
                        esac
                        ;;
                    *)
                        boot_mesg -n "\nUnknown type: ${type}" ${WARNING}
                        boot_mesg "" ${NORMAL}
                        continue
                        ;;
                esac

                # Set up the permissions, too.
                chown ${usr}:${grp} "${name}"
                chmod ${perm} "${name}"
            fi
        done
    exec 0>&9 9>&-
}

case "${1}" in
    start)
        boot_mesg -n "Cleaning file systems:" ${INFO}

        boot_mesg -n " /tmp" ${NORMAL}
        cd /tmp &&
        find . -xdev -mindepth 1 ! -name lost+found \
            -delete || failed=1

        boot_mesg -n " /var/lock" ${NORMAL}
        cd /var/lock &&
        find . -type f -exec rm -f {} \; || failed=1

        boot_mesg " /var/run" ${NORMAL}
        cd /var/run &&
        find . ! -type d ! -name utmp \
            -exec rm -f {} \; || failed=1
        > /var/run/utmp
        if grep -q '^utmp:' /etc/group ; then
            chmod 664 /var/run/utmp
            chgrp utmp /var/run/utmp
        fi

        (exit ${failed})
        evaluate_retval

        if egrep -qv '^(#|$)' /etc/sysconfig/createfiles 2>/dev/null; then
            boot_mesg "Creating files and directories..."
            create_files
            evaluate_retval
        fi
        ;;
    *)
        echo "Usage: ${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/cleanfs


D.13. /etc/rc.d/init.d/console

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/console
#
# Description : Sets keymap and screen font
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#        Alexander E. Patrakov
#
# Version     : 00.03
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

# Native English speakers probably don't have /etc/sysconfig/console at all
if [ -f /etc/sysconfig/console ]
then
    . /etc/sysconfig/console
else
        exit 0
fi

is_true() {
    [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ]
}

failed=0

case "${1}" in
    start)
        boot_mesg "Setting up Linux console..."
        # There should be no bogus failures below this line!
        
        # Figure out if a framebuffer console is used
        [ -d /sys/class/graphics/fb0 ] && USE_FB=1 || USE_FB=0
        
        # Figure out the command to set the console into the
        # desired mode
        is_true "${UNICODE}" &&
            MODE_COMMAND="${ECHO} -en '\033%G' && kbd_mode -u" ||
            MODE_COMMAND="${ECHO} -en '\033%@\033(K' && kbd_mode -a"
        
        # On framebuffer consoles, font has to be set for each vt in
        # UTF-8 mode. This doesn't hurt in non-UTF-8 mode also.
        
        ! is_true "${USE_FB}" || [ -z "${FONT}" ] ||
            MODE_COMMAND="${MODE_COMMAND} && setfont ${FONT}"

        # Apply that command to all consoles mentioned in
        # /etc/inittab. Important: in the UTF-8 mode this should
        # happen before setfont, otherwise a kernel bug will
        # show up and the unicode map of the font will not be
        # used.
        # FIXME: Fedora Core also initializes two spare consoles
        # - do we want that?
        
        for TTY in `grep '^[^#].*respawn:/sbin/agetty' /etc/inittab |
            grep -o '\btty[[:digit:]]*\b'`
        do
            openvt -f -w -c ${TTY#tty} -- \
                /bin/sh -c "${MODE_COMMAND}" || failed=1
        done

        # Set the font (if not already set above) and the keymap
        is_true "${USE_FB}" || [ -z "${FONT}" ] ||
            setfont $FONT ||
            failed=1
        [ -z "${KEYMAP}" ] ||
            loadkeys ${KEYMAP} >/dev/null 2>&1 ||
            failed=1
        [ -z "${KEYMAP_CORRECTIONS}" ] ||
            loadkeys ${KEYMAP_CORRECTIONS} >/dev/null 2>&1 ||
            failed=1

        # Convert the keymap from $LEGACY_CHARSET to UTF-8
        [ -z "$LEGACY_CHARSET" ] ||
            dumpkeys -c "$LEGACY_CHARSET" |
            loadkeys -u >/dev/null 2>&1 ||
            failed=1

        # If any of the commands above failed, the trap at the
        # top would set $failed to 1
        ( exit $failed )
        evaluate_retval
        ;;
    *)
        echo $"Usage:" "${0} {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/console


D.14. /etc/rc.d/init.d/localnet

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/localnet
#
# Description : Loopback device
#
# Authors     : Gerard Beekmans  - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}
. /etc/sysconfig/network

case "${1}" in
    start)
        boot_mesg "Bringing up the loopback interface..."
        ip addr add 127.0.0.1/8 label lo dev lo
        ip link set lo up
        evaluate_retval

        boot_mesg "Setting hostname to ${HOSTNAME}..."
        hostname ${HOSTNAME}
        evaluate_retval
        ;;

    stop)
        boot_mesg "Bringing down the loopback interface..."
        ip link set lo down
        evaluate_retval
        ;;

    restart)
        ${0} stop
        sleep 1
        ${0} start
        ;;

    status)
        echo "Hostname is: $(hostname)"
        ip link show lo
        ;;

    *)
        echo "Usage: ${0} {start|stop|restart|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/localnet


D.15. /etc/rc.d/init.d/sysctl

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/sysctl
#
# Description : File uses /etc/sysctl.conf to set kernel runtime
#               parameters
#
# Authors     : Nathan Coulson (nathan@linuxfromscratch.org)
#               Matthew Burgress (matthew@linuxfromscratch.org)
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        if [ -f "/etc/sysctl.conf" ]; then
            boot_mesg "Setting kernel runtime parameters..."
            sysctl -q -p
            evaluate_retval
        fi
        ;;

    status)
        sysctl -a    
        ;;

    *)
        echo "Usage: ${0} {start|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/sysctl


D.16. /etc/rc.d/init.d/sysklogd

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/sysklogd
#
# Description : Sysklogd loader
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Starting system log daemon..."
        loadproc syslogd -m 0

        boot_mesg "Starting kernel log daemon..."
        loadproc klogd
        ;;

    stop)
        boot_mesg "Stopping kernel log daemon..."
        killproc klogd

        boot_mesg "Stopping system log daemon..."
        killproc syslogd
        ;;

    reload)
        boot_mesg "Reloading system log daemon config file..."
        reloadproc syslogd
        ;;

    restart)
        ${0} stop
        sleep 1
        ${0} start
        ;;

    status)
        statusproc syslogd
        statusproc klogd
        ;;

    *)
        echo "Usage: ${0} {start|stop|reload|restart|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/sysklogd


D.17. /etc/rc.d/init.d/network

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/network
#
# Description : Network Control Script
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#        Nathan Coulson - nathan@linuxfromscratch.org
#        Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}
. /etc/sysconfig/network

case "${1}" in
    start)
        # Start all network interfaces
        for file in ${network_devices}/ifconfig.*
        do
            interface=${file##*/ifconfig.}

            # skip if $file is * (because nothing was found)
            if [ "${interface}" = "*" ]
            then
                continue
            fi

            IN_BOOT=1 ${network_devices}/ifup ${interface}
        done
        ;;

    stop)
        # Reverse list
        FILES=""
        for file in ${network_devices}/ifconfig.*
        do
            FILES="${file} ${FILES}"
        done

        # Stop all network interfaces
        for file in ${FILES}
        do
            interface=${file##*/ifconfig.}

            # skip if $file is * (because nothing was found)
            if [ "${interface}" = "*" ]
            then
                continue
            fi

            IN_BOOT=1 ${network_devices}/ifdown ${interface}
        done
        ;;

    restart)
        ${0} stop
        sleep 1
        ${0} start
        ;;

    *)
        echo "Usage: ${0} {start|stop|restart}"
        exit 1
        ;;
esac

# End /etc/rc.d/init.d/network


D.18. /etc/rc.d/init.d/sendsignals

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/sendsignals
#
# Description : Sendsignals Script
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    stop)
        boot_mesg "Sending all processes the TERM signal..."
        killall5 -15
        error_value=${?}

        sleep ${KILLDELAY}

        if [ "${error_value}" = 0 -o "${error_value}" = 2 ]; then
            echo_ok
        else
            echo_failure
        fi

        boot_mesg "Sending all processes the KILL signal..."
        killall5 -9
        error_value=${?}

        sleep ${KILLDELAY}

        if [ "${error_value}" = 0 -o "${error_value}" = 2 ]; then
            echo_ok
        else
            echo_failure
        fi
        ;;

    *)
        echo "Usage: ${0} {stop}"
        exit 1
        ;;

esac

# End $rc_base/init.d/sendsignals


D.19. /etc/rc.d/init.d/reboot

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/reboot
#
# Description : Reboot Scripts
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    stop)
        boot_mesg "Restarting system..."
        reboot -d -f -i
        ;;

    *)
        echo "Usage: ${0} {stop}"
        exit 1
        ;;

esac

# End $rc_base/init.d/reboot


D.20. /etc/rc.d/init.d/halt

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/halt
#
# Description : Halt Script
#
# Authors     : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    stop)
        halt -d -f -i -p
        ;;
    *)
        echo "Usage: {stop}"
        exit 1
        ;;
esac

# End $rc_base/init.d/halt


D.21. /etc/rc.d/init.d/template

#!/bin/sh
########################################################################
# Begin $rc_base/init.d/
#
# Description :
#
# Authors     :
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. ${rc_functions}

case "${1}" in
    start)
        boot_mesg "Starting..."
        loadproc
        ;;

    stop)
        boot_mesg "Stopping..."
        killproc
        ;;

    reload)
        boot_mesg "Reloading..."
        reloadproc
        ;;

    restart)
        ${0} stop
        sleep 1
        ${0} start
        ;;

    status)
        statusproc
        ;;

    *)
        echo "Usage: ${0} {start|stop|reload|restart|status}"
        exit 1
        ;;
esac

# End $rc_base/init.d/


D.22. /etc/sysconfig/rc

########################################################################
# Begin /etc/sysconfig/rc
#
# Description : rc script configuration
#
# Authors     :
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

rc_base=/etc/rc.d
rc_functions=${rc_base}/init.d/functions
network_devices=/etc/sysconfig/network-devices

# End /etc/sysconfig/rc


D.23. /etc/sysconfig/modules

########################################################################
# Begin /etc/sysconfig/modules
#
# Description : Module auto-loading configuration
#
# Authors     :
#
# Version     : 00.00
#
# Notes       : The syntax of this file is as follows:
#          <module> [<arg1> <arg2> ...]
#
# Each module should be on it's own line, and any options that you want
# passed to the module should follow it.  The line deliminator is either
# a space or a tab.
########################################################################

# End /etc/sysconfig/modules


D.24. /etc/sysconfig/createfiles

########################################################################
# Begin /etc/sysconfig/createfiles
#
# Description : Createfiles script config file
#
# Authors     :
#
# Version     : 00.00
#
# Notes       : The syntax of this file is as follows:
#         if type is equal to "file" or "dir"
#          <filename> <type> <permissions> <user> <group>
#         if type is equal to "dev"
#          <filename> <type> <permissions> <user> <group> <devtype> <major> <minor>
#
#         <filename> is the name of the file which is to be created
#         <type> is either file, dir, or dev.
#               file creates a new file
#               dir creates a new directory
#               dev creates a new device
#         <devtype> is either block, char or pipe
#               block creates a block device
#               char creates a character deivce
#               pipe creates a pipe, this will ignore the <major> and <minor> fields
#         <major> and <minor> are the major and minor numbers used for the device.
########################################################################

# End /etc/sysconfig/createfiles


D.25. /etc/sysconfig/network-devices/ifup

#!/bin/sh
########################################################################
# Begin $network_devices/ifup
#
# Description : Interface Up
#
# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
#               Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       : the IFCONFIG variable is passed to the scripts found
#               in the services directory, to indicate what file the
#               service should source to get environmental variables.
#
########################################################################

. /etc/sysconfig/rc 
. ${rc_functions} 

# Collect a list of configuration files for our interface
if [ -n "${2}" ]; then
    for file in ${@#$1} # All parameters except $1
  do
        FILES="${FILES} ${network_devices}/ifconfig.${1}/${file}"
    done
elif [ -d "${network_devices}/ifconfig.${1}" ]; then
    FILES=`echo ${network_devices}/ifconfig.${1}/*`
else 
    FILES="${network_devices}/ifconfig.${1}"
fi

boot_mesg "Bringing up the ${1} interface..."
boot_mesg_flush

# Process each configruation file
for file in ${FILES}; do
    # skip backup files
    if [ "${file}" != "${file%""~""}" ]; then
        continue
    fi

    if [ ! -f "${file}" ]; then
        boot_mesg "${file} is not a network configuration file or directory." ${WARNING}
        echo_warning
        continue
    fi

    (
        . ${file}

        # Will not process this service if started by boot, and ONBOOT
        # is not set to yes
        if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
            continue
        fi
        # Will not process this service if started by hotplug, and 
        # ONHOTPLUG is not set to yes
        if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" \
                    -a "${HOSTNAME}" != "(none)" ]; then continue
        fi

        if [ -n "${SERVICE}" -a -x "${network_devices}/services/${SERVICE}" ]; then
            if [ -z "${CHECK_LINK}" -o "${CHECK_LINK}" = "y" \
                            -o "${CHECK_LINK}" = "yes" -o "${CHECK_LINK}" = "1" ]; then
                if ip link show ${1} > /dev/null 2>&1; then
                    link_status=`ip link show ${1}`
                    if [ -n "${link_status}" ]; then
                        if ! echo "${link_status}" | grep -q UP; then
                            ip link set ${1} up
                        fi
                    fi
                else
                    boot_mesg "Interface ${1} doesn't exist." ${WARNING}
                    echo_warning
                    continue
                fi
            fi
            IFCONFIG=${file} ${network_devices}/services/${SERVICE} ${1} up
        else
            boot_mesg "Unable to process ${file}.  Either" ${FAILURE}
            boot_mesg " the SERVICE variable was not set,"
            boot_mesg " or the specified service cannot be executed."
            echo_failure
            continue
        fi
    )
done

# End $network_devices/ifup


D.26. /etc/sysconfig/network-devices/ifdown

#!/bin/sh
########################################################################
# Begin $network_devices/ifdown
#
# Description : Interface Down
#
# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
#               Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.01
#
# Notes       : the IFCONFIG variable is passed to the scripts found
#               in the services directory, to indicate what file the
#               service should source to get environmental variables.
#
########################################################################

. /etc/sysconfig/rc 
. ${rc_functions} 

# Collect a list of configuration files for our interface
if [ -n "${2}" ]; then
    for file in ${@#$1}; do # All parameters except $1
        FILES="${FILES} ${network_devices}/ifconfig.${1}/${file}"
    done
elif [ -d "${network_devices}/ifconfig.${1}" ]; then
    FILES=`echo ${network_devices}/ifconfig.${1}/*`
else
    FILES="${network_devices}/ifconfig.${1}"
fi

# Reverse the order configuration files are processed in
for file in ${FILES}; do
    FILES2="${file} ${FILES2}"
done
FILES=${FILES2}

# Process each configuration file
for file in ${FILES}; do
    # skip backup files
    if [ "${file}" != "${file%""~""}" ]; then
        continue
    fi

    if [ ! -f "${file}" ]; then
        boot_mesg "${file} is not a network configuration file or directory." ${WARNING}
        echo_warning
        continue
    fi
    (
        . ${file}

        # Will not process this service if started by boot, and ONBOOT
        # is not set to yes
        if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
            continue
        fi

        # Will not process this service if started by hotplug, and 
        # ONHOTPLUG is not set to yes
        if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then
            continue
        fi
    
        # This will run the service script, if SERVICE is set
        if [ -n "${SERVICE}" -a -x "${network_devices}/services/${SERVICE}" ]; then
            if ip link show ${1} > /dev/null 2>&1
            then
                IFCONFIG=${file} ${network_devices}/services/${SERVICE} ${1} down
            else
                boot_mesg "Interface ${1} doesn't exist." ${WARNING}
                echo_warning
            fi
        else
            boot_mesg -n "Unable to process ${file}.  Either" ${FAILURE}
            boot_mesg -n " the SERVICE variable was not set,"
            boot_mesg " or the specified service cannot be executed."
            echo_failure
            continue
        fi
    )
done

if [ -z "${2}" ]; then
    link_status=`ip link show $1 2>/dev/null`
    if [ -n "${link_status}" ]; then
        if echo "${link_status}" | grep -q UP; then
            boot_mesg "Bringing down the ${1} interface..."
            ip link set ${1} down
            evaluate_retval
        fi
    fi
fi

# End $network_devices/ifdown


D.27. /etc/sysconfig/network-devices/services/ipv4-static

#!/bin/sh
########################################################################
# Begin $network_devices/services/ipv4-static
#
# Description : IPV4 Static Boot Script
#
# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
#        Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc 
. ${rc_functions} 
. ${IFCONFIG}

if [ -z "${IP}" ]; then
    boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
    echo_failure
    exit 1
fi

if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
    boot_mesg -n "PREFIX variable missing from ${IFCONFIG}," ${WARNING}
    boot_mesg " assuming 24."
    echo_warning
    PREFIX=24
    args="${args} ${IP}/${PREFIX}"
elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
    boot_mesg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue." ${FAILURE}
    echo_failure
    exit 1
elif [ -n "${PREFIX}" ]; then
    args="${args} ${IP}/${PREFIX}"
elif [ -n "${PEER}" ]; then
    args="${args} ${IP} peer ${PEER}"
fi

if [ -n "${BROADCAST}" ]; then
    args="${args} broadcast ${BROADCAST}"
fi

case "${2}" in
    up)
        boot_mesg "Adding IPv4 address ${IP} to the ${1} interface..."
        ip addr add ${args} dev ${1}
        evaluate_retval
    
        if [ -n "${GATEWAY}" ]; then
            if ip route | grep -q default; then
                boot_mesg "Gateway already setup; skipping." ${WARNING}
                echo_warning
            else
                boot_mesg "Setting up default gateway..."
                ip route add default via ${GATEWAY} dev ${1}
                evaluate_retval
             fi
        fi
    ;;
    
    down)
        if [ -n "${GATEWAY}" ];    then
            boot_mesg "Removing default gateway..."
            ip route del default
            evaluate_retval
        fi
    
        boot_mesg "Removing IPv4 address ${IP} from the ${1} interface..."
        ip addr del ${args} dev ${1}
        evaluate_retval
    ;;
    
    *)
        echo "Usage: ${0} [interface] {up|down}"
        exit 1
    ;;
esac

# End $network_devices/services/ipv4-static


D.28. /etc/sysconfig/network-devices/services/ipv4-static-route

#!/bin/sh
########################################################################
# Begin $network_devices/services/ipv4-static-route
#
# Description : IPV4 Static Route Script
#
# Authors     : Kevin P. Fleming - kpfleming@linuxfromscratch.org
#
# Version     : 00.00
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc 
. ${rc_functions} 
. ${IFCONFIG}

case "${TYPE}" in
    ("" | "network")
        need_ip=1
        need_gateway=1
    ;;

    ("default")
        need_gateway=1
        args="${args} default"
        desc="default"
    ;;

    ("host")
        need_ip=1
    ;;

    ("unreachable")
        need_ip=1
        args="${args} unreachable"
        desc="unreachable "
    ;;

    (*)
        boot_mesg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue." ${FAILURE}
        echo_failure
        exit 1
    ;;
esac

if [ -n "${need_ip}" ]; then
    if [ -z "${IP}" ]; then
        boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
        echo_failure
        exit 1
    fi

    if [ -z "${PREFIX}" ]; then
        boot_mesg "PREFIX variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
        echo_failure
        exit 1
    fi
    
    args="${args} ${IP}/${PREFIX}"
    desc="${desc}${IP}/${PREFIX}"
fi

if [ -n "${need_gateway}" ]; then
    if [ -z "${GATEWAY}" ]; then
        boot_mesg "GATEWAY variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
        echo_failure
        exit 1
    fi
    args="${args} via ${GATEWAY}"
fi

if [ -n "${SOURCE}" ]; then
        args="${args} src ${SOURCE}"
fi

case "${2}" in
    up)
        boot_mesg "Adding '${desc}' route to the ${1} interface..."
        ip route add ${args} dev ${1}
        evaluate_retval
    ;;
    
    down)
        boot_mesg "Removing '${desc}' route from the ${1} interface..."
        ip route del ${args} dev ${1}
        evaluate_retval
    ;;
    
    *)
        echo "Usage: ${0} [interface] {up|down}"
        exit 1
    ;;
esac

# End $network_devices/services/ipv4-static-route

Предыдущий раздел: Оглавление Следующий раздел:
Приложение C. Зависимости   Приложение E. Конфигурационные правила udev


Эта статья еще не оценивалась
Вы сможете оценить статью и оставить комментарий, если войдете или зарегистрируетесь.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.

Комментарии отсутствуют