3 # rc This file is responsible for starting/stopping
4 # services when the runlevel changes. It is also
5 # responsible for the very first setup of basic
6 # things, such as setting the hostname.
10 # Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
13 # avoid being interrupted by child or keyboard
14 trap ":" INT QUIT TSTP
20 # Get terminal size of standard input of the system console
21 [ -z "$CONSOLE" ] && CONSOLE=/dev/console
22 if [ -c $CONSOLE ]; then
23 set -- $(stty size < $CONSOLE 2>/dev/null)
30 export LINES COLUMNS CONSOLE
33 if [ -f /etc/sysconfig/i18n ]; then
35 [ -n "$LANG" ] && export LANG || unset LANG
36 [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
37 [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
38 [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
39 [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
40 [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
41 [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
42 [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
43 [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
44 [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
47 # Source function library.
48 . /etc/rc.d/init.d/functions
50 if [ "$argv2" != "chroot" ]; then
51 # Now find out what the current and what the previous runlevel are.
55 export runlevel previous
58 # Get first argument. Set new runlevel to this argument.
59 [ -n "$argv1" ] && runlevel="$argv1"
61 # if previous runlevel = current runlevel do nothing
62 [ "$runlevel" = "$previous" ] && exit 0
64 # Tell linuxconf what runlevel we are in
65 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
67 # if runlevel is 0 (halt) or 6 (reboot) change to first
68 # virtual console, and send messages to /dev/console
69 # (it can be serial console too)
70 if [ "$COLUMNS" -gt 0 ]; then
71 if [ "$argv2" != "chroot" ] && ! is_yes "$VSERVER" && \
72 [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
74 [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > $CONSOLE
75 exec 0<> /dev/console 1>&0 2>&0
78 # Serial: columns and lines are not defined
83 # See if we want to be in user confirmation mode
84 if [ "$previous" = "N" ]; then
85 if ! is_yes "$VSERVER" && grep -qi confirm /proc/cmdline >/dev/null 2>/dev/null \
86 || [ -f /var/run/confirm ]; then
87 rm -f /var/run/confirm
89 nls "Entering interactive startup"
92 nls "Entering non-interactive startup"
96 # calculate bootsplash variables
98 for i in /etc/rc.d/rc$runlevel.d/S*; do
99 [ ! -f $i ] && continue
100 [ "${1%.rpmsave}" != "${1}" ] && continue
101 [ "${1%.rpmorig}" != "${1}" ] && continue
102 [ "${1%.rpmnew}" != "${1}" ] && continue
103 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
104 [ -f /var/lock/subsys/$subsys ] && \
105 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
106 sscripts=$(( sscripts + 1 ))
110 if test "$previous" != "N" ; then
112 for i in /etc/rc.d/rc$runlevel.d/K*; do
113 [ ! -f $i ] && continue
114 [ "${1%.rpmsave}" != "${1}" ] && continue
115 [ "${1%.rpmorig}" != "${1}" ] && continue
116 [ "${1%.rpmnew}" != "${1}" ] && continue
117 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
118 [ ! -f /var/lock/subsys/$subsys ] && \
119 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
120 kscripts=$(( kscripts + 1 ))
125 if test "$previous" = "N" -a "$runlevel" = "5" ; then
127 sscripts=$(( $sscripts + 15 ))
132 if is_yes "$VSERVER"; then
133 # if runlevel is not 0 (halt) or 6 (reboot) run rc.sysinit
134 # BUT only if rc is run standalone (not run by init, as init will run rc.sysinit)
135 if [ "$previous" != "N" -a "$runlevel" != "0" -a "$runlevel" != "6" ]; then
136 /etc/rc.d/rc.sysinit $runlevel
140 # set onlcr to avoid staircase effect and do not lock scrolling
141 stty onlcr -ixon 0>&1 2>/dev/null
144 af2=$(termput setaf $CRESMAN)
145 af6=$(termput setaf $CBRACKETS)
147 text="$(termput op)$(nls '%sResource Manager: %sEntering runlevel number' "$af2" "$af7")"
148 text_size="$(nls '%sResource Manager: %sEntering runlevel number' "" "")"
149 resp_size="$(nls 'DONE')"
151 local _len=${#text_size}
152 local _last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
153 while [ $((_len++)) -lt $_last_col ]; do
158 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
160 # Is there an rc directory for this new runlevel?
161 if [ -d /etc/rc.d/rc$runlevel.d ]; then
162 # First, run the KILL scripts.
163 for i in /etc/rc.d/rc$runlevel.d/K*; do
164 # Check if the script is there.
165 [ ! -f $i ] && continue
167 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
168 [ "${1%.rpmsave}" != "${1}" ] && continue
169 [ "${1%.rpmorig}" != "${1}" ] && continue
170 [ "${1%.rpmnew}" != "${1}" ] && continue
172 # Check if the subsystem is already up.
173 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
174 [ ! -f /var/lock/subsys/$subsys ] && \
175 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
179 # Bring the subsystem down.
183 # Now run the START scripts.
184 for i in /etc/rc.d/rc$runlevel.d/S*; do
185 # Check if the script is there.
186 [ ! -f $i ] && continue
188 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
189 [ "${1%.rpmsave}" != "${1}" ] && continue
190 [ "${1%.rpmorig}" != "${1}" ] && continue
191 [ "${1%.rpmnew}" != "${1}" ] && continue
193 # Check if the subsystem is already up.
194 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
195 [ -f /var/lock/subsys/$subsys ] || \
196 [ -f /var/lock/subsys/${subsys}.init ] && continue
198 # If we're in confirmation mode, get user confirmation
216 # Bring the subsystem up.
221 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
222 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
235 unset LC_IDENTIFICATION
239 if [ "$argv2" != "chroot" ]; then
240 exec /etc/rc.d/rc.shutdown $runlevel $previous
245 if is_yes "$RUN_LDCONFIG" || [ ! -f /etc/ld.so.cache ] ; then
246 if [ -x /sbin/ldconfig ]; then
247 run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
255 text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
256 text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
259 _last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
260 while [ $((_len++)) -lt $_last_col ]; do
266 echo "${af6}[${af2} $runlevel ${af6}]${af7}"