rc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $rc_base/init.d/rc
  4. #
  5. # Description : Main Run Level Control Script
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. #
  9. # Version : 00.00
  10. #
  11. # Notes :
  12. #
  13. ########################################################################
  14. . /etc/sysconfig/rc
  15. . ${rc_functions}
  16. # This sets a few default terminal options.
  17. stty sane
  18. # These 3 signals will not cause our script to exit
  19. trap "" INT QUIT TSTP
  20. [ "${1}" != "" ] && runlevel=${1}
  21. if [ "${runlevel}" = "" ]; then
  22. echo "Usage: ${0} <runlevel>" >&2
  23. exit 1
  24. fi
  25. previous=${PREVLEVEL}
  26. [ "${previous}" = "" ] && previous=N
  27. if [ ! -d ${rc_base}/rc${runlevel}.d ]; then
  28. boot_mesg "${rc_base}/rc${runlevel}.d does not exist." ${WARNING}
  29. boot_mesg_flush
  30. exit 1
  31. fi
  32. # Attempt to stop all service started by previous runlevel,
  33. # and killed in this runlevel
  34. if [ "${previous}" != "N" ]; then
  35. for i in $(ls -v ${rc_base}/rc${runlevel}.d/K* 2> /dev/null)
  36. do
  37. check_script_status
  38. suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
  39. prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
  40. sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix
  41. if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
  42. if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
  43. boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING}
  44. boot_mesg -n " executed because it was not"
  45. boot_mesg -n " not started in the previous"
  46. boot_mesg -n " runlevel (${previous})."
  47. boot_mesg "" ${NORMAL}
  48. boot_mesg_flush
  49. continue
  50. fi
  51. fi
  52. ${i} stop
  53. error_value=${?}
  54. if [ "${error_value}" != "0" ]; then
  55. print_error_msg
  56. fi
  57. done
  58. fi
  59. #Start all functions in this runlevel
  60. for i in $( ls -v ${rc_base}/rc${runlevel}.d/S* 2> /dev/null)
  61. do
  62. if [ "${previous}" != "N" ]; then
  63. suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
  64. stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
  65. prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
  66. [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
  67. fi
  68. check_script_status
  69. case ${runlevel} in
  70. 0|6)
  71. ${i} stop
  72. ;;
  73. *)
  74. ${i} start
  75. ;;
  76. esac
  77. error_value=${?}
  78. if [ "${error_value}" != "0" ]; then
  79. print_error_msg
  80. fi
  81. done
  82. # End $rc_base/init.d/rc