rc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/bin/sh
  2. # Begin $RC_BASE/init.d/rc
  3. # Get the configuration file
  4. # All changes are to occur in the config file
  5. . /etc/default/rc
  6. # These 3 signals will not cause our script to exit
  7. trap "" INT QUIT TSTP
  8. # Simple sanity check - rc only takes one argument
  9. if [ "${#}" -ne 1 ]; then
  10. echo "Usage: ${0} <runlevel>" >&2
  11. exit 1
  12. fi
  13. # Do not use the RUNLEVEL and PREVLEVEL variables provided by init so
  14. # that they can be modified and alternate directories (S) can
  15. # be used without affecting init
  16. runlevel="${1}"
  17. prevlevel="${PREVLEVEL}"
  18. # Just in case - some flavors of init don't set PREVLEVEL to 'N'
  19. if [ "${prevlevel}" = "" ]; then
  20. prevlevel="N"
  21. fi
  22. # Mount /run
  23. if [ "${runlevel}" = "S" ]; then
  24. mount -n -t tmpfs tmpfs /run
  25. fi
  26. # Provide an interactive prompt (if requested)
  27. if [ "${runlevel}" = "S" -a "${iprompt}" = "yes" ]; then
  28. # ash does not accept t and n flags for read
  29. ls -l /bin/sh | grep "/ash"
  30. if [ "${?}" -eq "0" ]; then
  31. # We are using ash
  32. echo -e -n "${WARNING}WARNING: Either bash or zsh is required"
  33. echo -e "${WARNING} for interactive startup.\n"
  34. sleep 3
  35. else
  36. echo ""
  37. # dcol and icol are spaces before the message to center the
  38. # message on screen.
  39. dcol=$(( $(( ${COLUMNS} - ${dlen} )) / 2 ))
  40. icol=$(( $(( ${COLUMNS} - ${ilen} )) / 2 ))
  41. echo -e "\\033[${dcol}G${welcome_message}"
  42. echo -e "\\033[${icol}G${i_message}${NORMAL}"
  43. echo ""
  44. read -t "${itime}" -n 1 interactive 2>&1 > /dev/null
  45. if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
  46. echo -n -e "${CURS_UP}"
  47. echo -e "${INFO}Interactive boot selected...${NORMAL}"
  48. echo "interactive=I" > /run/.interactive-start
  49. fi
  50. fi
  51. fi
  52. # Verify that the directory exists
  53. if [ ! -d "${RC_BASE}/rc${runlevel}.d" ]; then
  54. echo -n -e "${WARNING}${RC_BASE}/rc${runlevel}.d does not exist."
  55. echo -e "${NORMAL}"
  56. exit 1
  57. fi
  58. # Source the interactive state file if it exists
  59. if [ "${runlevel}" != "S" -a -f /run/.interactive-start ]; then
  60. . /run/.interactive-start
  61. fi
  62. # Prompt for interactive startup after completing S
  63. if [ "${interactive}" = "I" -a "${runlevel}" != "S" -a \
  64. "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
  65. echo -n -e "Proceed with interactive starup of runlevel "
  66. echo -n -e "${INFO}${runlevel}${NORMAL}?"
  67. echo -n -e "(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
  68. read -n 1 go_on
  69. echo ""
  70. if [ "${go_on}" = "n" ]; then
  71. # don't continue
  72. exit 0
  73. fi
  74. fi
  75. # Attempt to stop all services started in the previous runlevel,
  76. # that are stopped in this runlevel
  77. if [ "${prevlevel}" != "N" ]; then
  78. for link in $(ls -v ${RC_BASE}/rc${runlevel}.d/K* 2> /dev/null)
  79. do
  80. # Check to see if link is a valid symlink
  81. if [ ! -f ${link} ]; then
  82. echo -e "${WARNING}${link} is not a valid symlink."
  83. continue # go on to the next K* link
  84. fi
  85. # Check to see if link is executable
  86. if [ ! -x ${link} ]; then
  87. echo -e "${WARNING}${link} is not executable, skipping."
  88. continue # go on to the next K* link
  89. fi
  90. script=${link#$RC_BASE/rc$runlevel.d/K[0-9][0-9]}
  91. prev_start=$RC_BASE/rc$prevlevel.d/S[0-9][0-9]$script
  92. S_start=$RC_BASE/rcS.d/S[0-9][0-9]$script
  93. if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
  94. if [ ! -f ${prev_start} ] && [ ! -f ${S_start} ]; then
  95. echo -e -n "${WARNING}WARNING:\n\n${link} can't be"
  96. echo -e "${WARNING} executed because it was not"
  97. echo -e -n "${WARNING} not started in the previous"
  98. echo -e "${WARNING} runlevel (${prevlevel})."
  99. echo -e "${NORMAL}"
  100. continue
  101. fi
  102. fi
  103. ${link} stop
  104. error_value=${?}
  105. if [ "${error_value}" -ne "0" ]; then
  106. print_error_msg
  107. fi
  108. done
  109. fi
  110. # Start all functions in this runlevel if they weren't started in
  111. # the previous runlevel
  112. for link in $(ls -v ${RC_BASE}/rc${runlevel}.d/S* 2> /dev/null)
  113. do
  114. if [ "${prevlevel}" != "N" ]; then
  115. script=${link#$RC_BASE/rc$runlevel.d/S[0-9][0-9]}
  116. stop=$RC_BASE/rc$runlevel.d/K[0-9][0-9]$script
  117. prev_start=$RC_BASE/rc$prevlevel.d/S[0-9][0-9]$script
  118. [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
  119. fi
  120. # Check to see if link is a valid symlink
  121. if [ ! -f ${link} ]; then
  122. echo -e "${WARNING}${link} is not a valid symlink."
  123. continue # go on to the next K* link
  124. fi
  125. # Check to see if link is executable
  126. if [ ! -x ${link} ]; then
  127. echo -e "${WARNING}${link} is not executable, skipping."
  128. continue # go on to the next K* link
  129. fi
  130. case ${runlevel} in
  131. 0|6)
  132. ${link} stop
  133. ;;
  134. *)
  135. if [ "${interactive}" = "I" -o "${interactive}" = "i" ]; then
  136. echo -e -n "${WARNING}Start ${INFO}${link} ${WARNING}?"
  137. echo -e -n "${NORMAL}(${FAILURE}y${NORMAL})es/(${FAILURE}n${NORMAL})o "
  138. read -n 1 startit 2>&1 > /dev/null
  139. echo ""
  140. if [ "${startit}" = "y" -o "${startit}" = "Y" ]; then
  141. ${link} start
  142. else
  143. echo -e -n "${WARNING}Not starting ${INFO}${link}"
  144. echo -e "${WARNING}.${NORMAL}\n"
  145. fi
  146. else
  147. ${link} start
  148. fi
  149. ;;
  150. esac
  151. error_value=${?}
  152. if [ "${error_value}" -gt "1" ]; then
  153. print_error_msg
  154. fi
  155. done
  156. # Strip apply time to the logs, strip out any color codes and dump
  157. # the log to /var/log/boot.log
  158. if [ -f /run/.bootlog -a "${runlevel}" != "S" ]; then
  159. # Remove any color codes from the temp log file
  160. sed -i 's@\\033\[[0-9];[0-9][0-9]m@@g' /run/.bootlog
  161. #Fix the time and hostname
  162. BTIMESPEC=$(echo `date +"%b %d %T"` `hostname`)
  163. sed -i "s@^bootlog:@${BTIMESPEC} bootlog:@" /run/.bootlog
  164. # Don't try and write in 0 and 6, this is a 'boot' log
  165. if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then
  166. cat /run/.bootlog >> /var/log/boot.log
  167. rm -f /run/.bootlog
  168. fi
  169. fi
  170. # Remove interactive boot temp file
  171. if [ -f /run/.interactive-start -a "${runlevel}" != "S" ]; then
  172. rm -f /run/.interactive-start
  173. fi
  174. # End $RC_BASE/init.d/rc