[1c48007] | 1 | # Begin /etc/init.d/lfs-functions
|
---|
| 2 | # Provides LFS specific functions for LSB style bootscripts
|
---|
| 3 |
|
---|
| 4 | ################################# chkstat() ###################################
|
---|
| 5 | # chk_stat checks the status of a script by checking for both a binary file #
|
---|
| 6 | # to execute, and if set, a config file that may be needed for the program #
|
---|
| 7 | # to run successfully. The calling script will exit with a return value of 5 #
|
---|
| 8 | # if the binary does not exist, and a value of 6 if the needed config file is #
|
---|
| 9 | # unavailable as per LSB requirements. This function accepts zero, one, or #
|
---|
| 10 | # two string arguments. If arguments are passed, the first must be a bin #
|
---|
| 11 | # file. If a second argument is passed, it is interpreted as the config #
|
---|
| 12 | # file. Optionally, zero arguments can be passed if BIN_FILE, and optinally #
|
---|
| 13 | # CONFIG_FILE are set in the calling script. #
|
---|
| 14 | ###############################################################################
|
---|
| 15 | chk_stat()
|
---|
| 16 | {
|
---|
| 17 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 18 | BIN_FILE="${1}"
|
---|
| 19 | if [ -z "${2}" ]; then
|
---|
| 20 | CONFIG_FILE=""
|
---|
| 21 | else
|
---|
| 22 | CONFIG_FILE="${2}"
|
---|
| 23 | fi
|
---|
| 24 | elif [ -z "${BIN_FILE}" ]; then
|
---|
| 25 | echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'"
|
---|
| 26 | exit 1 # Generic Error
|
---|
| 27 | fi
|
---|
| 28 |
|
---|
| 29 | if [ ! -e "${BIN_FILE}" ]; then
|
---|
| 30 | log_failure_msg "${BIN_FILE} not installed" &&
|
---|
| 31 | exit 5
|
---|
| 32 | fi
|
---|
| 33 |
|
---|
| 34 | if [ ! -z "${CONFIG_FILE}" ]; then
|
---|
| 35 | if [ ! -e "${CONFIG_FILE}" ]; then
|
---|
| 36 | log_failure_msg "${CONFIG_FILE} does not exist" &&
|
---|
| 37 | exit 6
|
---|
| 38 | fi
|
---|
| 39 | fi
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | ################################ loadproc() ###################################
|
---|
| 43 | # loadproc is just a wraper to start_daemon for simple scripts, which will #
|
---|
| 44 | # require no arguments if $BIN_FILE is set. #
|
---|
| 45 | ###############################################################################
|
---|
| 46 | loadproc()
|
---|
| 47 | {
|
---|
| 48 | start_daemon "${BIN_FILE}" "${@}"
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | ################################ endproc() ####################################
|
---|
| 52 | # endproc, like loadproc, is just a wraper to killproc for simplicity and is #
|
---|
| 53 | # dependent on $BIN_FILE being set. #
|
---|
| 54 | ###############################################################################
|
---|
| 55 | endproc()
|
---|
| 56 | {
|
---|
| 57 | killproc "${BIN_FILE}" "${@}"
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | ############################### statusproc() ##################################
|
---|
| 61 | # statusproc checks the status of a particular binary and displays the #
|
---|
| 62 | # appropriate message (running or not running) and exits on the return value #
|
---|
| 63 | # of pidofproc. This function accepts two string arguments or zero arguments #
|
---|
| 64 | # if BIN_FILE and MESSAGE are set, else it requires the bin file as the first #
|
---|
| 65 | # argument, and the message as the second. Both must be enclosed in quotes. #
|
---|
| 66 | ###############################################################################
|
---|
| 67 | statusproc()
|
---|
| 68 | {
|
---|
| 69 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 70 | BIN_FILE="${1}"
|
---|
| 71 | MESSAGE="${2}"
|
---|
| 72 | elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
|
---|
| 73 | echo "Usage: 'statusproc BIN_FILE MESSAGE'"
|
---|
| 74 | exit 1 # Generic Error
|
---|
| 75 | fi
|
---|
| 76 |
|
---|
| 77 | pidlist=`pidofproc "${BIN_FILE}"`
|
---|
| 78 | STATUS=$?
|
---|
| 79 | echo "Checking ${MESSAGE} status:"
|
---|
| 80 | if [ "${STATUS}" = "0" ]; then
|
---|
| 81 | log_success_msg "Running with PID(s) ${pidlist}"
|
---|
| 82 | else
|
---|
| 83 | log_warning_msg "Not running!"
|
---|
| 84 | fi
|
---|
| 85 |
|
---|
| 86 | return "${STATUS}"
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | ############################### reloadproc() ##################################
|
---|
| 90 | # reloadproc sends a HUP signal to the running program (relaod configuration) #
|
---|
| 91 | # It optionally, using the -force switch, checks the status of a particular #
|
---|
| 92 | # program and starts it if it is not already running. This function accepts #
|
---|
| 93 | # one optional switch (must be the first argument), and either two, or zero #
|
---|
| 94 | # string arguments. If BIN_FILE and MESSAGE are set in the script's #
|
---|
| 95 | # environment, it will use those values, else it requires the bin file as #
|
---|
| 96 | # the first argument (following -force if used), and the message as the #
|
---|
| 97 | # second. Both must be enclosed in quotes. If the force option is used, it #
|
---|
| 98 | # follows the LSB definition of 'force-reload' - the program is started if #
|
---|
| 99 | # not already running. #
|
---|
| 100 | ###############################################################################
|
---|
| 101 | reloadproc()
|
---|
| 102 | {
|
---|
| 103 | local force="0"
|
---|
| 104 | if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then
|
---|
| 105 | force="1"
|
---|
| 106 | shift 1
|
---|
| 107 | fi
|
---|
| 108 |
|
---|
| 109 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 110 | BIN_FILE="${1}"
|
---|
| 111 | MESSAGE="${2}"
|
---|
| 112 | elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
|
---|
| 113 | echo "Usage: 'reloadproc BIN_FILE MESSAGE'"
|
---|
| 114 | exit 1 # Generic Error
|
---|
| 115 | fi
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | ############################## evaluate_retval() ###############################
|
---|
| 122 | # evaluate_retval requires that you pass exactly one evaluation parameter of #
|
---|
| 123 | # (start, stop, other) based on the previous action that is being evaluated. #
|
---|
| 124 | # This function is intended for use with start_daemon and killproc to #
|
---|
| 125 | # interpret the LSB exit codes properly, othewise the checks only for success #
|
---|
| 126 | # or failure. #
|
---|
| 127 | ################################################################################
|
---|
| 128 | evaluate_retval()
|
---|
| 129 | {
|
---|
| 130 | local error_value="${?}"
|
---|
| 131 |
|
---|
| 132 | # Handle LSB defined return values
|
---|
| 133 | case "${1}" in
|
---|
| 134 |
|
---|
| 135 | start)
|
---|
| 136 | case "${error_value}" in
|
---|
| 137 | 0)
|
---|
| 138 | log_success_msg "Starting ${MESSAGE} "
|
---|
| 139 | return "${error_value}"
|
---|
| 140 | ;;
|
---|
| 141 | 2)
|
---|
| 142 | log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!"
|
---|
| 143 | return "${error_value}"
|
---|
| 144 | ;;
|
---|
| 145 | 5)
|
---|
| 146 | log_failure_msg "Starting ${MESSAGE} Error: Not available!"
|
---|
| 147 | return "${error_value}"
|
---|
| 148 | ;;
|
---|
| 149 | *)
|
---|
| 150 | log_failure_msg "Starting ${MESSAGE} Error: General failure!"
|
---|
| 151 | return "${error_value}"
|
---|
| 152 | ;;
|
---|
| 153 | esac
|
---|
| 154 | ;;
|
---|
| 155 |
|
---|
| 156 | stop)
|
---|
| 157 | case "${error_value}" in
|
---|
| 158 | 0)
|
---|
| 159 | log_success_msg "Stopping ${MESSAGE} "
|
---|
| 160 | return "${error_value}"
|
---|
| 161 | ;;
|
---|
| 162 | 2)
|
---|
| 163 | log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!"
|
---|
| 164 | return "${error_value}"
|
---|
| 165 | ;;
|
---|
| 166 | 5)
|
---|
| 167 | log_failure_msg "Stopping ${MESSAGE} Error: Not available!"
|
---|
| 168 | return "${error_value}"
|
---|
| 169 | ;;
|
---|
| 170 | 7)
|
---|
| 171 | log_warning_msg "Stopping ${MESSAGE} Warning: Not running!"
|
---|
| 172 | return "${error_value}"
|
---|
| 173 | ;;
|
---|
| 174 | *)
|
---|
| 175 | log_failure_msg "Stopping ${MESSAGE} Error: General failure!"
|
---|
| 176 | return "${error_value}"
|
---|
| 177 | ;;
|
---|
| 178 | esac
|
---|
| 179 | ;;
|
---|
| 180 |
|
---|
| 181 | force-reload)
|
---|
| 182 | message="Forcefully reloading "
|
---|
| 183 | ;;
|
---|
| 184 |
|
---|
| 185 | reload)
|
---|
| 186 | message="Reloading "
|
---|
| 187 | ;;
|
---|
| 188 |
|
---|
| 189 | restart)
|
---|
| 190 | message="Restarting "
|
---|
| 191 | ;;
|
---|
| 192 |
|
---|
| 193 | try-restart)
|
---|
| 194 | message="Trying restart "
|
---|
| 195 | ;;
|
---|
| 196 |
|
---|
| 197 | standard)
|
---|
| 198 | # $message or $MESSAGE must be set, but not both in order
|
---|
| 199 | # to use the 'standard' target.
|
---|
| 200 | ;;
|
---|
| 201 | esac
|
---|
| 202 |
|
---|
| 203 | # Print messages for the generic force-reload, reload, restart,
|
---|
| 204 | # and try-restart targets
|
---|
| 205 | if [ "${error_value}" = "0" ]
|
---|
| 206 | then
|
---|
| 207 | log_success_msg "${message}${MESSAGE} "
|
---|
| 208 | return "${error_value}"
|
---|
| 209 | else
|
---|
| 210 | log_failure_msg "${message}${MESSAGE} "
|
---|
| 211 | return "${error_value}"
|
---|
| 212 | fi
|
---|
| 213 | }
|
---|
| 214 |
|
---|