diff options
author | DJ Lucas <dj@linuxfromscratch.org> | 2011-05-21 17:22:20 +0000 |
---|---|---|
committer | DJ Lucas <dj@linuxfromscratch.org> | 2011-05-21 17:22:20 +0000 |
commit | d93bdd1e252180cc619b8eba3d75cfdf2b31edb4 (patch) | |
tree | 3241626f9337330de9ab9d8aa1c19a9f50604afe | |
parent | c2db0877b0203a21182e5aaba75c98e6291d2ea0 (diff) |
Multiple changes - cleanup and udev trigger - see changelog
git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9544 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
-rw-r--r-- | lsb-bootscripts/ChangeLog | 14 | ||||
-rw-r--r-- | lsb-bootscripts/Makefile | 2 | ||||
-rw-r--r-- | lsb-bootscripts/etc/default/rc | 57 | ||||
-rw-r--r-- | lsb-bootscripts/etc/default/rc.site | 58 | ||||
-rw-r--r-- | lsb-bootscripts/etc/init.d/lfs-functions | 214 | ||||
-rw-r--r-- | lsb-bootscripts/etc/init.d/mountvirtfs | 6 | ||||
-rw-r--r-- | lsb-bootscripts/etc/init.d/udev | 3 | ||||
-rw-r--r-- | lsb-bootscripts/lib/lsb/init-functions | 496 |
8 files changed, 448 insertions, 402 deletions
diff --git a/lsb-bootscripts/ChangeLog b/lsb-bootscripts/ChangeLog index ddf064576..f6c4ca720 100644 --- a/lsb-bootscripts/ChangeLog +++ b/lsb-bootscripts/ChangeLog @@ -1,6 +1,16 @@ +2011-05-21 DJ Lucas <dj@linuxfromscratch.org> + * lib/lsb/init-functions: Merged the contents of etc/init.d/lfs-functions and + standardized comment headers. + * etc/init.d/lfs-functions: Removed. + * etc/default/rc, etc/default/rc.site: moved majority of etc/default/rc.site + into etc/default/rc as the configuration items are not generally user + configurable items. + * etc/init.d/udev: Changed trigger commands to use both subsystem and device + types, per udev documentation. + 2011-05-18 DJ Lucas <dj@linuxfromscratch.org> - * /sbin/ifup, /sbin/ifdown: Complete rewrite for use as standalone tools - * etc/init.d/network: Rewrote script to account for new ifup and ifdown + * sbin/ifup, sbin/ifdown: Complete rewrite for use as standalone tools. + * etc/init.d/network: Rewrote script to account for new ifup and ifdown. 2011-05-14 DJ Lucas <dj@linuxfromscratch.org> * etc/default/rc.site: Added FAILURE_ACTION variable for use in remote diff --git a/lsb-bootscripts/Makefile b/lsb-bootscripts/Makefile index a5ca9e00c..341d61967 100644 --- a/lsb-bootscripts/Makefile +++ b/lsb-bootscripts/Makefile @@ -26,7 +26,6 @@ create-dirs: install: create-dirs install -m ${MODE} etc/init.d/checkfs ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/cleanfs ${EXTDIR}/init.d/ - install -m ${CONFMODE} etc/init.d/lfs-functions ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/halt ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/console ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/localnet ${EXTDIR}/init.d/ @@ -75,7 +74,6 @@ install: create-dirs minimal: create-dirs install -m ${MODE} etc/init.d/checkfs ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/cleanfs ${EXTDIR}/init.d/ - install -m ${CONFMODE} etc/init.d/lfs-functions ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/halt ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/localnet ${EXTDIR}/init.d/ install -m ${MODE} etc/init.d/mountfs ${EXTDIR}/init.d/ diff --git a/lsb-bootscripts/etc/default/rc b/lsb-bootscripts/etc/default/rc index 96bd476d9..c530f6535 100644 --- a/lsb-bootscripts/etc/default/rc +++ b/lsb-bootscripts/etc/default/rc @@ -9,6 +9,12 @@ # Source site specific rc configuration . /etc/default/rc.site +# Set base directory information +RC_BASE="/etc" + +# Location of network device scripts and config files +NETWORK_DEVICES="/etc/network" + # This sets default terminal options. # stty sane - this has been removed as nobody recalls # the reason for it in the first place - if no problems arize, @@ -38,7 +44,56 @@ 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 +# Distro Information +DISTRO="Linux From Scratch" # The distro name +DISTRO_CONTACT="lfs-dev@linuxfromscratch.org" # Bug report address +DISTRO_MINI="lfs" # Short name used in filenames for distro config + +# Define custom colors used in messages printed to the screen +BRACKET="\\033[1;34m" # Blue +FAILURE="\\033[1;31m" # Red +INFO="\\033[1;36m" # Cyan +NORMAL="\\033[0;39m" # Grey +SUCCESS="\\033[1;32m" # Green +WARNING="\\033[1;33m" # Yellow + +# Prefix boot messages for easier reading on framebuffer consoles +PREFIX_SUCCESS=" ${SUCCESS}*${NORMAL} " +PREFIX_WARNING="${WARNING}**${NORMAL} " +PREFIX_FAILURE="${FAILURE}***${NORMAL}" + # Export the environment variables so they are inherited by the scripts -export PATH SET_COL SET_WCOL CURS_UP BOOTLOG_ENAB +export RC_BASE NETWORK_DEVICES PATH SET_COL SET_WCOL CURS_UP +export DISTRO DISTRO_CONTACT DISTRO_MINI +export BRACKET FAILURE INFO NORMAL SUCCESS WARNING +export PREFIX_SUCCESS PREFIX_WARNING PREFIX_FAILURE + +# Interactive startup +dlen="29" # The total length of the distro welcome string +ilen="38" # The total length of the interactive message +welcome_message="Welcome to ${INFO}${DISTRO}${NORMAL}" +i_message="Press '${FAILURE}I${NORMAL}' to enter interactive startup" + +# Error message displayed when a script's exit value is not zero +print_error_msg() +{ + # ${link} and ${error_value} are defined by the rc script + echo -e "${FAILURE}FAILURE: You should not be reading this error message." + echo -e "" + echo -e -n "${FAILURE}It means that an unforseen error took place in" + echo -e -n "${INFO} ${link}" + echo -e "${FAILURE}," + echo -e "${FAILURE}which exited with a return value of ${error_value}." + echo -e "" + echo -e -n "${FAILURE}If you are able to track this error down to a bug" + echo -e "${FAILURE}in one of the files" + echo -e -n "provided by ${INFO}${DISTRO}${FAILURE}, " + echo -e -n "${FAILURE}please be so kind to inform us at " + echo -e "${INFO}${DISTRO_CONTACT}${FAILURE}.${NORMAL}" + echo -e "" + echo -e "${INFO}Press Enter to continue..." + echo -e "${NORMAL}" + $FAILURE_ACTION +} # End /etc/default/rc diff --git a/lsb-bootscripts/etc/default/rc.site b/lsb-bootscripts/etc/default/rc.site index f617c16cb..34f25cc79 100644 --- a/lsb-bootscripts/etc/default/rc.site +++ b/lsb-bootscripts/etc/default/rc.site @@ -1,10 +1,3 @@ -# Set base directory information -RC_BASE="/etc" -RC_FUNCTIONS="${RC_BASE}/init.d/lfs-functions" - -# Location of network device scripts and config files -NETWORK_DEVICES="/etc/network" - # Bootlogging (requires a tempfs mount) BOOTLOG_ENAB="yes" @@ -19,59 +12,10 @@ CLOCKPARAMS= # an error is encountered that interupts the boot/shutdown proceess FAILURE_ACTION="read ENTER" -# Distro Information -DISTRO="Linux From Scratch" # The distro name -DISTRO_CONTACT="lfs-dev@linuxfromscratch.org" # Bug report address -DISTRO_MINI="lfs" # Short name used in filenames for distro config - -# Define custom colors used in messages printed to the screen -BRACKET="\\033[1;34m" # Blue -FAILURE="\\033[1;31m" # Red -INFO="\\033[1;36m" # Cyan -NORMAL="\\033[0;39m" # Grey -SUCCESS="\\033[1;32m" # Green -WARNING="\\033[1;33m" # Yellow - -# Prefix boot messages for easier reading on framebuffer consoles -PREFIX_SUCCESS=" ${SUCCESS}*${NORMAL} " -PREFIX_WARNING="${WARNING}**${NORMAL} " -PREFIX_FAILURE="${FAILURE}***${NORMAL}" - # Export varialbles so that they are inherited by the initscripts -export RC_BASE RC_FUNCTIONS NETWORK_DEVICES BOOTLOG_ENAB -export HOSTNAME UTC CLOCKPARAMS FAILURE_ACTION -export DISTRO DISTRO_CONTACT DISTRO_MINI -export BRACKET FAILURE INFO NORMAL SUCCESS WARNING -export PREFIX_SUCCESS PREFIX_WARNING PREFIX_FAILURE +export BOOTLOG_ENAB HOSTNAME UTC CLOCKPARAMS FAILURE_ACTION # Interactive startup iprompt="yes" # Wether to display the interactive boot promp itime="2" # The ammount of time (in seconds) to display the prompt -dlen="29" # The total length of the distro welcome string -ilen="38" # The total length of the interactive message -welcome_message="Welcome to ${INFO}${DISTRO}${NORMAL}" -i_message="Press '${FAILURE}I${NORMAL}' to enter interactive startup" - -# Error message displayed when a script's exit value is not zero -print_error_msg() -{ - # ${link} and ${error_value} are defined by the rc script - echo -e "${FAILURE}FAILURE: You should not be reading this error message." - echo -e "" - echo -e -n "${FAILURE}It means that an unforseen error took place in" - echo -e -n "${INFO} ${link}" - echo -e "${FAILURE}," - echo -e "${FAILURE}which exited with a return value of ${error_value}." - echo -e "" - echo -e -n "${FAILURE}If you are able to track this error down to a bug" - echo -e "${FAILURE}in one of the files" - echo -e -n "provided by ${INFO}${DISTRO}${FAILURE}, " - echo -e -n "${FAILURE}please be so kind to inform us at " - echo -e "${INFO}${DISTRO_CONTACT}${FAILURE}.${NORMAL}" - echo -e "" - echo -e "${INFO}Press Enter to continue..." - echo -e "${NORMAL}" - $FAILURE_ACTION -} - diff --git a/lsb-bootscripts/etc/init.d/lfs-functions b/lsb-bootscripts/etc/init.d/lfs-functions deleted file mode 100644 index b0fef4c29..000000000 --- a/lsb-bootscripts/etc/init.d/lfs-functions +++ /dev/null @@ -1,214 +0,0 @@ -# Begin /etc/init.d/lfs-functions -# Provides LFS specific functions for LSB style bootscripts - -################################# chkstat() ################################### -# chk_stat checks the status of a script by checking for both a binary file # -# to execute, and if set, a config file that may be needed for the program # -# to run successfully. The calling script will exit with a return value of 5 # -# if the binary does not exist, and a value of 6 if the needed config file is # -# unavailable as per LSB requirements. This function accepts zero, one, or # -# two string arguments. If arguments are passed, the first must be a bin # -# file. If a second argument is passed, it is interpreted as the config # -# file. Optionally, zero arguments can be passed if BIN_FILE, and optinally # -# CONFIG_FILE are set in the calling script. # -############################################################################### -chk_stat() -{ - if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then - BIN_FILE="${1}" - if [ -z "${2}" ]; then - CONFIG_FILE="" - else - CONFIG_FILE="${2}" - fi - elif [ -z "${BIN_FILE}" ]; then - echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'" - exit 1 # Generic Error - fi - - if [ ! -e "${BIN_FILE}" ]; then - log_failure_msg "${BIN_FILE} not installed" && - exit 5 - fi - - if [ ! -z "${CONFIG_FILE}" ]; then - if [ ! -e "${CONFIG_FILE}" ]; then - log_failure_msg "${CONFIG_FILE} does not exist" && - exit 6 - fi - fi -} - -################################ loadproc() ################################### -# loadproc is just a wraper to start_daemon for simple scripts, which will # -# require no arguments if $BIN_FILE is set. # -############################################################################### -loadproc() -{ - start_daemon "${BIN_FILE}" "${@}" -} - -################################ endproc() #################################### -# endproc, like loadproc, is just a wraper to killproc for simplicity and is # -# dependent on $BIN_FILE being set. # -############################################################################### -endproc() -{ - killproc "${BIN_FILE}" "${@}" -} - -############################### statusproc() ################################## -# statusproc checks the status of a particular binary and displays the # -# appropriate message (running or not running) and exits on the return value # -# of pidofproc. This function accepts two string arguments or zero arguments # -# if BIN_FILE and MESSAGE are set, else it requires the bin file as the first # -# argument, and the message as the second. Both must be enclosed in quotes. # -############################################################################### -statusproc() -{ - if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then - BIN_FILE="${1}" - MESSAGE="${2}" - elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then - echo "Usage: 'statusproc BIN_FILE MESSAGE'" - exit 1 # Generic Error - fi - - pidlist=`pidofproc "${BIN_FILE}"` - STATUS=$? - echo "Checking ${MESSAGE} status:" - if [ "${STATUS}" -eq "0" ]; then - log_success_msg "Running with PID(s) ${pidlist}" - else - log_warning_msg "Not running!" - fi - - return "${STATUS}" -} - -############################### reloadproc() ################################## -# reloadproc sends a HUP signal to the running program (relaod configuration) # -# It optionally, using the -force switch, checks the status of a particular # -# program and starts it if it is not already running. This function accepts # -# one optional switch (must be the first argument), and either two, or zero # -# string arguments. If BIN_FILE and MESSAGE are set in the script's # -# environment, it will use those values, else it requires the bin file as # -# the first argument (following -force if used), and the message as the # -# second. Both must be enclosed in quotes. If the force option is used, it # -# follows the LSB definition of 'force-reload' - the program is started if # -# not already running. # -############################################################################### -reloadproc() -{ - local force="0" - if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then - force="1" - shift 1 - fi - - if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then - BIN_FILE="${1}" - MESSAGE="${2}" - elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then - echo "Usage: 'reloadproc BIN_FILE MESSAGE'" - exit 1 # Generic Error - fi - - - -} - -############################## evaluate_retval() ############################### -# evaluate_retval requires that you pass exactly one evaluation parameter of # -# (start, stop, other) based on the previous action that is being evaluated. # -# This function is intended for use with start_daemon and killproc to # -# interpret the LSB exit codes properly, othewise the checks only for success # -# or failure. # -################################################################################ -evaluate_retval() -{ - local error_value="${?}" - - # Handle LSB defined return values - case "${1}" in - - start) - case "${error_value}" in - 0) - log_success_msg "Starting ${MESSAGE} " - return "${error_value}" - ;; - 2) - log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!" - return "${error_value}" - ;; - 5) - log_failure_msg "Starting ${MESSAGE} Error: Not available!" - return "${error_value}" - ;; - *) - log_failure_msg "Starting ${MESSAGE} Error: General failure!" - return "${error_value}" - ;; - esac - ;; - - stop) - case "${error_value}" in - 0) - log_success_msg "Stopping ${MESSAGE} " - return "${error_value}" - ;; - 2) - log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!" - return "${error_value}" - ;; - 5) - log_failure_msg "Stopping ${MESSAGE} Error: Not available!" - return "${error_value}" - ;; - 7) - log_warning_msg "Stopping ${MESSAGE} Warning: Not running!" - return "${error_value}" - ;; - *) - log_failure_msg "Stopping ${MESSAGE} Error: General failure!" - return "${error_value}" - ;; - esac - ;; - - force-reload) - message="Forcefully reloading " - ;; - - reload) - message="Reloading " - ;; - - restart) - message="Restarting " - ;; - - try-restart) - message="Trying restart " - ;; - - standard) - # $message or $MESSAGE must be set, but not both in order - # to use the 'standard' target. - ;; - esac - - # Print messages for the generic force-reload, reload, restart, - # and try-restart targets - if [ "${error_value}" -eq "0" ] - then - log_success_msg "${message}${MESSAGE} " - return "${error_value}" - else - log_failure_msg "${message}${MESSAGE} " - return "${error_value}" - fi -} - diff --git a/lsb-bootscripts/etc/init.d/mountvirtfs b/lsb-bootscripts/etc/init.d/mountvirtfs index 994976934..382404cc1 100644 --- a/lsb-bootscripts/etc/init.d/mountvirtfs +++ b/lsb-bootscripts/etc/init.d/mountvirtfs @@ -9,8 +9,8 @@ # Should-Stop: # Default-Start: S # Default-Stop: -# Short-Description: Mounts /sys, /proc, and /run virtual (virtel) filesystems. -# Description: Mounts /sys, /proc, and run virtual (virtel) filesystems. +# Short-Description: Mounts /sys, /proc, and /run virtual (kernel) filesystems. +# Description: Mounts /sys, /proc, and run virtual (kernel) filesystems. # X-LFS-Provided-By: LFS ### END INIT INFO @@ -18,7 +18,7 @@ case "${1}" in start) - message="Mounting virtel-based file systems:" + message="Mounting virtual file systems:" if ! mountpoint /proc > /dev/null; then message="${message}${INFO} /proc${NORMAL}" diff --git a/lsb-bootscripts/etc/init.d/udev b/lsb-bootscripts/etc/init.d/udev index fd17b5e94..9f04ecb9e 100644 --- a/lsb-bootscripts/etc/init.d/udev +++ b/lsb-bootscripts/etc/init.d/udev @@ -73,7 +73,8 @@ case "${1}" in # Now traverse /sys in order to "coldplug" devices that have # already been discovered - /sbin/udevadm trigger --action=add + /sbin/udevadm trigger --action=add --type=subsystems + /sbin/udevadm trigger --action=add --type=devices # Now wait for udevd to process the uevents we triggered /sbin/udevadm settle diff --git a/lsb-bootscripts/lib/lsb/init-functions b/lsb-bootscripts/lib/lsb/init-functions index 338f3e00b..39e4d2318 100644 --- a/lsb-bootscripts/lib/lsb/init-functions +++ b/lsb-bootscripts/lib/lsb/init-functions @@ -8,29 +8,24 @@ if [ "${RC_BASE}" = "" ]; then . /etc/default/rc fi -# Source the distro functions file -if [ "${DISTRO_MINI}" != "" ]; then - . "${RC_BASE}/init.d/${DISTRO_MINI}-functions" -fi - -################################################################################ -# start_daemon() # -# Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] # -# # -# Purpose: This runs the specified program as a daemon # -# # -# Inputs: -f: (force) run the program even if it is already running. # -# -n nicelevel: specify a nice level. See 'man nice(1)'. # -# -p pidfile: use the specified file to determine PIDs. # -# pathname: the complete path to the specified program # -# args: additional arguments passed to the program (pathname) # -# # -# Return values (as defined by LSB exit codes): # -# 0 - program is running or service is OK # -# 1 - generic or unspecified error # -# 2 - invalid or excessive argument(s) # -# 5 - program is not installed # -################################################################################ +############################################################################### +# start_daemon() # +# Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] # +# # +# Purpose: This runs the specified program as a daemon # +# # +# Inputs: -f: (force) run the program even if it is already running. # +# -n nicelevel: specify a nice level. See 'man nice(1)'. # +# -p pidfile: use the specified file to determine PIDs. # +# pathname: the complete path to the specified program # +# args: additional arguments passed to the program (pathname) # +# # +# Return values (as defined by LSB exit codes): # +# 0 - program is running or service is OK # +# 1 - generic or unspecified error # +# 2 - invalid or excessive argument(s) # +# 5 - program is not installed # +############################################################################### start_daemon() { local force="" @@ -127,25 +122,25 @@ start_daemon() } -################################################################################ -# killproc() # -# Usage: killproc [-p pidfile] pathname [signal] # -# # -# Purpose: Send control signals to running processes # -# # -# Inputs: -p pidfile, uses the specified pidfile # -# pathname, pathname to the specified program # -# signal, send this signal to pathname # -# # -# Return values (as defined by LSB exit codes): # -# 0 - program (pathname) has stopped/is already stopped or a # -# running program has been sent specified signal and stopped # -# successfully # -# 1 - generic or unspecified error # -# 2 - invalid or excessive argument(s) # -# 5 - program is not installed # -# 7 - program is not running and a signal was supplied # -################################################################################ +############################################################################### +# killproc() # +# Usage: killproc [-p pidfile] pathname [signal] # +# # +# Purpose: Send control signals to running processes # +# # +# Inputs: -p pidfile, uses the specified pidfile # +# pathname, pathname to the specified program # +# signal, send this signal to pathname # +# # +# Return values (as defined by LSB exit codes): # +# 0 - program (pathname) has stopped/is already stopped or a # +# running program has been sent specified signal and stopped # +# successfully # +# 1 - generic or unspecified error # +# 2 - invalid or excessive argument(s) # +# 5 - program is not installed # +# 7 - program is not running and a signal was supplied # +############################################################################### killproc() { local pidfile @@ -335,20 +330,20 @@ killproc() fi } -################################################################################ -# pidofproc() # -# Usage: pidofproc [-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 # -# # -# Return values (as defined by LSB status codes): # -# 0 - Success (PIDs to stdout) # -# 1 - Program is dead, PID file still exists (remaining PIDs output) # -# 3 - Program is not running (no output) # -################################################################################ +############################################################################### +# pidofproc() # +# Usage: pidofproc [-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 # +# # +# Return values (as defined by LSB status codes): # +# 0 - Success (PIDs to stdout) # +# 1 - Program is dead, PID file still exists (remaining PIDs output) # +# 3 - Program is not running (no output) # +############################################################################### pidofproc() { @@ -427,18 +422,19 @@ local exitstatus="0" return "${exitstatus}" fi } -################################################################################ -# log_success_msg() # -# Usage: log_success_msg [$MESSAGE | "message"] # -# # -# Purpose: Print a successful status message to the screen and optionally # -# a boot log file. # -# # -# Inputs: accepts one string value, either a quoted string or optionally # -# the value of $MESSAGE if set in the running environment. # -# # -# Return values: Not used # -################################################################################ + +############################################################################### +# log_success_msg() # +# Usage: log_success_msg [$MESSAGE | "message"] # +# # +# Purpose: Print a successful status message to the screen and optionally # +# a boot log file. # +# # +# Inputs: accepts one string value, either a quoted string or optionally # +# the value of $MESSAGE if set in the running environment. # +# # +# Return values: Not used # +############################################################################### log_success_msg() { echo -n -e "${PREFIX_SUCCESS}${@}" @@ -456,18 +452,18 @@ log_success_msg() return 0 } -################################################################################ -# log_failure_msg() # -# Usage: log_failure_msg [$MESSAGE | "message"] # -# # -# Purpose: Print a failure status message to the screen and optionally # -# a boot log file. # -# # -# Inputs: accepts one string value, either a quoted string or optionally # -# the value of $MESSAGE if set in the running environment. # -# # -# Return values: Not used # -################################################################################ +############################################################################### +# log_failure_msg() # +# Usage: log_failure_msg [$MESSAGE | "message"] # +# # +# Purpose: Print a failure status message to the screen and optionally # +# a boot log file. # +# # +# Inputs: accepts one string value, either a quoted string or optionally # +# the value of $MESSAGE if set in the running environment. # +# # +# Return values: Not used # +############################################################################### log_failure_msg() { echo -n -e "${PREFIX_FAILURE}${@}" @@ -485,18 +481,18 @@ log_failure_msg() return 0 } -################################################################################ -# log_warning_msg() # -# Usage: log_warning_msg [$MESSAGE | "message"] # -# # -# Purpose: Print a warning status message to the screen and optionally # -# a boot log file. # -# # -# Inputs: accepts one string value, either a quoted string or optionally # -# the value of $MESSAGE if set in the running environment. # -# # -# Return values: Not used # -################################################################################ +############################################################################### +# log_warning_msg() # +# Usage: log_warning_msg [$MESSAGE | "message"] # +# # +# Purpose: Print a warning status message to the screen and optionally # +# a boot log file. # +# # +# Inputs: accepts one string value, either a quoted string or optionally # +# the value of $MESSAGE if set in the running environment. # +# # +# Return values: Not used # +############################################################################### log_warning_msg() { echo -n -e "${PREFIX_WARNING}${@}" @@ -514,20 +510,22 @@ log_warning_msg() return 0 } -################################################################################ -# check_signal() # -# Usage: check_signal [ -{signal} | {signal} ] # -# # -# Purpose: Check for a valid signal. This is not defined by any LSB draft, # -# however, it is required to check the signals to determine if the # -# signals chosen are invalid arguments to the other functions. # -# # -# Inputs: accepts a single string value in the form or -{signal} or {signal} # -# # -# Return values: # -# 0 - Success (signal is valid # -# 1 - Signal is not valid # -################################################################################ +# The remaining fucntions are distro specific and are not defined by the LSB + +############################################################################### +# check_signal() # +# Usage: check_signal [ -{signal} | {signal} ] # +# # +# Purpose: Check for a valid signal. This is not defined by any LSB draft, # +# however, it is required to check the signals to determine if the # +# signals chosen are invalid arguments to the other functions. # +# # +# Inputs: accepts a single string value in the form or -{signal} or {signal} # +# # +# Return values: # +# 0 - Success (signal is valid # +# 1 - Signal is not valid # +############################################################################### check_signal() { local valsig @@ -548,22 +546,21 @@ check_signal() fi } - -################################################################################ -# check_sig_type() # -# Usage: check_signal [ -{signal} | {signal} ] # -# # -# Purpose: Check if signal is a program termination signal or a control signal # -# This is not defined by any LSB draft, however, it is required to # -# check the signals to determine if they are intended to end a # -# program or simply to control it. # -# # -# Inputs: accepts a single string value in the form or -{signal} or {signal} # -# # -# Return values: # -# 0 - Signal is used for program termination # -# 1 - Signal is used for program control # -################################################################################ +############################################################################### +# check_sig_type() # +# Usage: check_signal [ -{signal} | {signal} ] # +# # +# Purpose: Check if signal is a program termination signal or a control # +# signal. This is not defined by any LSB draft, however, it is # +# required to check the signals to determine if they are intended # +# to end a program or simply to control it. # +# # +# Inputs: accepts a single string value in the form or -{signal} or {signal} # +# # +# Return values: # +# 0 - Signal is used for program termination # +# 1 - Signal is used for program control # +############################################################################### check_sig_type() { local valsig @@ -580,4 +577,259 @@ check_sig_type() fi } +############################################################################### +# chkstat() # +# Usage: chckstat BIN_FILE {CONFIG_FILE} # +# # +# Purpose: chk_stat checks the status of a script by checking for both a # +# binary file to execute, and if set, a config file that may be # +# needed for the program to run successfully. # +# # +# Inputs: accepts first argument of an executable file, and optionally a # +# second arugument of a configuration file. If BIN_FILE and # +# CONFIG_FILE are set in the calling environment, either or both # +# arguments may be omitted. # +# # +# Return values: # +# 0 - The executable, and optionally the configuration file exists # +# 2 - Invalid or excessive arguments # +# 5 - BIN_FILE does not exist # +# 6 - CONFIG_FILE (if set) does not exist # +############################################################################### +chk_stat() +{ + if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then + BIN_FILE="${1}" + if [ -z "${2}" ]; then + CONFIG_FILE="" + else + CONFIG_FILE="${2}" + fi + elif [ -z "${BIN_FILE}" ]; then + echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'" + exit 1 # Generic Error + fi + + if [ ! -e "${BIN_FILE}" ]; then + log_failure_msg "${BIN_FILE} not installed" && + exit 5 + fi + + if [ ! -z "${CONFIG_FILE}" ]; then + if [ ! -e "${CONFIG_FILE}" ]; then + log_failure_msg "${CONFIG_FILE} does not exist" && + exit 6 + fi + fi +} + +############################################################################### +# loadproc() # +# Usage: loadproc {arguments} # +# # +# Purpose: loadproc is just a wrapper to start_daemon for simple scripts, # +# which will require no aruguments if $BIN_FILE is set. # +# # +# Inputs: Any optional arguments passed to loadproc will be passed on to the # +# executable defined by $BIN_FILE. # +# # +# Return values: (none) # +############################################################################### +loadproc() +{ + start_daemon "${BIN_FILE}" "${@}" +} + +############################################################################### +# endproc() # +# Usage: endproc {arguments} # +# # +# Purpose: endproc is just a wrapper to killproc for simple scripts, which # +# which will require no aruguments if $BIN_FILE is set. # +# # +# Inputs: Any optional arguments passed to endproc will be passed on to the # +# executable defined by $BIN_FILE. # +# # +# Return values: (none) # +############################################################################### +endproc() +{ + killproc "${BIN_FILE}" "${@}" +} + +############################################################################### +# statusproc() # +# Usage: statusproc $BIN_FILE $MESSAGE # +# # +# Purpose: stautsproc is just a wrapper to pidofproc for simple scripts, # +# which will require no aruguments if $BIN_FILE and MESSAGE are set. # +# # +# Inputs: accepts first argument of an executable file, and a second message # +# arugument "MESSAGE" to be displayed. If BIN_FILE and MESSAGE are # +# set in the calling environment, both arguments may be omitted. # +# # +# Return values: exit values of pidofproc # +############################################################################### +statusproc() +{ + if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then + BIN_FILE="${1}" + MESSAGE="${2}" + elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then + echo "Usage: 'statusproc BIN_FILE MESSAGE'" + exit 1 # Generic Error + fi + + pidlist=`pidofproc "${BIN_FILE}"` + STATUS=$? + echo "Checking ${MESSAGE} status:" + if [ "${STATUS}" -eq "0" ]; then + log_success_msg "Running with PID(s) ${pidlist}" + else + log_warning_msg "Not running!" + fi + + return "${STATUS}" +} + +############################################################################### +# reloadproc() # +# Usage: reloadproc {--force} $BIN_FILE $MESSAGE # +# # +# Purpose: reloadproc sends a HUP signal to the running program (relaod # +# configuration). It optionally, using the -force switch, checks the # +# status of a particular program and starts it if it is not already # +# running. # +# # +# Inputs: accepts one optional switch (must be the first argument), and # +# either two, or zero string arguments. If BIN_FILE and MESSAGE are # +# set in the calling envirnoment it will use those values, else it # +# requires the bin file as the first argument (following -force if # +# used), and the message as the second. If the --force argument is # +# given, it follows the LSB definition of 'force-reload' - the # +# program is started if not already running. # +# # +# Return values: 1 - generic error # +############################################################################### +reloadproc() +{ + local force="0" + if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then + force="1" + shift 1 + fi + + if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then + BIN_FILE="${1}" + MESSAGE="${2}" + elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then + echo "Usage: 'reloadproc BIN_FILE MESSAGE'" + exit 1 # Generic Error + fi +} + +############################################################################### +# evaluate_retval() # +# Usage: evaluate_retval \ # +# [standard|start|stop|reload|force-reload|restart|try-restart] # +# # +# Purpose: determines the sucess or failure of a previous command based on # +# LSB exit values, and prints messages to the screen using the # +# log_*_msg() functions. # +# # +# Inputs: accepts one argument which determines the output of the message # +# displayed on the screen based on the LSB input values for init # +# scripts. The 'standard' argument makes no changes to the value of # +# $message or $MESSAGE, but only one can be set in the calling # +# environment. # +# # +# Return values: (none) # +############################################################################### +evaluate_retval() +{ + local error_value="${?}" + + # Handle LSB defined return values + case "${1}" in + + start) + case "${error_value}" in + 0) + log_success_msg "Starting ${MESSAGE} " + return "${error_value}" + ;; + 2) + log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!" + return "${error_value}" + ;; + 5) + log_failure_msg "Starting ${MESSAGE} Error: Not available!" + return "${error_value}" + ;; + *) + log_failure_msg "Starting ${MESSAGE} Error: General failure!" + return "${error_value}" + ;; + esac + ;; + + stop) + case "${error_value}" in + 0) + log_success_msg "Stopping ${MESSAGE} " + return "${error_value}" + ;; + 2) + log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!" + return "${error_value}" + ;; + 5) + log_failure_msg "Stopping ${MESSAGE} Error: Not available!" + return "${error_value}" + ;; + 7) + log_warning_msg "Stopping ${MESSAGE} Warning: Not running!" + return "${error_value}" + ;; + *) + log_failure_msg "Stopping ${MESSAGE} Error: General failure!" + return "${error_value}" + ;; + esac + ;; + + force-reload) + message="Forcefully reloading " + ;; + + reload) + message="Reloading " + ;; + + restart) + message="Restarting " + ;; + + try-restart) + message="Trying restart " + ;; + + standard) + # $message or $MESSAGE must be set, but not both in order + # to use the 'standard' target. + ;; + esac + + # Print messages for the generic force-reload, reload, restart, + # and try-restart targets + if [ "${error_value}" -eq "0" ] + then + log_success_msg "${message}${MESSAGE} " + return "${error_value}" + else + log_failure_msg "${message}${MESSAGE} " + return "${error_value}" + fi +} + # End /lib/lsb/init-functions |