Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.30 KB | None | 0 0
  1. > cat rc.status
  2. # /etc/rc.status
  3. # vim: syntax=sh
  4. # Definition of boot script return messages
  5. #
  6. # The bootscripts should use the variables rc_done and rc_failed to
  7. # report whether they failed or succeeded. See /etc/init.d/skeleton for
  8. # an example how the shell functions rc_status and rc_reset are used.
  9. #
  10. # These functions make use of the variables rc_done and rc_failed;
  11. # rc_done_up and rc_failed_up are the same as rc_done and rc_failed
  12. # but contain a terminal code to move up one line before the output
  13. # of the actual string. (This is particularly useful when the script
  14. # starts a daemon which produces user output with a newline character)
  15. #
  16. # The variable rc_reset is used by the master resource control script
  17. # /etc/init.d/rc to turn off all attributes and switch to the standard
  18. # character set.
  19. #
  20. # \033 ascii ESCape
  21. # \033[<NUM>G move to column <NUM> (linux console, xterm, not vt100)
  22. # \033[<NUM>C move <NUM> columns forward but only upto last column
  23. # \033[<NUM>D move <NUM> columns backward but only upto first column
  24. # \033[<NUM>A move <NUM> rows up
  25. # \033[<NUM>B move <NUM> rows down
  26. # \033[1m switch on bold
  27. # \033[31m switch on red
  28. # \033[32m switch on green
  29. # \033[33m switch on yellow
  30. # \033[m switch off color/bold
  31. # \017 exit alternate mode (xterm, vt100, linux console)
  32. # \033[10m exit alternate mode (linux console)
  33. # \015 carriage return (without newline)
  34. #
  35.  
  36. # Check if the service is used under systemd but not started with
  37. if test -z "$SYSTEMD_NO_WRAP" && /bin/mountpoint -q /sys/fs/cgroup/systemd > /dev/null 2>&1 ; then
  38. if test $PPID -ne 1 -a $# -eq 1 ; then
  39. _rc_base=
  40. case "$0" in
  41. /etc/init.d/boot.*)
  42. _rc_base=${0##*/boot.} ;;
  43. /etc/init.d/*|/etc/rc.d/*)
  44. _rc_base=${0##*/} ;;
  45. */rc*)
  46. if test -L "$0"; then
  47. _rc_base=`readlink "$0"`
  48. _rc_base=${_rc_base##*/}
  49. case "$_rc_base" in
  50. boot.*) _rc_base=${_rc_base#boot.}
  51. esac
  52. else
  53. _rc_base=${0##*/rc}
  54. fi
  55. ;;
  56. esac
  57. case "$1" in
  58. start|stop|reload|restart|try-restart|force-reload|status) echo "redirecting to systemctl" >/dev/stderr ;;
  59. *) unset _rc_base ;;
  60. esac
  61. if test -n "$_rc_base" -a -x /bin/systemctl ; then
  62. exec /bin/systemctl $1 "${_rc_base}.service"
  63. fi
  64. unset _rc_base
  65. fi
  66. if test -z "$REDIRECT" -a -x /sbin/showconsole ; then
  67. REDIRECT="$(/sbin/showconsole 2>/dev/null)"
  68. test -z "$CONSOLE" && CONSOLE=/dev/console
  69. export REDIRECT CONSOLE
  70. fi
  71. fi
  72.  
  73. # Do _not_ be fooled by non POSIX locale
  74. LC_ALL=POSIX
  75. export LC_ALL
  76.  
  77. # Seek for terminal size and, if needed, set default size
  78. rc_lc () {
  79. if test -n "$REDIRECT" ; then
  80. set -- $(stty size < "$REDIRECT" 2> /dev/null || echo 0 0)
  81. else
  82. set -- $(stty size 2> /dev/null || echo 0 0)
  83. fi
  84. LINES=$1
  85. COLUMNS=$2
  86. if test $LINES -eq 0 -o $COLUMNS -eq 0; then
  87. LINES=24
  88. COLUMNS=80
  89. TERM=dumb
  90. fi
  91. }
  92. trap 'rc_lc' SIGWINCH
  93. test -n "$COLUMNS" -a -n "$LINES" || rc_lc
  94. export LINES COLUMNS
  95.  
  96. # Make sure we have /sbin and /usr/sbin in PATH
  97. case ":$PATH:" in
  98. *:/sbin:*)
  99. ;;
  100. *)
  101. PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH
  102. export PATH
  103. ;;
  104. esac
  105.  
  106. if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb"; then
  107. esc=`echo -en "\033"`
  108. extd="${esc}[1m"
  109. warn="${esc}[1;31m"
  110. done="${esc}[1;32m"
  111. attn="${esc}[1;33m"
  112. norm=`echo -en "${esc}[m\017"`
  113. stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
  114.  
  115. rc_done="${stat}${done}done${norm}"
  116. rc_running="${stat}${done}running${norm}"
  117. rc_failed="${stat}${warn}failed${norm}"
  118. rc_missed="${stat}${warn}missing${norm}"
  119. rc_skipped="${stat}${attn}skipped${norm}"
  120. rc_dead="${stat}${warn}dead${norm}"
  121. rc_unused="${stat}${extd}unused${norm}"
  122. rc_unknown="${stat}${attn}unknown${norm}"
  123. rc_done_up="${esc}[1A${rc_done}"
  124. rc_failed_up="${esc}[1A${rc_failed}"
  125. rc_reset="${norm}${esc}[?25h"
  126. rc_save="${esc}7${esc}[?25l"
  127. rc_restore="${esc}8${esc}[?25h"
  128. rc_cuu () { test $1 -eq 0 && return; echo -en "\033[${1}A"; }
  129. rc_cud () { test $1 -eq 0 && return; echo -en "\033[${1}B"; }
  130. rc_timer_on () {
  131. # Draw seconds of running timout to column.
  132. # Two arguments: timeout in seconds and offset
  133. local n=$1
  134. local c=$2
  135. (trap "exit 0" SIGTERM
  136. while test $((n--)) -gt 0; do
  137. sleep 1;
  138. if test $n -gt 9 ; then
  139. echo -en "\015${esc}[${c}C(${n}s) "
  140. else
  141. echo -en "\015${esc}[${c}C( ${n}s) "
  142. fi
  143. done) & _rc_timer_pid=$!
  144. }
  145. rc_timer_off () {
  146. if test -n "$_rc_timer_pid" ; then
  147. kill -TERM $_rc_timer_pid > /dev/null 2>&1
  148. fi
  149. unset _rc_timer_pid
  150. }
  151. else
  152. esc=""
  153. extd=""
  154. warn=""
  155. done=""
  156. attn=""
  157. norm=""
  158. stat=""
  159.  
  160. rc_done="..done"
  161. rc_running="..running"
  162. rc_failed="..failed"
  163. rc_missed="..missing"
  164. rc_skipped="..skipped"
  165. rc_dead="..dead"
  166. rc_unused="..unused"
  167. rc_unknown="..unknown"
  168. rc_done_up="${rc_done}"
  169. rc_failed_up="${rc_failed}"
  170. rc_reset=""
  171. rc_save=""
  172. rc_restore=""
  173. rc_cuu () { return; }
  174. rc_cud () { return; }
  175. rc_timer_on () { return; }
  176. rc_timer_off () { return; }
  177. fi
  178.  
  179. _rc_service=${0##*/[SK][0-9][0-9]}
  180. _rc_status=0
  181. _rc_status_all=0
  182. _rc_todo=$1
  183.  
  184. rc_check ()
  185. {
  186. _rc_status_ret=$?
  187. test $_rc_status_ret -eq 0 || _rc_status=$_rc_status_ret
  188. test $_rc_status -eq 0 || _rc_status_all=$_rc_status
  189. return $_rc_status_ret
  190. }
  191.  
  192. rc_reset ()
  193. {
  194. _rc_status=0
  195. _rc_status_all=0
  196. rc_check
  197. return 0
  198. }
  199.  
  200. if test "$_rc_todo" = "status" ; then
  201. rc_status ()
  202. {
  203. rc_check
  204. _rc_status_ret=$_rc_status
  205. local i
  206. for i ; do
  207. case "$i" in
  208. -v|-v[1-9]|-v[1-9][0-9])
  209. local vrt=""
  210. local out=1
  211. local opt="en"
  212.  
  213. test -n "${i#-v}" && vrt=${esc:+"${esc}[${i#-v}A"} || opt="e"
  214. case "$_rc_status" in
  215. 0) vrt="$vrt$rc_running"; ;; # service running
  216. 1) vrt="$vrt$rc_dead" ; out=2 ;; # service dead (but has pid file)
  217. 2) vrt="$vrt$rc_dead" ; out=2 ;; # service dead (but has lock file)
  218. 3) vrt="$vrt$rc_unused" ; ;; # service not running
  219. 4) vrt="$vrt$rc_unknown"; ;; # status is unknown
  220. esac
  221. echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  222.  
  223. # reset _rc_status to 0 after verbose case
  224. _rc_status=0 ;;
  225. -r) rc_reset ;;
  226. -s) echo -e "$rc_skipped" ; rc_failed 3 ;;
  227. -u) echo -e "$rc_unused" ; rc_failed 3 ;;
  228. *) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  229. esac
  230. done
  231. return $_rc_status_ret
  232. }
  233. elif test -n "$_rc_todo" ; then
  234. rc_status ()
  235. {
  236. rc_check
  237. test "$_rc_status" -gt 7 && rc_failed 1
  238. _rc_status_ret=$_rc_status
  239. case "$_rc_todo" in
  240. stop)
  241. # program is not running which
  242. # is success if we stop service
  243. test "$_rc_status" -eq 7 && rc_failed 0 ;;
  244. esac
  245. local i
  246. for i ; do
  247. case "$i" in
  248. -v|-v[1-9]|-v[1-9][0-9])
  249. local vrt=""
  250. local out=1
  251. local opt="en"
  252.  
  253. test -n "${i#-v}" && vrt=${esc:+"${esc}[${i#-v}A"} || opt="e"
  254. case "$_rc_status" in
  255. 0) vrt="$vrt$rc_done" ; ;; # success
  256. 1) vrt="$vrt$rc_failed" ; out=2 ;; # generic or unspecified error
  257. 2) vrt="$vrt$rc_failed" ; out=2 ;; # invalid or excess args
  258. 3) vrt="$vrt$rc_missed" ; out=2 ;; # unimplemented feature
  259. 4) vrt="$vrt$rc_failed" ; out=2 ;; # insufficient privilege
  260. 5) vrt="$vrt$rc_skipped"; out=2 ;; # program is not installed
  261. 6) vrt="$vrt$rc_unused" ; out=2 ;; # program is not configured
  262. 7) vrt="$vrt$rc_failed" ; out=2 ;; # program is not running
  263. *) vrt="$vrt$rc_failed" ; out=2 ;; # unknown (maybe used in future)
  264. esac
  265. echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  266.  
  267. # reset _rc_status to 0 after verbose case
  268. _rc_status=0 ;;
  269. -r) rc_reset ;;
  270. -s) echo -e "$rc_skipped" 1>&2 ; rc_failed 5 ;;
  271. -u) echo -e "$rc_unused" 1>&2 ; rc_failed 6 ;;
  272. *) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  273. esac
  274. done
  275. return $_rc_status_ret
  276. }
  277. else
  278. rc_status ()
  279. {
  280. rc_check
  281. _rc_status_ret=$_rc_status
  282. local i
  283. for i ; do
  284. case "$i" in
  285. -v|-v[1-9]|-v[1-9][0-9])
  286. local vrt=""
  287. local out=1
  288. local opt="en"
  289.  
  290. test -n "${i#-v}" && vrt=${esc:+"${esc}[${i#-v}A"} || opt="e"
  291. case "$_rc_status" in
  292. 0) vrt="$vrt$rc_done" ; ;; # success
  293. *) vrt="$vrt$rc_failed"; out=2 ;; # failed
  294. esac
  295. echo -$opt "$rc_save$vrt$rc_restore" 1>&$out
  296.  
  297. # reset _rc_status to 0 after verbose case
  298. _rc_status=0 ;;
  299. -r) rc_reset ;;
  300. -s) echo -e "$rc_skipped" ; return 0 ;;
  301. -u) echo -e "$rc_unused" ; return 0 ;;
  302. *) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
  303. esac
  304. done
  305. return $_rc_status_ret
  306. }
  307. fi
  308.  
  309. rc_failed ()
  310. {
  311. rc_reset
  312. case "$1" in
  313. [0-7]) _rc_status=$1 ;;
  314. "") _rc_status=1
  315. esac
  316. rc_check
  317. return $_rc_status
  318. }
  319.  
  320. rc_exit ()
  321. {
  322. exit $_rc_status_all
  323. }
  324.  
  325. rc_confirm()
  326. {
  327. local timeout="30"
  328. local answer=""
  329. local ret=0
  330.  
  331. case "$1" in
  332. -t) timeout=$2; shift 2 ;;
  333. esac
  334. local message="$@, (Y)es/(N)o/(C)ontinue? [y] "
  335. : ${REDIRECT:=/dev/tty}
  336.  
  337. while true ; do
  338. read -t ${timeout} -n 1 -p "${message}" answer < $REDIRECT > $REDIRECT 2>&1
  339. case "$answer" in
  340. [yY]|"") ret=0; break ;;
  341. [nN]) ret=1; break ;;
  342. [cC]) ret=2; break ;;
  343. *) echo; continue
  344. esac
  345. done
  346. echo
  347. return $ret
  348. }
  349.  
  350. rc_active ()
  351. {
  352. local link
  353. for link in /etc/init.d/*.d/S[0-9][0-9]${1} ; do
  354. test -e $link || break
  355. return 0
  356. done
  357. return 1
  358. }
  359.  
  360. rc_splash()
  361. {
  362. return 0
  363. }
  364.  
  365. # Wait between last SIGTERM and the next SIGKILL
  366. # any argument specify a *path* of a process which
  367. # process identity should *not* be checked.
  368. rc_wait()
  369. {
  370. local -i etime=$SECONDS
  371.  
  372. if test -f /fastboot ; then
  373. let etime+=2
  374. else
  375. let etime+=6
  376. fi
  377.  
  378. local -i pid
  379. local -i ppid=$$
  380. local comm state rest
  381. local parent_processes="$ppid"
  382.  
  383. while test $ppid -gt 1; do
  384. read -t 1 pid comm state ppid rest < /proc/$ppid/stat
  385. parent_processes="${parent_processes:+$parent_processes:}${ppid}"
  386. done
  387. for comm ; do
  388. test -s $comm || continue
  389. ppid="$(/sbin/pidofproc $comm 2> /dev/null)" || continue
  390. parent_processes="${parent_processes:+$parent_processes:}${ppid}"
  391. done
  392. unset comm state ppid rest
  393.  
  394. local -i busy
  395. while test $SECONDS -lt $etime; do
  396. let busy=0
  397. for proc in /proc/[0-9]* ; do
  398. test -e $proc/exe || continue
  399. let pid=${proc##*/}
  400. case ":${parent_processes}:" in
  401. *:${pid}:*) continue
  402. esac
  403. let busy=pid
  404. break
  405. done
  406. test $busy -ne 0 || return 0
  407. usleep 500000
  408. done
  409. }
  410.  
  411. rc_runlevel()
  412. {
  413. test -z "$RUNLEVEL" || return
  414. set -- $(/sbin/runlevel)
  415. PREVLEVEL=$1
  416. RUNLEVEL=$2
  417. export PREVLEVEL RUNLEVEL
  418. }
  419.  
  420. cmdline=""
  421. rc_cmdline()
  422. {
  423. local arg cmd key val
  424. test -e /proc/cmdline || mount -nt proc proc /proc
  425. test -n "$cmdline" || read -t 2 cmdline < /proc/cmdline
  426. for arg; do
  427. for cmd in $cmdline ; do
  428. key="${cmd%%=*}"
  429. key="${key//-/_}"
  430. case "${key}" in
  431. $arg)
  432. case "$cmd" in
  433. *=*) val="${cmd#*=}" ;;
  434. *) val=yes
  435. esac
  436. echo $key=$val
  437. return 0
  438. esac
  439. done
  440. done
  441. return 1
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement