rc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin rc
  4. #
  5. # Description : Main Run Level Control Script
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  9. #
  10. # Version : LFS 7.0
  11. #
  12. ########################################################################
  13. . /lib/boot/functions
  14. print_error_msg()
  15. {
  16. echo_failure
  17. # $i is set when called
  18. boot_mesg -n "FAILURE:\n\nYou should not be reading this error message.\n\n" ${FAILURE}
  19. boot_mesg -n " It means that an unforeseen error took"
  20. boot_mesg -n " place in ${i}, which exited with a return value of"
  21. boot_mesg " ${error_value}.\n"
  22. boot_mesg_flush
  23. boot_mesg -n "If you're able to track this"
  24. boot_mesg -n " error down to a bug in one of the files provided by"
  25. boot_mesg -n " the LFS book, please be so kind to inform us at"
  26. boot_mesg " lfs-dev@linuxfromscratch.org.\n"
  27. boot_mesg_flush
  28. boot_mesg -n "Press Enter to continue..." ${INFO}
  29. boot_mesg "" ${NORMAL}
  30. wait_for_user
  31. }
  32. check_script_status()
  33. {
  34. # $i is set when called
  35. if [ ! -f ${i} ]; then
  36. boot_mesg "${i} is not a valid symlink." ${WARNING}
  37. echo_warning
  38. continue
  39. fi
  40. if [ ! -x ${i} ]; then
  41. boot_mesg "${i} is not executable, skipping." ${WARNING}
  42. echo_warning
  43. continue
  44. fi
  45. }
  46. # This sets a few default terminal options.
  47. stty sane
  48. # These 3 signals will not cause our script to exit
  49. trap "" INT QUIT TSTP
  50. [ "${1}" != "" ] && runlevel=${1}
  51. if [ "${runlevel}" = "" ]; then
  52. echo "Usage: ${0} <runlevel>" >&2
  53. exit 1
  54. fi
  55. previous=${PREVLEVEL}
  56. [ "${previous}" = "" ] && previous=N
  57. if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then
  58. boot_mesg "/etc/rc.d/rc${runlevel}.d does not exist."
  59. exit 1
  60. fi
  61. # Attempt to stop all services started by the previous runlevel,
  62. # and killed in this runlevel
  63. if [ "${previous}" != "N" ]; then
  64. for i in $(ls -v /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null)
  65. do
  66. check_script_status
  67. suffix=${i#/etc/rc.d/rc$runlevel.d/K[0-9][0-9]}
  68. prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
  69. sysinit_start=/etc/rc.d/rcsysinit.d/S[0-9][0-9]$suffix
  70. if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
  71. if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
  72. boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING}
  73. boot_mesg -n " executed because it was not"
  74. boot_mesg -n " not started in the previous"
  75. boot_mesg -n " runlevel (${previous})."
  76. boot_mesg "" ${NORMAL}
  77. boot_mesg_flush
  78. continue
  79. fi
  80. fi
  81. ${i} stop
  82. error_value=${?}
  83. if [ "${error_value}" != "0" ]; then
  84. print_error_msg
  85. fi
  86. done
  87. fi
  88. [ "${previous}" = "N" ] && IN_BOOT=1
  89. #Start all functions in this runlevel
  90. for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null)
  91. do
  92. if [ "${previous}" != "N" ]; then
  93. suffix=${i#/etc/rc.d/rc$runlevel.d/S[0-9][0-9]}
  94. stop=/etc/rc.d/rc$runlevel.d/K[0-9][0-9]$suffix
  95. prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
  96. [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
  97. fi
  98. check_script_status
  99. case ${runlevel} in
  100. 0|6)
  101. ${i} stop
  102. ;;
  103. *)
  104. ${i} start
  105. ;;
  106. esac
  107. error_value=${?}
  108. if [ "${error_value}" != "0" ]; then
  109. print_error_msg
  110. fi
  111. done
  112. # End rc