init-functions 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # Begin /lib/lsb/init-funtions
  5. #
  6. # Description : Run Level Control Functions
  7. #
  8. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  9. # : DJ Lucas - dj@linuxfromscratch.org
  10. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  11. #
  12. # Version : LFS 7.0
  13. #
  14. # Notes : With code based on Matthias Benkmann's simpleinit-msb
  15. # http://winterdrache.de/linux/newboot/index.html
  16. #
  17. # The file should be located in /lib/lsb
  18. #
  19. ########################################################################
  20. ## Environmental setup
  21. # Setup default values for environment
  22. umask 022
  23. export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
  24. ## Screen Dimensions
  25. # Find current screen size
  26. if [ -z "${COLUMNS}" ]; then
  27. COLUMNS=$(stty size)
  28. COLUMNS=${COLUMNS##* }
  29. fi
  30. # When using remote connections, such as a serial port, stty size returns 0
  31. if [ "${COLUMNS}" = "0" ]; then
  32. COLUMNS=80
  33. fi
  34. ## Measurements for positioning result messages
  35. COL=$((${COLUMNS} - 8))
  36. WCOL=$((${COL} - 2))
  37. ## Set Cursor Position Commands, used via echo
  38. SET_COL="\\033[${COL}G" # at the $COL char
  39. SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
  40. CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
  41. CURS_ZERO="\\033[0G"
  42. ## Set color commands, used via echo
  43. # Please consult `man console_codes for more information
  44. # under the "ECMA-48 Set Graphics Rendition" section
  45. #
  46. # Warning: when switching from a 8bit to a 9bit font,
  47. # the linux console will reinterpret the bold (1;) to
  48. # the top 256 glyphs of the 9bit font. This does
  49. # not affect framebuffer consoles
  50. NORMAL="\\033[0;39m" # Standard console grey
  51. SUCCESS="\\033[1;32m" # Success is green
  52. WARNING="\\033[1;33m" # Warnings are yellow
  53. FAILURE="\\033[1;31m" # Failures are red
  54. INFO="\\033[1;36m" # Information is light cyan
  55. BRACKET="\\033[1;34m" # Brackets are blue
  56. # Use a colored prefix
  57. BMPREFIX=" "
  58. SUCCESS_PREFIX="${SUCCESS} * ${NORMAL}"
  59. FAILURE_PREFIX="${FAILURE}*****${NORMAL}"
  60. WARNING_PREFIX="${WARNING} *** ${NORMAL}"
  61. SUCCESS_SUFFIX="${BRACKET}[${SUCCESS} OK ${BRACKET}]${NORMAL}"
  62. FAILURE_SUFFIX="${BRACKET}[${FAILURE} FAIL ${BRACKET}]${NORMAL}"
  63. WARNING_SUFFIX="${BRACKET}[${WARNING} WARN ${BRACKET}]${NORMAL}"
  64. BOOTLOG=/run/bootlog
  65. KILLDELAY=3
  66. # Set any user specified environment variables e.g. HEADLESS
  67. [ -r /etc/sysconfig/rc.site ] && . /etc/sysconfig/rc.site
  68. ################################################################################
  69. # start_daemon() #
  70. # Usage: start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...] #
  71. # #
  72. # Purpose: This runs the specified program as a daemon #
  73. # #
  74. # Inputs: -f: (force) run the program even if it is already running. #
  75. # -n nicelevel: specify a nice level. See 'man nice(1)'. #
  76. # -p pidfile: use the specified file to determine PIDs. #
  77. # pathname: the complete path to the specified program #
  78. # args: additional arguments passed to the program (pathname) #
  79. # #
  80. # Return values (as defined by LSB exit codes): #
  81. # 0 - program is running or service is OK #
  82. # 1 - generic or unspecified error #
  83. # 2 - invalid or excessive argument(s) #
  84. # 5 - program is not installed #
  85. ################################################################################
  86. start_daemon()
  87. {
  88. local force=""
  89. local nice="0"
  90. local pidfile=""
  91. local pidlist=""
  92. local retval=""
  93. # Process arguments
  94. while true
  95. do
  96. case "${1}" in
  97. -f)
  98. force="1"
  99. shift 1
  100. ;;
  101. -n)
  102. nice="${2}"
  103. shift 2
  104. ;;
  105. -p)
  106. pidfile="${2}"
  107. shift 2
  108. ;;
  109. -*)
  110. return 2
  111. ;;
  112. *)
  113. program="${1}"
  114. break
  115. ;;
  116. esac
  117. done
  118. # Check for a valid program
  119. if [ ! -e "${program}" ]; then return 5; fi
  120. # Execute
  121. if [ -z "${force}" ]; then
  122. if [ -z "${pidfile}" ]; then
  123. # Determine the pid by discovery
  124. pidlist=`pidofproc "${1}"`
  125. retval="${?}"
  126. else
  127. # The PID file contains the needed PIDs
  128. # Note that by LSB requirement, the path must be given to pidofproc,
  129. # however, it is not used by the current implementation or standard.
  130. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  131. retval="${?}"
  132. fi
  133. # Return a value ONLY
  134. # It is the init script's (or distribution's functions) responsibilty
  135. # to log messages!
  136. case "${retval}" in
  137. 0)
  138. # Program is already running correctly, this is a
  139. # successful start.
  140. return 0
  141. ;;
  142. 1)
  143. # Program is not running, but an invalid pid file exists
  144. # remove the pid file and continue
  145. rm -f "${pidfile}"
  146. ;;
  147. 3)
  148. # Program is not running and no pidfile exists
  149. # do nothing here, let start_deamon continue.
  150. ;;
  151. *)
  152. # Others as returned by status values shall not be interpreted
  153. # and returned as an unspecified error.
  154. return 1
  155. ;;
  156. esac
  157. fi
  158. # Do the start!
  159. nice -n "${nice}" "${@}"
  160. }
  161. ################################################################################
  162. # killproc() #
  163. # Usage: killproc [-p pidfile] pathname [signal] #
  164. # #
  165. # Purpose: Send control signals to running processes #
  166. # #
  167. # Inputs: -p pidfile, uses the specified pidfile #
  168. # pathname, pathname to the specified program #
  169. # signal, send this signal to pathname #
  170. # #
  171. # Return values (as defined by LSB exit codes): #
  172. # 0 - program (pathname) has stopped/is already stopped or a #
  173. # running program has been sent specified signal and stopped #
  174. # successfully #
  175. # 1 - generic or unspecified error #
  176. # 2 - invalid or excessive argument(s) #
  177. # 5 - program is not installed #
  178. # 7 - program is not running and a signal was supplied #
  179. ################################################################################
  180. killproc()
  181. {
  182. local pidfile
  183. local program
  184. local prefix
  185. local progname
  186. local signal="-TERM"
  187. local fallback="-KILL"
  188. local nosig
  189. local pidlist
  190. local retval
  191. local pid
  192. local delay="30"
  193. local piddead
  194. local dtime
  195. # Process arguments
  196. while true; do
  197. case "${1}" in
  198. -p)
  199. pidfile="${2}"
  200. shift 2
  201. ;;
  202. *)
  203. program="${1}"
  204. if [ -n "${2}" ]; then
  205. signal="${2}"
  206. fallback=""
  207. else
  208. nosig=1
  209. fi
  210. # Error on additional arguments
  211. if [ -n "${3}" ]; then
  212. return 2
  213. else
  214. break
  215. fi
  216. ;;
  217. esac
  218. done
  219. # Check for a valid program
  220. if [ ! -e "${program}" ]; then return 5; fi
  221. # Check for a valid signal
  222. check_signal "${signal}"
  223. if [ "${?}" -ne "0" ]; then return 2; fi
  224. # Get a list of pids
  225. if [ -z "${pidfile}" ]; then
  226. # determine the pid by discovery
  227. pidlist=`pidofproc "${1}"`
  228. retval="${?}"
  229. else
  230. # The PID file contains the needed PIDs
  231. # Note that by LSB requirement, the path must be given to pidofproc,
  232. # however, it is not used by the current implementation or standard.
  233. pidlist=`pidofproc -p "${pidfile}" "${1}"`
  234. retval="${?}"
  235. fi
  236. # Return a value ONLY
  237. # It is the init script's (or distribution's functions) responsibilty
  238. # to log messages!
  239. case "${retval}" in
  240. 0)
  241. # Program is running correctly
  242. # Do nothing here, let killproc continue.
  243. ;;
  244. 1)
  245. # Program is not running, but an invalid pid file exists
  246. # Remove the pid file.
  247. rm -f "${pidfile}"
  248. # This is only a success if no signal was passed.
  249. if [ -n "${nosig}" ]; then
  250. return 0
  251. else
  252. return 7
  253. fi
  254. ;;
  255. 3)
  256. # Program is not running and no pidfile exists
  257. # This is only a success if no signal was passed.
  258. if [ -n "${nosig}" ]; then
  259. return 0
  260. else
  261. return 7
  262. fi
  263. ;;
  264. *)
  265. # Others as returned by status values shall not be interpreted
  266. # and returned as an unspecified error.
  267. return 1
  268. ;;
  269. esac
  270. # Perform different actions for exit signals and control signals
  271. check_sig_type "${signal}"
  272. if [ "${?}" -eq "0" ]; then # Signal is used to terminate the program
  273. # Account for empty pidlist (pid file still exists and no
  274. # signal was given)
  275. if [ "${pidlist}" != "" ]; then
  276. # Kill the list of pids
  277. for pid in ${pidlist}; do
  278. kill -0 "${pid}" 2> /dev/null
  279. if [ "${?}" -ne "0" ]; then
  280. # Process is dead, continue to next and assume all is well
  281. continue
  282. else
  283. kill "${signal}" "${pid}" 2> /dev/null
  284. # Wait up to ${delay}/10 seconds to for "${pid}" to
  285. # terminate in 10ths of a second
  286. while [ "${delay}" -ne "0" ]; do
  287. kill -0 "${pid}" 2> /dev/null || piddead="1"
  288. if [ "${piddead}" = "1" ]; then break; fi
  289. sleep 0.1
  290. delay="$(( ${delay} - 1 ))"
  291. done
  292. # If a fallback is set, and program is still running, then
  293. # use the fallback
  294. if [ -n "${fallback}" -a "${piddead}" != "1" ]; then
  295. kill "${fallback}" "${pid}" 2> /dev/null
  296. sleep 1
  297. # Check again, and fail if still running
  298. kill -0 "${pid}" 2> /dev/null && return 1
  299. fi
  300. fi
  301. done
  302. fi
  303. # Check for and remove stale PID files.
  304. if [ -z "${pidfile}" ]; then
  305. # Find the basename of $program
  306. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  307. progname=`echo "${program}" | sed "s@${prefix}@@"`
  308. if [ -e "/var/run/${progname}.pid" ]; then
  309. rm -f "/var/run/${progname}.pid" 2> /dev/null
  310. fi
  311. else
  312. if [ -e "${pidfile}" ]; then rm -f "${pidfile}" 2> /dev/null; fi
  313. fi
  314. # For signals that do not expect a program to exit, simply
  315. # let kill do its job, and evaluate kill's return for value
  316. else # check_sig_type - signal is not used to terminate program
  317. for pid in ${pidlist}; do
  318. kill "${signal}" "${pid}"
  319. if [ "${?}" -ne "0" ]; then return 1; fi
  320. done
  321. fi
  322. }
  323. ################################################################################
  324. # pidofproc() #
  325. # Usage: pidofproc [-p pidfile] pathname #
  326. # #
  327. # Purpose: This function returns one or more pid(s) for a particular daemon #
  328. # #
  329. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  330. # pathname, path to the specified program #
  331. # #
  332. # Return values (as defined by LSB status codes): #
  333. # 0 - Success (PIDs to stdout) #
  334. # 1 - Program is dead, PID file still exists (remaining PIDs output) #
  335. # 3 - Program is not running (no output) #
  336. ################################################################################
  337. pidofproc()
  338. {
  339. local pidfile
  340. local program
  341. local prefix
  342. local progname
  343. local pidlist
  344. local lpids
  345. local exitstatus="0"
  346. # Process arguments
  347. while true; do
  348. case "${1}" in
  349. -p)
  350. pidfile="${2}"
  351. shift 2
  352. ;;
  353. *)
  354. program="${1}"
  355. if [ -n "${2}" ]; then
  356. # Too many arguments
  357. # Since this is status, return unknown
  358. return 4
  359. else
  360. break
  361. fi
  362. ;;
  363. esac
  364. done
  365. # If a PID file is not specified, try and find one.
  366. if [ -z "${pidfile}" ]; then
  367. # Get the program's basename
  368. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  369. if [ -z "${prefix}" ]; then
  370. progname="${program}"
  371. else
  372. progname=`echo "${program}" | sed "s@${prefix}@@"`
  373. fi
  374. # If a PID file exists with that name, assume that is it.
  375. if [ -e "/var/run/${progname}.pid" ]; then
  376. pidfile="/var/run/${progname}.pid"
  377. fi
  378. fi
  379. # If a PID file is set and exists, use it.
  380. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  381. # Use the value in the first line of the pidfile
  382. pidlist=`/bin/head -n1 "${pidfile}"`
  383. # This can optionally be written as 'sed 1q' to repalce 'head -n1'
  384. # should LFS move /bin/head to /usr/bin/head
  385. else
  386. # Use pidof
  387. pidlist=`pidof "${program}"`
  388. fi
  389. # Figure out if all listed PIDs are running.
  390. for pid in ${pidlist}; do
  391. kill -0 ${pid} 2> /dev/null
  392. if [ "${?}" -eq "0" ]; then
  393. lpids="${lpids}${pid} "
  394. else
  395. exitstatus="1"
  396. fi
  397. done
  398. if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
  399. return 3
  400. else
  401. echo "${lpids}"
  402. return "${exitstatus}"
  403. fi
  404. }
  405. ################################################################################
  406. # statusproc() #
  407. # Usage: statusproc [-p pidfile] pathname #
  408. # #
  409. # Purpose: This function prints the status of a particular daemon to stdout #
  410. # #
  411. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  412. # pathname, path to the specified program #
  413. # #
  414. # Return values: #
  415. # 0 - Status printed #
  416. # 1 - Input error. The daemon to check was not specified. #
  417. ################################################################################
  418. statusproc()
  419. {
  420. local pidfile
  421. local pidlist
  422. if [ "${#}" = "0" ]; then
  423. echo "Usage: statusproc [-p pidfle] {program}"
  424. exit 1
  425. fi
  426. # Process arguments
  427. while true; do
  428. case "${1}" in
  429. -p)
  430. pidfile="${2}"
  431. shift 2
  432. ;;
  433. *)
  434. if [ -n "${2}" ]; then
  435. echo "Too many arguments"
  436. return 1
  437. else
  438. break
  439. fi
  440. ;;
  441. esac
  442. done
  443. if [ -n "${pidfile}" ]; then
  444. pidlist=`pidofproc -p "${pidfile}" $@`
  445. else
  446. pidlist=`pidofproc $@`
  447. fi
  448. # Trim trailing blanks
  449. pidlist=`echo "${pidlist}" | sed -r 's/ +$//'`
  450. base="${1##*/}"
  451. if [ -n "${pidlist}" ]; then
  452. /bin/echo -e "${INFO}${base} is running with Process" \
  453. "ID(s) ${pidlist}.${NORMAL}"
  454. else
  455. if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
  456. /bin/echo -e "${WARNING}${1} is not running but" \
  457. "/var/run/${base}.pid exists.${NORMAL}"
  458. else
  459. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  460. /bin/echo -e "${WARNING}${1} is not running" \
  461. "but ${pidfile} exists.${NORMAL}"
  462. else
  463. /bin/echo -e "${INFO}${1} is not running.${NORMAL}"
  464. fi
  465. fi
  466. fi
  467. }
  468. ################################################################################
  469. # timespec() #
  470. # #
  471. # Purpose: An internal utility function to format a timestamp #
  472. # a boot log file. Sets the STAMP variable. #
  473. # #
  474. # Return value: Not used #
  475. ################################################################################
  476. timespec()
  477. {
  478. STAMP="$(echo `date +"%b %d %T %:z"` `hostname`) "
  479. return 0
  480. }
  481. ################################################################################
  482. # log_success_msg() #
  483. # Usage: log_success_msg ["message"] #
  484. # #
  485. # Purpose: Print a successful status message to the screen and #
  486. # a boot log file. #
  487. # #
  488. # Inputs: $@ - Message #
  489. # #
  490. # Return values: Not used #
  491. ################################################################################
  492. log_success_msg()
  493. {
  494. /bin/echo -n -e "${BMPREFIX}${@}"
  495. /bin/echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  496. # Strip non-printable characters from log file
  497. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  498. timespec
  499. /bin/echo -e "${STAMP} ${logmessage} OK" >> ${BOOTLOG}
  500. return 0
  501. }
  502. log_success_msg2()
  503. {
  504. /bin/echo -n -e "${BMPREFIX}${@}"
  505. /bin/echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  506. echo " OK" >> ${BOOTLOG}
  507. return 0
  508. }
  509. ################################################################################
  510. # log_failure_msg() #
  511. # Usage: log_failure_msg ["message"] #
  512. # #
  513. # Purpose: Print a failure status message to the screen and #
  514. # a boot log file. #
  515. # #
  516. # Inputs: $@ - Message #
  517. # #
  518. # Return values: Not used #
  519. ################################################################################
  520. log_failure_msg()
  521. {
  522. /bin/echo -n -e "${BMPREFIX}${@}"
  523. /bin/echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  524. # Strip non-printable characters from log file
  525. timespec
  526. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  527. /bin/echo -e "${STAMP} ${logmessage} FAIL" >> ${BOOTLOG}
  528. return 0
  529. }
  530. log_failure_msg2()
  531. {
  532. /bin/echo -n -e "${BMPREFIX}${@}"
  533. /bin/echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  534. echo "FAIL" >> ${BOOTLOG}
  535. return 0
  536. }
  537. ################################################################################
  538. # log_warning_msg() #
  539. # Usage: log_warning_msg ["message"] #
  540. # #
  541. # Purpose: Print a warning status message to the screen and #
  542. # a boot log file. #
  543. # #
  544. # Return values: Not used #
  545. ################################################################################
  546. log_warning_msg()
  547. {
  548. /bin/echo -n -e "${BMPREFIX}${@}"
  549. /bin/echo -e "${CURS_ZERO}${WARNING_PREFIX}${SET_COL}${WARNING_SUFFIX}"
  550. # Strip non-printable characters from log file
  551. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  552. timespec
  553. /bin/echo -e "${STAMP} ${logmessage} WARN" >> ${BOOTLOG}
  554. return 0
  555. }
  556. ################################################################################
  557. # log_info_msg() #
  558. # Usage: log_info_msg message #
  559. # #
  560. # Purpose: Print an information message to the screen and #
  561. # a boot log file. Does not print a trailing newline character. #
  562. # #
  563. # Return values: Not used #
  564. ################################################################################
  565. log_info_msg()
  566. {
  567. /bin/echo -n -e "${BMPREFIX}${@}"
  568. # Strip non-printable characters from log file
  569. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  570. timespec
  571. /bin/echo -n -e "${STAMP} ${logmessage}" >> ${BOOTLOG}
  572. return 0
  573. }
  574. log_info_msg2()
  575. {
  576. /bin/echo -n -e "${@}"
  577. # Strip non-printable characters from log file
  578. logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  579. /bin/echo -n -e "${logmessage}" >> ${BOOTLOG}
  580. return 0
  581. }
  582. ################################################################################
  583. # evaluate_retval() #
  584. # Usage: Evaluate a return value and print success or failyure as appropriate #
  585. # #
  586. # Purpose: Convenience function to terminate an info message #
  587. # #
  588. # Return values: Not used #
  589. ################################################################################
  590. evaluate_retval()
  591. {
  592. local error_value="${?}"
  593. if [ ${error_value} = 0 ]; then
  594. log_success_msg2
  595. else
  596. log_failure_msg2
  597. fi
  598. }
  599. ################################################################################
  600. # check_signal() #
  601. # Usage: check_signal [ -{signal} | {signal} ] #
  602. # #
  603. # Purpose: Check for a valid signal. This is not defined by any LSB draft, #
  604. # however, it is required to check the signals to determine if the #
  605. # signals chosen are invalid arguments to the other functions. #
  606. # #
  607. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  608. # #
  609. # Return values: #
  610. # 0 - Success (signal is valid #
  611. # 1 - Signal is not valid #
  612. ################################################################################
  613. check_signal()
  614. {
  615. local valsig
  616. # Add error handling for invalid signals
  617. valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
  618. valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
  619. valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
  620. valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
  621. valsig="${valsig} -11 -13 -14 -15"
  622. echo "${valsig}" | grep -- " ${1} " > /dev/null
  623. if [ "${?}" -eq "0" ]; then
  624. return 0
  625. else
  626. return 1
  627. fi
  628. }
  629. ################################################################################
  630. # check_sig_type() #
  631. # Usage: check_signal [ -{signal} | {signal} ] #
  632. # #
  633. # Purpose: Check if signal is a program termination signal or a control signal #
  634. # This is not defined by any LSB draft, however, it is required to #
  635. # check the signals to determine if they are intended to end a #
  636. # program or simply to control it. #
  637. # #
  638. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  639. # #
  640. # Return values: #
  641. # 0 - Signal is used for program termination #
  642. # 1 - Signal is used for program control #
  643. ################################################################################
  644. check_sig_type()
  645. {
  646. local valsig
  647. # The list of termination signals (limited to generally used items)
  648. valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
  649. echo "${valsig}" | grep -- " ${1} " > /dev/null
  650. if [ "${?}" -eq "0" ]; then
  651. return 0
  652. else
  653. return 1
  654. fi
  655. }
  656. ################################################################################
  657. # wait_for_user() #
  658. # #
  659. # Purpose: Wait for the user to respond if not a headless system #
  660. # #
  661. ################################################################################
  662. wait_for_user()
  663. {
  664. # Wait for the user by default
  665. [ "${HEADLESS=0}" = "0" ] && read ENTER
  666. return 0
  667. }
  668. ################################################################################
  669. # is_true() #
  670. # #
  671. # Purpose: Utility to test if a variable is true | yes | 1 #
  672. # #
  673. ################################################################################
  674. is_true()
  675. {
  676. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "y" ] ||
  677. [ "$1" = "t" ]
  678. }
  679. # End /lib/lsb/init-functions