[f874424] | 1 | #!/bin/bash
|
---|
[1c48007] | 2 | ########################################################################
|
---|
[0cda898] | 3 | # Begin rc
|
---|
[1c48007] | 4 | #
|
---|
| 5 | # Description : Main Run Level Control Script
|
---|
| 6 | #
|
---|
| 7 | # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
[f874424] | 8 | # : DJ Lucas - dj@linuxfromscratch.org
|
---|
[0cda898] | 9 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
[1c48007] | 10 | #
|
---|
[0cda898] | 11 | # Version : LFS 7.0
|
---|
[1c48007] | 12 | #
|
---|
| 13 | ########################################################################
|
---|
| 14 |
|
---|
[f874424] | 15 | . /lib/lsb/init-functions
|
---|
[0cda898] | 16 |
|
---|
[f874424] | 17 | function print_error_msg()
|
---|
[0cda898] | 18 | {
|
---|
[f874424] | 19 | log_failure_msg
|
---|
[0cda898] | 20 | # $i is set when called
|
---|
[f874424] | 21 | MSG="FAILURE:\n\nYou should not be reading this error message.\n\n"
|
---|
| 22 | MSG="${MSG}It means that an unforeseen error took place in\n"
|
---|
| 23 | MSG="${MSG}${i},\n"
|
---|
| 24 | MSG="${MSG}which exited with a return value of ${error_value}.\n"
|
---|
| 25 |
|
---|
| 26 | MSG="${MSG}If you're able to track this error down to a bug in one of\n"
|
---|
| 27 | MSG="${MSG}the files provided by the files provided by\n"
|
---|
| 28 | MSG="${MSG}the ${DISDRI_MINI} book, please be so kind to inform us at\n"
|
---|
| 29 | MSG="${MSG}${DISTRO_CONTACT}.\n"
|
---|
| 30 | log_failure_msg "${MSG}"
|
---|
| 31 |
|
---|
| 32 | log_info_msg "Press Enter to continue..."
|
---|
[0cda898] | 33 | wait_for_user
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[f874424] | 36 | function check_script_status()
|
---|
[0cda898] | 37 | {
|
---|
| 38 | # $i is set when called
|
---|
| 39 | if [ ! -f ${i} ]; then
|
---|
[f874424] | 40 | log_warning_msg "${i} is not a valid symlink."
|
---|
[0cda898] | 41 | continue
|
---|
| 42 | fi
|
---|
| 43 |
|
---|
| 44 | if [ ! -x ${i} ]; then
|
---|
[f874424] | 45 | log_warning_msg "${i} is not executable, skipping."
|
---|
[0cda898] | 46 | continue
|
---|
| 47 | fi
|
---|
| 48 | }
|
---|
[1c48007] | 49 |
|
---|
[f874424] | 50 | function run()
|
---|
| 51 | {
|
---|
| 52 | if [ -z $interactive ]; then
|
---|
| 53 | ${1} ${2}
|
---|
| 54 | return $?
|
---|
| 55 | fi
|
---|
| 56 |
|
---|
| 57 | while true; do
|
---|
| 58 | read -p "Run ${1} ${2} (Yes/no/continue)? " -n 1 runit
|
---|
| 59 | echo
|
---|
| 60 |
|
---|
| 61 | case ${runit} in
|
---|
| 62 | c | C)
|
---|
| 63 | interactive=""
|
---|
| 64 | ${i} ${2}
|
---|
| 65 | ret=${?}
|
---|
| 66 | break;
|
---|
| 67 | ;;
|
---|
| 68 |
|
---|
| 69 | n | N)
|
---|
| 70 | return 0
|
---|
| 71 | ;;
|
---|
| 72 |
|
---|
| 73 | y | Y)
|
---|
| 74 | ${i} ${2}
|
---|
| 75 | ret=${?}
|
---|
| 76 | break
|
---|
| 77 | ;;
|
---|
| 78 | esac
|
---|
| 79 | done
|
---|
| 80 |
|
---|
| 81 | return $ret
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | # Read any local settings/overrides
|
---|
| 85 | [ -r /etc/sysconfig/rc.site ] && source /etc/sysconfig/rc.site
|
---|
| 86 |
|
---|
| 87 | DISTRO=${DISTRO:-"Linux From Scratch"}
|
---|
| 88 | DISTRO_CONTACT=${DISTRO_CONTACT:-"lfs-dev@linuxfromscratch.org (Registration required)"}
|
---|
| 89 | DISTRO_MINI=${DISTRO_MINI:-"LFS"}
|
---|
[1c48007] | 90 |
|
---|
| 91 | # These 3 signals will not cause our script to exit
|
---|
| 92 | trap "" INT QUIT TSTP
|
---|
| 93 |
|
---|
| 94 | [ "${1}" != "" ] && runlevel=${1}
|
---|
| 95 |
|
---|
| 96 | if [ "${runlevel}" = "" ]; then
|
---|
[0cda898] | 97 | echo "Usage: ${0} <runlevel>" >&2
|
---|
| 98 | exit 1
|
---|
[1c48007] | 99 | fi
|
---|
| 100 |
|
---|
| 101 | previous=${PREVLEVEL}
|
---|
| 102 | [ "${previous}" = "" ] && previous=N
|
---|
| 103 |
|
---|
[0cda898] | 104 | if [ ! -d /etc/rc.d/rc${runlevel}.d ]; then
|
---|
[f874424] | 105 | log_info_msg "/etc/rc.d/rc${runlevel}.d does not exist.\n"
|
---|
[0cda898] | 106 | exit 1
|
---|
[1c48007] | 107 | fi
|
---|
| 108 |
|
---|
[f874424] | 109 | if [ "$runlevel" == "6" ] || [ "$runlevel" == "0" ]; then IPROMPT="no"; fi
|
---|
| 110 |
|
---|
| 111 | if [ "${IPROMPT}" == "yes" ]; then
|
---|
| 112 | # dcol and icol are spaces before the message to center the
|
---|
| 113 | # message on screen.
|
---|
| 114 |
|
---|
| 115 | wcol=$(( ( ${COLUMNS} - ${wlen} ) / 2 ))
|
---|
| 116 | icol=$(( ( ${COLUMNS} - ${ilen} ) / 2 ))
|
---|
| 117 |
|
---|
| 118 | echo -e "\\033[${wcol}G${welcome_message}"
|
---|
| 119 | echo -e "\\033[${icol}G${i_message}${NORMAL}"
|
---|
| 120 | echo ""
|
---|
| 121 | read -t "${itime}" -n 1 interactive 2>&1 > /dev/null
|
---|
| 122 |
|
---|
| 123 | # Make lower case
|
---|
| 124 | [ "${interactive}" == "I" ] && interactive="i"
|
---|
| 125 | [ "${interactive}" != "i" ] && interactive=""
|
---|
| 126 | fi
|
---|
| 127 |
|
---|
[0cda898] | 128 | # Attempt to stop all services started by the previous runlevel,
|
---|
[1c48007] | 129 | # and killed in this runlevel
|
---|
| 130 | if [ "${previous}" != "N" ]; then
|
---|
[0cda898] | 131 | for i in $(ls -v /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null)
|
---|
| 132 | do
|
---|
| 133 | check_script_status
|
---|
| 134 |
|
---|
| 135 | suffix=${i#/etc/rc.d/rc$runlevel.d/K[0-9][0-9]}
|
---|
| 136 | prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
|
---|
[f874424] | 137 | sysinit_start=/etc/rc.d/rcS.d/S[0-9][0-9]$suffix
|
---|
[0cda898] | 138 |
|
---|
[f874424] | 139 | if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
|
---|
[0cda898] | 140 | if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
|
---|
[f874424] | 141 | MSG="WARNING:\n\n${i} can't be "
|
---|
| 142 | MSG="${MSG}executed because it was not "
|
---|
| 143 | MSG="${MSG}not started in the previous "
|
---|
| 144 | MSG="${MSG}runlevel (${previous})."
|
---|
| 145 | log_warning_msg "$MSG"
|
---|
[0cda898] | 146 | continue
|
---|
| 147 | fi
|
---|
| 148 | fi
|
---|
[f874424] | 149 |
|
---|
| 150 | run ${i} stop
|
---|
[0cda898] | 151 | error_value=${?}
|
---|
| 152 |
|
---|
[f874424] | 153 | if [ "${error_value}" != "0" ]; then print_error_msg; fi
|
---|
[0cda898] | 154 | done
|
---|
[1c48007] | 155 | fi
|
---|
| 156 |
|
---|
[f874424] | 157 | if [ "${previous}" == "N" ]; then export IN_BOOT=1; fi
|
---|
| 158 |
|
---|
[5a58876] | 159 | if [ "$runlevel" == "6" ] && [ -n "${FASTBOOT}" ]; then
|
---|
[f874424] | 160 | touch /fastboot
|
---|
[13e7d79] | 161 | fi
|
---|
[0cda898] | 162 |
|
---|
[f874424] | 163 |
|
---|
| 164 | # Start all functions in this runlevel
|
---|
[0cda898] | 165 | for i in $( ls -v /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null)
|
---|
[1c48007] | 166 | do
|
---|
[0cda898] | 167 | if [ "${previous}" != "N" ]; then
|
---|
| 168 | suffix=${i#/etc/rc.d/rc$runlevel.d/S[0-9][0-9]}
|
---|
| 169 | stop=/etc/rc.d/rc$runlevel.d/K[0-9][0-9]$suffix
|
---|
| 170 | prev_start=/etc/rc.d/rc$previous.d/S[0-9][0-9]$suffix
|
---|
| 171 |
|
---|
| 172 | [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
|
---|
| 173 | fi
|
---|
| 174 |
|
---|
| 175 | check_script_status
|
---|
| 176 |
|
---|
| 177 | case ${runlevel} in
|
---|
| 178 | 0|6)
|
---|
[f874424] | 179 | run ${i} stop
|
---|
[0cda898] | 180 | ;;
|
---|
| 181 | *)
|
---|
[f874424] | 182 | run ${i} start
|
---|
[0cda898] | 183 | ;;
|
---|
| 184 | esac
|
---|
[f874424] | 185 |
|
---|
[0cda898] | 186 | error_value=${?}
|
---|
| 187 |
|
---|
[f874424] | 188 | if [ "${error_value}" != "0" ]; then print_error_msg; fi
|
---|
[1c48007] | 189 | done
|
---|
| 190 |
|
---|
[f874424] | 191 | # Copy the boot log on initial boot only
|
---|
| 192 | if [ "${previous}" == "N" ]; then
|
---|
| 193 | cat /run/var/bootlog >> /var/log/boot.log
|
---|
| 194 | echo "--------" >> /var/log/boot.log # Mark the end of boot
|
---|
| 195 | fi
|
---|
| 196 |
|
---|
[0cda898] | 197 | # End rc
|
---|