init-functions 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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/var/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. # succesful 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. else
  300. # just check one last time and if still alive, fail
  301. sleep 1
  302. kill -0 "${pid}" 2> /dev/null && return 1
  303. fi
  304. fi
  305. done
  306. fi
  307. # Check for and remove stale PID files.
  308. if [ -z "${pidfile}" ]; then
  309. # Find the basename of $program
  310. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  311. progname=`echo "${program}" | sed "s@${prefix}@@"`
  312. if [ -e "/var/run/${progname}.pid" ]; then
  313. rm -f "/var/run/${progname}.pid" 2> /dev/null
  314. fi
  315. else
  316. if [ -e "${pidfile}" ]; then rm -f "${pidfile}" 2> /dev/null; fi
  317. fi
  318. # For signals that do not expect a program to exit, simply
  319. # let kill do it's job, and evaluate kills return for value
  320. else # check_sig_type - signal is not used to terminate program
  321. for pid in ${pidlist}; do
  322. kill "${signal}" "${pid}"
  323. if [ "${?}" -ne "0" ]; then return 1; fi
  324. done
  325. fi
  326. }
  327. ################################################################################
  328. # pidofproc() #
  329. # Usage: pidofproc [-p pidfile] pathname #
  330. # #
  331. # Purpose: This function returns one or more pid(s) for a particular daemon #
  332. # #
  333. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  334. # pathname, path to the specified program #
  335. # #
  336. # Return values (as defined by LSB status codes): #
  337. # 0 - Success (PIDs to stdout) #
  338. # 1 - Program is dead, PID file still exists (remaining PIDs output) #
  339. # 3 - Program is not running (no output) #
  340. ################################################################################
  341. pidofproc()
  342. {
  343. local pidfile
  344. local program
  345. local prefix
  346. local progname
  347. local pidlist
  348. local lpids
  349. local exitstatus="0"
  350. # Process arguments
  351. while true; do
  352. case "${1}" in
  353. -p)
  354. pidfile="${2}"
  355. shift 2
  356. ;;
  357. *)
  358. program="${1}"
  359. if [ -n "${2}" ]; then
  360. # Too many arguments
  361. # Since this is status, return unknown
  362. return 4
  363. else
  364. break
  365. fi
  366. ;;
  367. esac
  368. done
  369. # If a PID file is not specified, try and find one.
  370. if [ -z "${pidfile}" ]; then
  371. # Get the program's basename
  372. prefix=`echo "${program}" | sed 's/[^/]*$//'`
  373. if [ -z "${prefix}" ]; then
  374. progname="${program}"
  375. else
  376. progname=`echo "${program}" | sed "s@${prefix}@@"`
  377. fi
  378. # If a PID file exists with that name, assume that is it.
  379. if [ -e "/var/run/${progname}.pid" ]; then
  380. pidfile="/var/run/${progname}.pid"
  381. fi
  382. fi
  383. # If a PID file is set and exists, use it.
  384. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  385. # Use the value in the first line of the pidfile
  386. pidlist=`/bin/head -n1 "${pidfile}"`
  387. # This can optionally be written as 'sed 1q' to repalce 'head -n1'
  388. # should LFS move /bin/head to /usr/bin/head
  389. else
  390. # Use pidof
  391. pidlist=`pidof "${program}"`
  392. fi
  393. # Figure out if all listed PIDs are running.
  394. for pid in ${pidlist}; do
  395. kill -0 ${pid} 2> /dev/null
  396. if [ "${?}" -eq "0" ]; then
  397. lpids="${lpids}${pid} "
  398. else
  399. exitstatus="1"
  400. fi
  401. done
  402. if [ -z "${lpids}" -a ! -f "${pidfile}" ]; then
  403. return 3
  404. else
  405. echo "${lpids}"
  406. return "${exitstatus}"
  407. fi
  408. }
  409. ################################################################################
  410. # statusproc() #
  411. # Usage: statusproc [-p pidfile] pathname #
  412. # #
  413. # Purpose: This function prints the status of a particular daemon to stdout #
  414. # #
  415. # Inputs: -p pidfile, use the specified pidfile instead of pidof #
  416. # pathname, path to the specified program #
  417. # #
  418. # Return values: #
  419. # 0 - Status printed #
  420. # 1 - Input error. The daemon to check was not specified. #
  421. ################################################################################
  422. statusproc()
  423. {
  424. local pidfile
  425. local pidlist
  426. if [ "${#}" = "0" ]; then
  427. echo "Usage: statusproc [-p pidfle] {program}"
  428. exit 1
  429. fi
  430. # Process arguments
  431. while true; do
  432. case "${1}" in
  433. -p)
  434. pidfile="${2}"
  435. shift 2
  436. ;;
  437. *)
  438. if [ -n "${2}" ]; then
  439. echo "Too many arguments"
  440. return 1
  441. else
  442. break
  443. fi
  444. ;;
  445. esac
  446. done
  447. if [ -n "${pidfile}" ]; then
  448. pidlist=`pidofproc -p "${pidfile}" $@`
  449. else
  450. pidlist=`pidofproc $@`
  451. fi
  452. # Trim trailing blanks
  453. pidlist=`echo "${pidlist}" | sed -r 's/ +$//'`
  454. base="${1##*/}"
  455. if [ -n "${pidlist}" ]; then
  456. echo -e "${INFO}${base} is running with Process" \
  457. "ID(s) ${pidlist}.${NORMAL}"
  458. else
  459. if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
  460. echo -e "${WARNING}${1} is not running but" \
  461. "/var/run/${base}.pid exists.${NORMAL}"
  462. else
  463. if [ -n "${pidfile}" -a -e "${pidfile}" ]; then
  464. echo -e "${WARNING}${1} is not running" \
  465. "but ${pidfile} exists.${NORMAL}"
  466. else
  467. echo -e "${INFO}${1} is not running.${NORMAL}"
  468. fi
  469. fi
  470. fi
  471. }
  472. ################################################################################
  473. # timespec() #
  474. # #
  475. # Purpose: An internal utility function to format a timestamp #
  476. # a boot log file. Sets the STAMP variable. #
  477. # #
  478. # Return value: Not used #
  479. ################################################################################
  480. timespec()
  481. {
  482. STAMP="$(echo `date +"%b %d %T %:z"` `hostname`) "
  483. return 0
  484. }
  485. ################################################################################
  486. # log_success_msg() #
  487. # Usage: log_success_msg ["message"] #
  488. # #
  489. # Purpose: Print a successful status message to the screen and #
  490. # a boot log file. #
  491. # #
  492. # Inputs: $@ - Message #
  493. # #
  494. # Return values: Not used #
  495. ################################################################################
  496. log_success_msg()
  497. {
  498. echo -n -e "${BMPREFIX}${@}"
  499. echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  500. # Strip non-printable characters from log file
  501. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  502. timespec
  503. echo -e "${STAMP} ${logmessage} OK" >> ${BOOTLOG}
  504. return 0
  505. }
  506. log_success_msg2()
  507. {
  508. echo -n -e "${BMPREFIX}${@}"
  509. echo -e "${CURS_ZERO}${SUCCESS_PREFIX}${SET_COL}${SUCCESS_SUFFIX}"
  510. echo " OK" >> ${BOOTLOG}
  511. return 0
  512. }
  513. ################################################################################
  514. # log_failure_msg() #
  515. # Usage: log_failure_msg ["message"] #
  516. # #
  517. # Purpose: Print a failure status message to the screen and #
  518. # a boot log file. #
  519. # #
  520. # Inputs: $@ - Message #
  521. # #
  522. # Return values: Not used #
  523. ################################################################################
  524. log_failure_msg()
  525. {
  526. echo -n -e "${BMPREFIX}${@}"
  527. echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  528. # Strip non-printable characters from log file
  529. timespec
  530. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  531. echo -e "${STAMP} ${logmessage} FAIL" >> ${BOOTLOG}
  532. return 0
  533. }
  534. log_failure_msg2()
  535. {
  536. echo -n -e "${BMPREFIX}${@}"
  537. echo -e "${CURS_ZERO}${FAILURE_PREFIX}${SET_COL}${FAILURE_SUFFIX}"
  538. echo "FAIL" >> ${BOOTLOG}
  539. return 0
  540. }
  541. ################################################################################
  542. # log_warning_msg() #
  543. # Usage: log_warning_msg ["message"] #
  544. # #
  545. # Purpose: Print a warning status message to the screen and #
  546. # a boot log file. #
  547. # #
  548. # Return values: Not used #
  549. ################################################################################
  550. log_warning_msg()
  551. {
  552. echo -n -e "${BMPREFIX}${@}"
  553. echo -e "${CURS_ZERO}${WARNING_PREFIX}${SET_COL}${WARNING_SUFFIX}"
  554. # Strip non-printable characters from log file
  555. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  556. timespec
  557. echo -e "${STAMP} ${logmessage} WARN" >> ${BOOTLOG}
  558. return 0
  559. }
  560. ################################################################################
  561. # log_info_msg() #
  562. # Usage: log_info_msg message #
  563. # #
  564. # Purpose: Print an information message to the screen and #
  565. # a boot log file. Does not print a trailing newline character. #
  566. # #
  567. # Return values: Not used #
  568. ################################################################################
  569. log_info_msg()
  570. {
  571. echo -n -e "${BMPREFIX}${@}"
  572. # Strip non-printable characters from log file
  573. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  574. timespec
  575. echo -n -e "${STAMP} ${logmessage}" >> ${BOOTLOG}
  576. return 0
  577. }
  578. log_info_msg2()
  579. {
  580. echo -n -e "${@}"
  581. # Strip non-printable characters from log file
  582. local logmessage=`echo "${@}" | sed 's/\\\033[^a-zA-Z]*.//g'`
  583. echo -n -e "${logmessage}" >> ${BOOTLOG}
  584. return 0
  585. }
  586. ################################################################################
  587. # evaluate_retval() #
  588. # Usage: Evaluate a return value and print success or failyure as appropriate #
  589. # #
  590. # Purpose: Convenience function to terminate an info message #
  591. # #
  592. # Return values: Not used #
  593. ################################################################################
  594. evaluate_retval()
  595. {
  596. local error_value="${?}"
  597. if [ ${error_value} = 0 ]; then
  598. log_success_msg2
  599. else
  600. log_failure_msg2
  601. fi
  602. }
  603. ################################################################################
  604. # check_signal() #
  605. # Usage: check_signal [ -{signal} | {signal} ] #
  606. # #
  607. # Purpose: Check for a valid signal. This is not defined by any LSB draft, #
  608. # however, it is required to check the signals to determine if the #
  609. # signals chosen are invalid arguments to the other functions. #
  610. # #
  611. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  612. # #
  613. # Return values: #
  614. # 0 - Success (signal is valid #
  615. # 1 - Signal is not valid #
  616. ################################################################################
  617. check_signal()
  618. {
  619. local valsig
  620. # Add error handling for invalid signals
  621. valsig="-ALRM -HUP -INT -KILL -PIPE -POLL -PROF -TERM -USR1 -USR2"
  622. valsig="${valsig} -VTALRM -STKFLT -PWR -WINCH -CHLD -URG -TSTP -TTIN"
  623. valsig="${valsig} -TTOU -STOP -CONT -ABRT -FPE -ILL -QUIT -SEGV -TRAP"
  624. valsig="${valsig} -SYS -EMT -BUS -XCPU -XFSZ -0 -1 -2 -3 -4 -5 -6 -8 -9"
  625. valsig="${valsig} -11 -13 -14 -15"
  626. echo "${valsig}" | grep -- " ${1} " > /dev/null
  627. if [ "${?}" -eq "0" ]; then
  628. return 0
  629. else
  630. return 1
  631. fi
  632. }
  633. ################################################################################
  634. # check_sig_type() #
  635. # Usage: check_signal [ -{signal} | {signal} ] #
  636. # #
  637. # Purpose: Check if signal is a program termination signal or a control signal #
  638. # This is not defined by any LSB draft, however, it is required to #
  639. # check the signals to determine if they are intended to end a #
  640. # program or simply to control it. #
  641. # #
  642. # Inputs: Accepts a single string value in the form or -{signal} or {signal} #
  643. # #
  644. # Return values: #
  645. # 0 - Signal is used for program termination #
  646. # 1 - Signal is used for program control #
  647. ################################################################################
  648. check_sig_type()
  649. {
  650. local valsig
  651. # The list of termination signals (limited to generally used items)
  652. valsig="-ALRM -INT -KILL -TERM -PWR -STOP -ABRT -QUIT -2 -3 -6 -9 -14 -15"
  653. echo "${valsig}" | grep -- " ${1} " > /dev/null
  654. if [ "${?}" -eq "0" ]; then
  655. return 0
  656. else
  657. return 1
  658. fi
  659. }
  660. ################################################################################
  661. # wait_for_user() #
  662. # #
  663. # Purpose: Wait for the user to respond if not a headless system #
  664. # #
  665. ################################################################################
  666. wait_for_user()
  667. {
  668. # Wait for the user by default
  669. [ "${HEADLESS=0}" = "0" ] && read ENTER
  670. return 0
  671. }
  672. ################################################################################
  673. # is_true() #
  674. # #
  675. # Purpose: Utility to test if a variable is true | yes | 1 #
  676. # #
  677. ################################################################################
  678. is_true()
  679. {
  680. [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "y" ] ||
  681. [ "$1" = "t" ]
  682. }
  683. # End /lib/lsb/init-functions