init-functions 28 KB

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