[1c48007] | 1 | # Begin /lib/lsb/init-funtions
|
---|
| 2 |
|
---|
| 3 | # Provides initialization funtions as defined by the Linux Standard Base
|
---|
| 4 | # specification, version 3.1.0
|
---|
| 5 |
|
---|
| 6 | # Source rc configuration if not inherited from the environment
|
---|
| 7 | if [ "${RC_BASE}" = "" ]; then
|
---|
[dc55fb5e] | 8 | . /etc/default/rc
|
---|
[1c48007] | 9 | fi
|
---|
| 10 |
|
---|
[d93bdd1e] | 11 | ###############################################################################
|
---|
| 12 | # start_daemon() #
|
---|
| 13 | # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] #
|
---|
| 14 | # #
|
---|
| 15 | # Purpose: This runs the specified program as a daemon #
|
---|
| 16 | # #
|
---|
| 17 | # Inputs: -f: (force) run the program even if it is already running. #
|
---|
| 18 | # -n nicelevel: specify a nice level. See 'man nice(1)'. #
|
---|
| 19 | # -p pidfile: use the specified file to determine PIDs. #
|
---|
| 20 | # pathname: the complete path to the specified program #
|
---|
| 21 | # args: additional arguments passed to the program (pathname) #
|
---|
| 22 | # #
|
---|
| 23 | # Return values (as defined by LSB exit codes): #
|
---|
| 24 | # 0 - program is running or service is OK #
|
---|
| 25 | # 1 - generic or unspecified error #
|
---|
| 26 | # 2 - invalid or excessive argument(s) #
|
---|
| 27 | # 5 - program is not installed #
|
---|
| 28 | ###############################################################################
|
---|
[1c48007] | 29 | start_daemon()
|
---|
| 30 | {
|
---|
| 31 | local force=""
|
---|
| 32 | local nice="0"
|
---|
| 33 | local pidfile=""
|
---|
| 34 | local pidlist=""
|
---|
| 35 | local retval=""
|
---|
| 36 |
|
---|
| 37 | # Process arguments
|
---|
| 38 | while true
|
---|
| 39 | do
|
---|
| 40 | case "${1}" in
|
---|
| 41 |
|
---|
| 42 | -f)
|
---|
| 43 | force="1"
|
---|
| 44 | shift 1
|
---|
| 45 | ;;
|
---|
| 46 |
|
---|
| 47 | -n)
|
---|
| 48 | nice="${2}"
|
---|
| 49 | shift 2
|
---|
| 50 | ;;
|
---|
| 51 |
|
---|
| 52 | -p)
|
---|
| 53 | pidfile="${2}"
|
---|
| 54 | shift 2
|
---|
| 55 | ;;
|
---|
| 56 |
|
---|
| 57 | -*)
|
---|
| 58 | return 2
|
---|
| 59 | ;;
|
---|
| 60 |
|
---|
| 61 | *)
|
---|
| 62 | program="${1}"
|
---|
| 63 | break
|
---|
| 64 | ;;
|
---|
| 65 | esac
|
---|
| 66 | done
|
---|
| 67 |
|
---|
| 68 | # Check for a valid program
|
---|
| 69 | if [ ! -e "${program}" ]
|
---|
| 70 | then
|
---|
| 71 | return 5
|
---|
| 72 | fi
|
---|
| 73 |
|
---|
| 74 | # Execute
|
---|
| 75 | if [ -z "${force}" ]
|
---|
| 76 | then
|
---|
| 77 | if [ -z "${pidfile}" ]
|
---|
| 78 | then
|
---|
| 79 | # determine the pid by discovery
|
---|
| 80 | pidlist=`pidofproc "${1}"`
|
---|
| 81 | retval="${?}"
|
---|
| 82 | else
|
---|
| 83 | # The PID file contains the needed PIDs
|
---|
| 84 | # Note that by LSB requirement, the path must be given to pidofproc,
|
---|
| 85 | # however, it is not used by the current implementation or standard.
|
---|
| 86 | pidlist=`pidofproc -p "${pidfile}" "${1}"`
|
---|
| 87 | retval="${?}"
|
---|
| 88 | fi
|
---|
| 89 |
|
---|
| 90 | # return a value ONLY
|
---|
| 91 | # It is the init script's (or distribution's functions) responsibilty
|
---|
| 92 | # to log messages!
|
---|
| 93 | case "${retval}" in
|
---|
| 94 |
|
---|
| 95 | 0)
|
---|
| 96 | # program is already running correctly, this is a
|
---|
| 97 | # succesful start.
|
---|
| 98 | return 0
|
---|
| 99 | ;;
|
---|
| 100 |
|
---|
| 101 | 1)
|
---|
| 102 | # program is not running, but an invalid pid file exists
|
---|
| 103 | # remove the pid file and continue
|
---|
| 104 | rm -f "${pidfile}"
|
---|
| 105 | ;;
|
---|
| 106 |
|
---|
| 107 | 3)
|
---|
| 108 | # program is not running and no pidfile exists
|
---|
| 109 | # do nothing here, let start_deamon continue.
|
---|
| 110 | ;;
|
---|
| 111 |
|
---|
| 112 | *)
|
---|
| 113 | # Others as returned by status values shall not be interpreted
|
---|
| 114 | # and returned as an unspecified error.
|
---|
| 115 | return 1
|
---|
| 116 | ;;
|
---|
| 117 | esac
|
---|
| 118 | fi
|
---|
| 119 |
|
---|
| 120 | # do the start!
|
---|
| 121 | nice -n "${nice}" "${@}"
|
---|
| 122 |
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[d93bdd1e] | 125 | ###############################################################################
|
---|
| 126 | # killproc() #
|
---|
| 127 | # Usage: killproc [-p pidfile] pathname [signal] #
|
---|
| 128 | # #
|
---|
| 129 | # Purpose: Send control signals to running processes #
|
---|
| 130 | # #
|
---|
| 131 | # Inputs: -p pidfile, uses the specified pidfile #
|
---|
| 132 | # pathname, pathname to the specified program #
|
---|
| 133 | # signal, send this signal to pathname #
|
---|
| 134 | # #
|
---|
| 135 | # Return values (as defined by LSB exit codes): #
|
---|
| 136 | # 0 - program (pathname) has stopped/is already stopped or a #
|
---|
| 137 | # running program has been sent specified signal and stopped #
|
---|
| 138 | # successfully #
|
---|
| 139 | # 1 - generic or unspecified error #
|
---|
| 140 | # 2 - invalid or excessive argument(s) #
|
---|
| 141 | # 5 - program is not installed #
|
---|
| 142 | # 7 - program is not running and a signal was supplied #
|
---|
| 143 | ###############################################################################
|
---|
[1c48007] | 144 | killproc()
|
---|
| 145 | {
|
---|
| 146 | local pidfile
|
---|
| 147 | local program
|
---|
| 148 | local prefix
|
---|
| 149 | local progname
|
---|
| 150 | local signal="-TERM"
|
---|
| 151 | local fallback="-KILL"
|
---|
| 152 | local nosig
|
---|
| 153 | local pidlist
|
---|
| 154 | local retval
|
---|
| 155 | local pid
|
---|
| 156 | local delay="30"
|
---|
| 157 | local piddead
|
---|
| 158 | local dtime
|
---|
| 159 |
|
---|
| 160 | # Process arguments
|
---|
| 161 | while true
|
---|
| 162 | do
|
---|
| 163 | case "${1}" in
|
---|
| 164 |
|
---|
| 165 | -p)
|
---|
| 166 | pidfile="${2}"
|
---|
| 167 | shift 2
|
---|
| 168 | ;;
|
---|
| 169 |
|
---|
| 170 | *)
|
---|
| 171 | program="${1}"
|
---|
| 172 | if [ -n "${2}" ]
|
---|
| 173 | then
|
---|
| 174 | signal="${2}"
|
---|
| 175 | fallback=""
|
---|
| 176 | else
|
---|
| 177 | nosig=1
|
---|
| 178 | fi
|
---|
| 179 |
|
---|
| 180 | # error on additional arguments
|
---|
| 181 | if [ -n "${3}" ]
|
---|
| 182 | then
|
---|
| 183 | return 2
|
---|
| 184 | else
|
---|
| 185 | break
|
---|
| 186 | fi
|
---|
| 187 | ;;
|
---|
| 188 | esac
|
---|
| 189 | done
|
---|
| 190 |
|
---|
| 191 | # Check for a valid program
|
---|
| 192 | if [ ! -e "${program}" ]
|
---|
| 193 | then
|
---|
| 194 | return 5
|
---|
| 195 | fi
|
---|
| 196 |
|
---|
| 197 | # Check for a valid signal
|
---|
| 198 | check_signal "${signal}"
|
---|
[5597318] | 199 | if [ "${?}" -ne "0" ]
|
---|
[1c48007] | 200 | then
|
---|
| 201 | return 2
|
---|
| 202 | fi
|
---|
| 203 |
|
---|
| 204 | # Get a list of pids
|
---|
| 205 | if [ -z "${pidfile}" ]
|
---|
| 206 | then
|
---|
| 207 | # determine the pid by discovery
|
---|
| 208 | pidlist=`pidofproc "${1}"`
|
---|
| 209 | retval="${?}"
|
---|
| 210 | else
|
---|
| 211 | # The PID file contains the needed PIDs
|
---|
| 212 | # Note that by LSB requirement, the path must be given to pidofproc,
|
---|
| 213 | # however, it is not used by the current implementation or standard.
|
---|
| 214 | pidlist=`pidofproc -p "${pidfile}" "${1}"`
|
---|
| 215 | retval="${?}"
|
---|
| 216 | fi
|
---|
| 217 |
|
---|
| 218 | # return a value ONLY
|
---|
| 219 | # It is the init script's (or distribution's functions) responsibilty
|
---|
| 220 | # to log messages!
|
---|
| 221 | case "${retval}" in
|
---|
| 222 |
|
---|
| 223 | 0)
|
---|
| 224 | # program is running correctly
|
---|
| 225 | # do nothing here, let killproc continue.
|
---|
| 226 | ;;
|
---|
| 227 |
|
---|
| 228 | 1)
|
---|
| 229 | # program is not running, but an invalid pid file exists
|
---|
| 230 | # remove the pid file.
|
---|
| 231 | rm -f "${pidfile}"
|
---|
| 232 | # this is only a success if no signal was passed.
|
---|
| 233 | if [ -n "${nosig}" ]
|
---|
| 234 | then
|
---|
| 235 | return 0
|
---|
| 236 | else
|
---|
| 237 | return 7
|
---|
| 238 | fi
|
---|
| 239 | ;;
|
---|
| 240 |
|
---|
| 241 | 3)
|
---|
| 242 | # program is not running and no pidfile exists
|
---|
| 243 | # this is only a success if no signal was passed.
|
---|
| 244 | if [ -n "${nosig}" ]
|
---|
| 245 | then
|
---|
| 246 | return 0
|
---|
| 247 | else
|
---|
| 248 | return 7
|
---|
| 249 | fi
|
---|
| 250 | ;;
|
---|
| 251 |
|
---|
| 252 | *)
|
---|
| 253 | # Others as returned by status values shall not be interpreted
|
---|
| 254 | # and returned as an unspecified error.
|
---|
| 255 | return 1
|
---|
| 256 | ;;
|
---|
| 257 | esac
|
---|
| 258 |
|
---|
| 259 | # perform different actions for exit signals and control signals
|
---|
| 260 | check_sig_type "${signal}"
|
---|
| 261 | if [ "${?}" -eq "0" ] # signal is used to terminate the program
|
---|
| 262 | then
|
---|
| 263 | # account for empty pidlist (pid file still exists and nosignal was given)
|
---|
| 264 | if [ "${pidlist}" != "" ]; then
|
---|
| 265 | #kill the list of pids
|
---|
| 266 | for pid in ${pidlist}
|
---|
| 267 | do
|
---|
| 268 | kill -0 "${pid}" 2> /dev/null
|
---|
| 269 | if [ "${?}" -ne "0" ]; then
|
---|
| 270 | # process is dead, continue to next and assume all is well
|
---|
| 271 | continue
|
---|
| 272 | else
|
---|
| 273 | kill "${signal}" "${pid}" 2> /dev/null
|
---|
| 274 | # Wait up to ${delay}/10 seconds to for "${pid}" to
|
---|
| 275 | # terminate in 10ths of a second
|
---|
[5597318] | 276 | while [ "${delay}" -ne "0" ]
|
---|
[1c48007] | 277 | do
|
---|
| 278 | kill -0 "${pid}" 2> /dev/null || piddead="1"
|
---|
| 279 | if [ "${piddead}" = "1" ]
|
---|
| 280 | then
|
---|
| 281 | break
|
---|
| 282 | fi
|
---|
| 283 | sleep 0.1
|
---|
| 284 | delay="$(( ${delay} - 1 ))"
|
---|
| 285 | done
|
---|
| 286 | # If a fallback is set, and program is still running, then
|
---|
| 287 | # use the fallback
|
---|
| 288 | if [ -n "${fallback}" -a "${piddead}" != "1" ]
|
---|
| 289 | then
|
---|
| 290 | kill "${fallback}" "${pid}" 2> /dev/null
|
---|
| 291 | sleep 1
|
---|
| 292 | # Check again, and fail if still running
|
---|
| 293 | kill -0 "${pid}" 2> /dev/null && return 1
|
---|
| 294 | else
|
---|
| 295 | # just check one last time and if still alive, fail
|
---|
| 296 | sleep 1
|
---|
| 297 | kill -0 "${pid}" 2> /dev/null && return 1
|
---|
| 298 | fi
|
---|
| 299 | fi
|
---|
| 300 | done
|
---|
| 301 | fi
|
---|
| 302 |
|
---|
| 303 | # Check for and remove stale PID files.
|
---|
| 304 | if [ -z "${pidfile}" ]
|
---|
| 305 | then
|
---|
| 306 | #find the basename of $program
|
---|
| 307 | prefix=`echo "${program}" | sed 's/[^/]*$//'`
|
---|
| 308 | progname=`echo "${program}" | sed "s@${prefix}@@"`
|
---|
| 309 | if [ -e "/var/run/${progname}.pid" ]
|
---|
| 310 | then
|
---|
| 311 | rm -f "/var/run/${progname}.pid" 2> /dev/null
|
---|
| 312 | fi
|
---|
| 313 | else
|
---|
| 314 | if [ -e "${pidfile}" ]
|
---|
| 315 | then
|
---|
| 316 | rm -f "${pidfile}" 2> /dev/null
|
---|
| 317 | fi
|
---|
| 318 | fi
|
---|
| 319 |
|
---|
| 320 | # For signals that do not expect a program to exit, simply
|
---|
| 321 | # let kill do it's job, and evaluate kills return for value
|
---|
| 322 | else # check_sig_type - signal is not used to terminate program
|
---|
| 323 | for pid in ${pidlist}
|
---|
| 324 | do
|
---|
| 325 | kill "${signal}" "${pid}"
|
---|
| 326 | if [ "${?}" -ne "0" ]; then
|
---|
| 327 | return 1
|
---|
| 328 | fi
|
---|
| 329 | done
|
---|
| 330 | fi
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[d93bdd1e] | 333 | ###############################################################################
|
---|
| 334 | # pidofproc() #
|
---|
| 335 | # Usage: pidofproc [-p pidfile] pathname #
|
---|
| 336 | # #
|
---|
| 337 | # Purpose: This function returns one or more pid(s) for a particular daemon #
|
---|
| 338 | # #
|
---|
| 339 | # Inputs: -p pidfile, use the specified pidfile instead of pidof #
|
---|
| 340 | # pathname, path to the specified program #
|
---|
| 341 | # #
|
---|
| 342 | # Return values (as defined by LSB status codes): #
|
---|
| 343 | # 0 - Success (PIDs to stdout) #
|
---|
| 344 | # 1 - Program is dead, PID file still exists (remaining PIDs output) #
|
---|
| 345 | # 3 - Program is not running (no output) #
|
---|
| 346 | ###############################################################################
|
---|
[1c48007] | 347 | pidofproc()
|
---|
| 348 | {
|
---|
| 349 |
|
---|
| 350 | local pidfile
|
---|
| 351 | local program
|
---|
| 352 | local prefix
|
---|
| 353 | local progname
|
---|
| 354 | local pidlist
|
---|
| 355 | local lpids
|
---|
| 356 | local exitstatus="0"
|
---|
| 357 |
|
---|
| 358 | # Process arguments
|
---|
| 359 | while true
|
---|
| 360 | do
|
---|
| 361 | case "${1}" in
|
---|
| 362 |
|
---|
| 363 | -p)
|
---|
| 364 | pidfile="${2}"
|
---|
| 365 | shift 2
|
---|
| 366 | ;;
|
---|
| 367 |
|
---|
| 368 | *)
|
---|
| 369 | program="${1}"
|
---|
| 370 | if [ -n "${2}" ]
|
---|
| 371 | then
|
---|
| 372 | # Too many arguments
|
---|
| 373 | # Since this is status, return unknown
|
---|
| 374 | return 4
|
---|
| 375 | else
|
---|
| 376 | break
|
---|
| 377 | fi
|
---|
| 378 | ;;
|
---|
| 379 | esac
|
---|
| 380 | done
|
---|
| 381 |
|
---|
| 382 | # If a PID file is not specified, try and find one.
|
---|
| 383 | if [ -z "${pidfile}" ]
|
---|
| 384 | then
|
---|
| 385 | # get the program's basename
|
---|
| 386 | prefix=`echo "${program}" | sed 's/[^/]*$//'`
|
---|
| 387 | progname=`echo "${program}" | sed "s@${prefix}@@"`
|
---|
| 388 | # if a PID file exists with that name, assume that is it.
|
---|
| 389 | if [ -e "/var/run/${progname}.pid" ]
|
---|
| 390 | then
|
---|
| 391 | pidfile="/var/run/${progname}.pid"
|
---|
| 392 | fi
|
---|
| 393 | fi
|
---|
| 394 |
|
---|
| 395 | # if a PID file is set and exists, use it.
|
---|
| 396 | if [ -n "${pidfile}" -a -e "${pidfile}" ]
|
---|
| 397 | then
|
---|
| 398 | # use the value in the first line of the pidfile
|
---|
| 399 | pidlist=`/bin/head -n1 "${pidfile}"`
|
---|
| 400 | # This can optionally be written as 'sed 1q' to repalce 'head -n1'
|
---|
| 401 | # should LFS move /bin/head to /usr/bin/head
|
---|
| 402 | else
|
---|
| 403 | # use pidof
|
---|
| 404 | pidlist=`pidof "${program}"`
|
---|
| 405 | fi
|
---|
| 406 |
|
---|
| 407 | # Figure out if all listed PIDs are running.
|
---|
| 408 | for pid in ${pidlist}
|
---|
| 409 | do
|
---|
| 410 | kill -0 ${pid} 2> /dev/null
|
---|
[5597318] | 411 | if [ "${?}" -eq "0" ]; then
|
---|
[1c48007] | 412 | lpids="${pids}${pid} "
|
---|
| 413 | else
|
---|
| 414 | exitstatus="1"
|
---|
| 415 | fi
|
---|
| 416 | done
|
---|
| 417 |
|
---|
| 418 | if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
|
---|
| 419 | return 3
|
---|
| 420 | else
|
---|
| 421 | echo "${lpids}"
|
---|
| 422 | return "${exitstatus}"
|
---|
| 423 | fi
|
---|
| 424 | }
|
---|
[d93bdd1e] | 425 |
|
---|
| 426 | ###############################################################################
|
---|
| 427 | # log_success_msg() #
|
---|
| 428 | # Usage: log_success_msg [$MESSAGE | "message"] #
|
---|
| 429 | # #
|
---|
| 430 | # Purpose: Print a successful status message to the screen and optionally #
|
---|
| 431 | # a boot log file. #
|
---|
| 432 | # #
|
---|
| 433 | # Inputs: accepts one string value, either a quoted string or optionally #
|
---|
| 434 | # the value of $MESSAGE if set in the running environment. #
|
---|
| 435 | # #
|
---|
| 436 | # Return values: Not used #
|
---|
| 437 | ###############################################################################
|
---|
[1c48007] | 438 | log_success_msg()
|
---|
| 439 | {
|
---|
| 440 | echo -n -e "${PREFIX_SUCCESS}${@}"
|
---|
| 441 | echo -e "${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
|
---|
| 442 | if [ "${BOOTLOG_ENAB}" = "yes" ]; then
|
---|
| 443 | if [ $( hostname ) = "(none)" ]; then
|
---|
| 444 | BTTIMESPEC=""
|
---|
| 445 | else
|
---|
[67de919] | 446 | BTTIMESPEC="$(echo `date -u +"%b %d %T"` `hostname`) "
|
---|
[1c48007] | 447 | fi
|
---|
[dc55fb5e] | 448 | if [ "${RUNLEVEL}" != "0" -a "${RUNLEVEL}" != "6" ]; then
|
---|
| 449 | echo "${BTTIMESPEC}bootlog: ${@} Successful" >> /run/.bootlog
|
---|
| 450 | fi
|
---|
[1c48007] | 451 | fi
|
---|
| 452 | return 0
|
---|
| 453 | }
|
---|
| 454 |
|
---|
[d93bdd1e] | 455 | ###############################################################################
|
---|
| 456 | # log_failure_msg() #
|
---|
| 457 | # Usage: log_failure_msg [$MESSAGE | "message"] #
|
---|
| 458 | # #
|
---|
| 459 | # Purpose: Print a failure status message to the screen and optionally #
|
---|
| 460 | # a boot log file. #
|
---|
| 461 | # #
|
---|
| 462 | # Inputs: accepts one string value, either a quoted string or optionally #
|
---|
| 463 | # the value of $MESSAGE if set in the running environment. #
|
---|
| 464 | # #
|
---|
| 465 | # Return values: Not used #
|
---|
| 466 | ###############################################################################
|
---|
[1c48007] | 467 | log_failure_msg()
|
---|
| 468 | {
|
---|
| 469 | echo -n -e "${PREFIX_FAILURE}${@}"
|
---|
| 470 | echo -e "${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
|
---|
| 471 | if [ "${BOOTLOG_ENAB}" = "yes" ]; then
|
---|
| 472 | if [ $( hostname ) = "(none)" ]; then
|
---|
| 473 | BTTIMESPEC=""
|
---|
| 474 | else
|
---|
[67de919] | 475 | BTTIMESPEC="$(echo `date -u +"%b %d %T"` `hostname`) "
|
---|
[1c48007] | 476 | fi
|
---|
[dc55fb5e] | 477 | if [ "${RUNLEVEL}" != "0" -a "${RUNLEVEL}" != "6" ]; then
|
---|
| 478 | echo "${BTTIMESPEC}bootlog: ${@} Failed!" >> /run/.bootlog
|
---|
| 479 | fi
|
---|
[1c48007] | 480 | fi
|
---|
| 481 | return 0
|
---|
| 482 | }
|
---|
| 483 |
|
---|
[d93bdd1e] | 484 | ###############################################################################
|
---|
| 485 | # log_warning_msg() #
|
---|
| 486 | # Usage: log_warning_msg [$MESSAGE | "message"] #
|
---|
| 487 | # #
|
---|
| 488 | # Purpose: Print a warning status message to the screen and optionally #
|
---|
| 489 | # a boot log file. #
|
---|
| 490 | # #
|
---|
| 491 | # Inputs: accepts one string value, either a quoted string or optionally #
|
---|
| 492 | # the value of $MESSAGE if set in the running environment. #
|
---|
| 493 | # #
|
---|
| 494 | # Return values: Not used #
|
---|
| 495 | ###############################################################################
|
---|
[1c48007] | 496 | log_warning_msg()
|
---|
| 497 | {
|
---|
| 498 | echo -n -e "${PREFIX_WARNING}${@}"
|
---|
| 499 | echo -e "${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
|
---|
| 500 | if [ "${BOOTLOG_ENAB}" = "yes" ]; then
|
---|
| 501 | if [ $( hostname ) = "(none)" ]; then
|
---|
| 502 | BTTIMESPEC=""
|
---|
| 503 | else
|
---|
[67de919] | 504 | BTTIMESPEC="$(echo `date -u +"%b %d %T"` `hostname`) "
|
---|
[1c48007] | 505 | fi
|
---|
[dc55fb5e] | 506 | if [ "${RUNLEVEL}" != "0" -a "${RUNLEVEL}" != "6" ]; then
|
---|
| 507 | echo "${BTTIMESPEC}bootlog: ${@} Warning" >> /run/.bootlog
|
---|
| 508 | fi
|
---|
[1c48007] | 509 | fi
|
---|
| 510 | return 0
|
---|
| 511 | }
|
---|
| 512 |
|
---|
[d93bdd1e] | 513 | # The remaining fucntions are distro specific and are not defined by the LSB
|
---|
| 514 |
|
---|
| 515 | ###############################################################################
|
---|
| 516 | # check_signal() #
|
---|
| 517 | # Usage: check_signal [ -{signal} | {signal} ] #
|
---|
| 518 | # #
|
---|
| 519 | # Purpose: Check for a valid signal. This is not defined by any LSB draft, #
|
---|
| 520 | # however, it is required to check the signals to determine if the #
|
---|
| 521 | # signals chosen are invalid arguments to the other functions. #
|
---|
| 522 | # #
|
---|
| 523 | # Inputs: accepts a single string value in the form or -{signal} or {signal} #
|
---|
| 524 | # #
|
---|
| 525 | # Return values: #
|
---|
| 526 | # 0 - Success (signal is valid #
|
---|
| 527 | # 1 - Signal is not valid #
|
---|
| 528 | ###############################################################################
|
---|
[1c48007] | 529 | check_signal()
|
---|
| 530 | {
|
---|
| 531 | local valsig
|
---|
| 532 |
|
---|
| 533 | # Add error handling for invalid signals
|
---|
| 534 | valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
|
---|
| 535 | valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
|
---|
| 536 | valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
|
---|
| 537 | valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
|
---|
| 538 | valsig="${valsig} -11 -13 -14 -15"
|
---|
| 539 |
|
---|
| 540 | echo "${valsig}" | grep -- " ${1} " > /dev/null
|
---|
[5597318] | 541 | if [ "${?}" -eq "0" ]
|
---|
[1c48007] | 542 | then
|
---|
| 543 | return 0
|
---|
| 544 | else
|
---|
| 545 | return 1
|
---|
| 546 | fi
|
---|
| 547 | }
|
---|
| 548 |
|
---|
[d93bdd1e] | 549 | ###############################################################################
|
---|
| 550 | # check_sig_type() #
|
---|
| 551 | # Usage: check_signal [ -{signal} | {signal} ] #
|
---|
| 552 | # #
|
---|
| 553 | # Purpose: Check if signal is a program termination signal or a control #
|
---|
| 554 | # signal. This is not defined by any LSB draft, however, it is #
|
---|
| 555 | # required to check the signals to determine if they are intended #
|
---|
| 556 | # to end a program or simply to control it. #
|
---|
| 557 | # #
|
---|
| 558 | # Inputs: accepts a single string value in the form or -{signal} or {signal} #
|
---|
| 559 | # #
|
---|
| 560 | # Return values: #
|
---|
| 561 | # 0 - Signal is used for program termination #
|
---|
| 562 | # 1 - Signal is used for program control #
|
---|
| 563 | ###############################################################################
|
---|
[1c48007] | 564 | check_sig_type()
|
---|
| 565 | {
|
---|
| 566 | local valsig
|
---|
| 567 |
|
---|
| 568 | # The list of termination signals (limited to generally used items)
|
---|
| 569 | valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
|
---|
| 570 |
|
---|
| 571 | echo "${valsig}" | grep -- " ${1} " > /dev/null
|
---|
[5597318] | 572 | if [ "${?}" -eq "0" ]
|
---|
[1c48007] | 573 | then
|
---|
| 574 | return 0
|
---|
| 575 | else
|
---|
| 576 | return 1
|
---|
| 577 | fi
|
---|
| 578 | }
|
---|
| 579 |
|
---|
[d93bdd1e] | 580 | ###############################################################################
|
---|
| 581 | # chkstat() #
|
---|
| 582 | # Usage: chckstat BIN_FILE {CONFIG_FILE} #
|
---|
| 583 | # #
|
---|
| 584 | # Purpose: chk_stat checks the status of a script by checking for both a #
|
---|
| 585 | # binary file to execute, and if set, a config file that may be #
|
---|
| 586 | # needed for the program to run successfully. #
|
---|
| 587 | # #
|
---|
| 588 | # Inputs: accepts first argument of an executable file, and optionally a #
|
---|
| 589 | # second arugument of a configuration file. If BIN_FILE and #
|
---|
| 590 | # CONFIG_FILE are set in the calling environment, either or both #
|
---|
| 591 | # arguments may be omitted. #
|
---|
| 592 | # #
|
---|
| 593 | # Return values: #
|
---|
| 594 | # 0 - The executable, and optionally the configuration file exists #
|
---|
| 595 | # 2 - Invalid or excessive arguments #
|
---|
| 596 | # 5 - BIN_FILE does not exist #
|
---|
| 597 | # 6 - CONFIG_FILE (if set) does not exist #
|
---|
| 598 | ###############################################################################
|
---|
| 599 | chk_stat()
|
---|
| 600 | {
|
---|
| 601 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 602 | BIN_FILE="${1}"
|
---|
| 603 | if [ -z "${2}" ]; then
|
---|
| 604 | CONFIG_FILE=""
|
---|
| 605 | else
|
---|
| 606 | CONFIG_FILE="${2}"
|
---|
| 607 | fi
|
---|
| 608 | elif [ -z "${BIN_FILE}" ]; then
|
---|
| 609 | echo "Usage: 'chk_stat BIN_FILE CONFIG_FILE'"
|
---|
| 610 | exit 1 # Generic Error
|
---|
| 611 | fi
|
---|
| 612 |
|
---|
| 613 | if [ ! -e "${BIN_FILE}" ]; then
|
---|
| 614 | log_failure_msg "${BIN_FILE} not installed" &&
|
---|
| 615 | exit 5
|
---|
| 616 | fi
|
---|
| 617 |
|
---|
| 618 | if [ ! -z "${CONFIG_FILE}" ]; then
|
---|
| 619 | if [ ! -e "${CONFIG_FILE}" ]; then
|
---|
| 620 | log_failure_msg "${CONFIG_FILE} does not exist" &&
|
---|
| 621 | exit 6
|
---|
| 622 | fi
|
---|
| 623 | fi
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | ###############################################################################
|
---|
| 627 | # loadproc() #
|
---|
| 628 | # Usage: loadproc {arguments} #
|
---|
| 629 | # #
|
---|
| 630 | # Purpose: loadproc is just a wrapper to start_daemon for simple scripts, #
|
---|
| 631 | # which will require no aruguments if $BIN_FILE is set. #
|
---|
| 632 | # #
|
---|
| 633 | # Inputs: Any optional arguments passed to loadproc will be passed on to the #
|
---|
| 634 | # executable defined by $BIN_FILE. #
|
---|
| 635 | # #
|
---|
| 636 | # Return values: (none) #
|
---|
| 637 | ###############################################################################
|
---|
| 638 | loadproc()
|
---|
| 639 | {
|
---|
| 640 | start_daemon "${BIN_FILE}" "${@}"
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | ###############################################################################
|
---|
| 644 | # endproc() #
|
---|
| 645 | # Usage: endproc {arguments} #
|
---|
| 646 | # #
|
---|
| 647 | # Purpose: endproc is just a wrapper to killproc for simple scripts, which #
|
---|
| 648 | # which will require no aruguments if $BIN_FILE is set. #
|
---|
| 649 | # #
|
---|
| 650 | # Inputs: Any optional arguments passed to endproc will be passed on to the #
|
---|
| 651 | # executable defined by $BIN_FILE. #
|
---|
| 652 | # #
|
---|
| 653 | # Return values: (none) #
|
---|
| 654 | ###############################################################################
|
---|
| 655 | endproc()
|
---|
| 656 | {
|
---|
| 657 | killproc "${BIN_FILE}" "${@}"
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | ###############################################################################
|
---|
| 661 | # statusproc() #
|
---|
| 662 | # Usage: statusproc $BIN_FILE $MESSAGE #
|
---|
| 663 | # #
|
---|
| 664 | # Purpose: stautsproc is just a wrapper to pidofproc for simple scripts, #
|
---|
| 665 | # which will require no aruguments if $BIN_FILE and MESSAGE are set. #
|
---|
| 666 | # #
|
---|
| 667 | # Inputs: accepts first argument of an executable file, and a second message #
|
---|
| 668 | # arugument "MESSAGE" to be displayed. If BIN_FILE and MESSAGE are #
|
---|
| 669 | # set in the calling environment, both arguments may be omitted. #
|
---|
| 670 | # #
|
---|
| 671 | # Return values: exit values of pidofproc #
|
---|
| 672 | ###############################################################################
|
---|
| 673 | statusproc()
|
---|
| 674 | {
|
---|
| 675 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 676 | BIN_FILE="${1}"
|
---|
| 677 | MESSAGE="${2}"
|
---|
| 678 | elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
|
---|
| 679 | echo "Usage: 'statusproc BIN_FILE MESSAGE'"
|
---|
| 680 | exit 1 # Generic Error
|
---|
| 681 | fi
|
---|
| 682 |
|
---|
| 683 | pidlist=`pidofproc "${BIN_FILE}"`
|
---|
| 684 | STATUS=$?
|
---|
| 685 | echo "Checking ${MESSAGE} status:"
|
---|
| 686 | if [ "${STATUS}" -eq "0" ]; then
|
---|
| 687 | log_success_msg "Running with PID(s) ${pidlist}"
|
---|
| 688 | else
|
---|
| 689 | log_warning_msg "Not running!"
|
---|
| 690 | fi
|
---|
| 691 |
|
---|
| 692 | return "${STATUS}"
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | ###############################################################################
|
---|
| 696 | # reloadproc() #
|
---|
| 697 | # Usage: reloadproc {--force} $BIN_FILE $MESSAGE #
|
---|
| 698 | # #
|
---|
| 699 | # Purpose: reloadproc sends a HUP signal to the running program (relaod #
|
---|
| 700 | # configuration). It optionally, using the -force switch, checks the #
|
---|
| 701 | # status of a particular program and starts it if it is not already #
|
---|
| 702 | # running. #
|
---|
| 703 | # #
|
---|
| 704 | # Inputs: accepts one optional switch (must be the first argument), and #
|
---|
| 705 | # either two, or zero string arguments. If BIN_FILE and MESSAGE are #
|
---|
| 706 | # set in the calling envirnoment it will use those values, else it #
|
---|
| 707 | # requires the bin file as the first argument (following -force if #
|
---|
| 708 | # used), and the message as the second. If the --force argument is #
|
---|
| 709 | # given, it follows the LSB definition of 'force-reload' - the #
|
---|
| 710 | # program is started if not already running. #
|
---|
| 711 | # #
|
---|
| 712 | # Return values: 1 - generic error #
|
---|
| 713 | ###############################################################################
|
---|
| 714 | reloadproc()
|
---|
| 715 | {
|
---|
| 716 | local force="0"
|
---|
| 717 | if [ "${#}" -gt "0" -a "${1}" = "-force" ]; then
|
---|
| 718 | force="1"
|
---|
| 719 | shift 1
|
---|
| 720 | fi
|
---|
| 721 |
|
---|
| 722 | if [ "${#}" -gt "0" -a "${#}" -lt "3" ]; then
|
---|
| 723 | BIN_FILE="${1}"
|
---|
| 724 | MESSAGE="${2}"
|
---|
| 725 | elif [ -z "${BIN_FILE}" -o -z "${MESSAGE}" ]; then
|
---|
| 726 | echo "Usage: 'reloadproc BIN_FILE MESSAGE'"
|
---|
| 727 | exit 1 # Generic Error
|
---|
| 728 | fi
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | ###############################################################################
|
---|
| 732 | # evaluate_retval() #
|
---|
| 733 | # Usage: evaluate_retval \ #
|
---|
| 734 | # [standard|start|stop|reload|force-reload|restart|try-restart] #
|
---|
| 735 | # #
|
---|
| 736 | # Purpose: determines the sucess or failure of a previous command based on #
|
---|
| 737 | # LSB exit values, and prints messages to the screen using the #
|
---|
| 738 | # log_*_msg() functions. #
|
---|
| 739 | # #
|
---|
| 740 | # Inputs: accepts one argument which determines the output of the message #
|
---|
| 741 | # displayed on the screen based on the LSB input values for init #
|
---|
| 742 | # scripts. The 'standard' argument makes no changes to the value of #
|
---|
| 743 | # $message or $MESSAGE, but only one can be set in the calling #
|
---|
| 744 | # environment. #
|
---|
| 745 | # #
|
---|
| 746 | # Return values: (none) #
|
---|
| 747 | ###############################################################################
|
---|
| 748 | evaluate_retval()
|
---|
| 749 | {
|
---|
| 750 | local error_value="${?}"
|
---|
| 751 |
|
---|
| 752 | # Handle LSB defined return values
|
---|
| 753 | case "${1}" in
|
---|
| 754 |
|
---|
| 755 | start)
|
---|
| 756 | case "${error_value}" in
|
---|
| 757 | 0)
|
---|
| 758 | log_success_msg "Starting ${MESSAGE} "
|
---|
| 759 | return "${error_value}"
|
---|
| 760 | ;;
|
---|
| 761 | 2)
|
---|
| 762 | log_failure_msg "Starting ${MESSAGE} Error: Invalid argument!"
|
---|
| 763 | return "${error_value}"
|
---|
| 764 | ;;
|
---|
| 765 | 5)
|
---|
| 766 | log_failure_msg "Starting ${MESSAGE} Error: Not available!"
|
---|
| 767 | return "${error_value}"
|
---|
| 768 | ;;
|
---|
| 769 | *)
|
---|
| 770 | log_failure_msg "Starting ${MESSAGE} Error: General failure!"
|
---|
| 771 | return "${error_value}"
|
---|
| 772 | ;;
|
---|
| 773 | esac
|
---|
| 774 | ;;
|
---|
| 775 |
|
---|
| 776 | stop)
|
---|
| 777 | case "${error_value}" in
|
---|
| 778 | 0)
|
---|
| 779 | log_success_msg "Stopping ${MESSAGE} "
|
---|
| 780 | return "${error_value}"
|
---|
| 781 | ;;
|
---|
| 782 | 2)
|
---|
| 783 | log_failure_msg "Stopping ${MESSAGE} Error: Invalid argument!"
|
---|
| 784 | return "${error_value}"
|
---|
| 785 | ;;
|
---|
| 786 | 5)
|
---|
| 787 | log_failure_msg "Stopping ${MESSAGE} Error: Not available!"
|
---|
| 788 | return "${error_value}"
|
---|
| 789 | ;;
|
---|
| 790 | 7)
|
---|
| 791 | log_warning_msg "Stopping ${MESSAGE} Warning: Not running!"
|
---|
| 792 | return "${error_value}"
|
---|
| 793 | ;;
|
---|
| 794 | *)
|
---|
| 795 | log_failure_msg "Stopping ${MESSAGE} Error: General failure!"
|
---|
| 796 | return "${error_value}"
|
---|
| 797 | ;;
|
---|
| 798 | esac
|
---|
| 799 | ;;
|
---|
| 800 |
|
---|
| 801 | force-reload)
|
---|
| 802 | message="Forcefully reloading "
|
---|
| 803 | ;;
|
---|
| 804 |
|
---|
| 805 | reload)
|
---|
| 806 | message="Reloading "
|
---|
| 807 | ;;
|
---|
| 808 |
|
---|
| 809 | restart)
|
---|
| 810 | message="Restarting "
|
---|
| 811 | ;;
|
---|
| 812 |
|
---|
| 813 | try-restart)
|
---|
| 814 | message="Trying restart "
|
---|
| 815 | ;;
|
---|
| 816 |
|
---|
| 817 | standard)
|
---|
| 818 | # $message or $MESSAGE must be set, but not both in order
|
---|
| 819 | # to use the 'standard' target.
|
---|
| 820 | ;;
|
---|
| 821 | esac
|
---|
| 822 |
|
---|
| 823 | # Print messages for the generic force-reload, reload, restart,
|
---|
| 824 | # and try-restart targets
|
---|
| 825 | if [ "${error_value}" -eq "0" ]
|
---|
| 826 | then
|
---|
| 827 | log_success_msg "${message}${MESSAGE} "
|
---|
| 828 | return "${error_value}"
|
---|
| 829 | else
|
---|
| 830 | log_failure_msg "${message}${MESSAGE} "
|
---|
| 831 | return "${error_value}"
|
---|
| 832 | fi
|
---|
| 833 | }
|
---|
| 834 |
|
---|
[1c48007] | 835 | # End /lib/lsb/init-functions
|
---|