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.
11 # Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
12 # Changes: Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
15 # avoid being interrupted by child or keyboard
16 trap ":" INT QUIT TSTP
22 # Get terminal size of standard input of the system console
23 [ -z "$CONSOLE" ] && CONSOLE=/dev/console
24 if [ -c $CONSOLE ]; then
25 set -- $(stty size < $CONSOLE 2>/dev/null)
32 export LINES COLUMNS CONSOLE
35 if [ -f /etc/sysconfig/i18n ]; then
37 [ -n "$LANG" ] && export LANG || unset LANG
38 [ -n "$LC_CTYPE" ] && export LC_CTYPE || unset LC_CTYPE
39 [ -n "$LC_COLLATE" ] && export LC_COLLATE || unset LC_COLLATE
40 [ -n "$LC_MESSAGES" ] && export LC_MESSAGES || unset LC_MESSAGES
41 [ -n "$LC_NUMERIC" ] && export LC_NUMERIC || unset LC_NUMERIC
42 [ -n "$LC_MONETARY" ] && export LC_MONETARY || unset LC_MONETARY
43 [ -n "$LC_TIME" ] && export LC_TIME || unset LC_TIME
44 [ -n "$LC_ALL" ] && export LC_ALL || unset LC_ALL
45 [ -n "$LANGUAGE" ] && export LANGUAGE || unset LANGUAGE
46 [ -n "$LINGUAS" ] && export LINGUAS || unset LINGUAS
49 # Read system config data.
50 if [ -f /etc/sysconfig/system ]; then
51 . /etc/sysconfig/system
53 RUN_SULOGIN_ON_ERR=yes
63 # Source function library.
64 . /etc/rc.d/init.d/functions
66 if [ "$argv2" != "chroot" ]; then
67 # Now find out what the current and what the previous runlevel are.
71 export runlevel previous
74 # Get first argument. Set new runlevel to this argument.
75 [ -n "$argv1" ] && runlevel="$argv1"
77 # if previous runlevel = current runlevel do nothing
78 [ "$runlevel" = "$previous" ] && exit 0
80 # Tell linuxconf what runlevel we are in
81 [ -d /var/run -a -w /var/run ] && echo "/etc/rc.d/rc$runlevel.d" > /var/run/runlevel.dir
83 # if runlevel is 0 (halt) or 6 (reboot) change to first
84 # virtual console, and send messages to /dev/console
85 # (it can be serial console too)
86 if [ "$COLUMNS" -gt 0 ]; then
87 if [ "$argv2" != "chroot" ] && ! is_yes "$VSERVER" && \
88 [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
90 [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > $CONSOLE
91 exec 0<> /dev/console 1>&0 2>&0
94 # Serial: columns and lines are not defined
99 # See if we want to be in user confirmation mode
100 if [ "$previous" = "N" ]; then
101 if grep -qi confirm /proc/cmdline >/dev/null 2>/dev/null \
102 || [ -f /var/run/confirm ] || ! is_yes "$VSERVER"; then
103 rm -f /var/run/confirm
105 nls "Entering interactive startup"
108 nls "Entering non-interactive startup"
112 # calculate bootsplash variables
114 for i in /etc/rc.d/rc$runlevel.d/S*; do
115 [ ! -f $i ] && continue
116 [ "${1%.rpmsave}" != "${1}" ] && continue
117 [ "${1%.rpmorig}" != "${1}" ] && continue
118 [ "${1%.rpmnew}" != "${1}" ] && continue
119 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
120 [ -f /var/lock/subsys/$subsys ] && \
121 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
122 sscripts=$(( sscripts + 1 ))
126 if test "$previous" != "N" ; then
128 for i in /etc/rc.d/rc$runlevel.d/K*; do
129 [ ! -f $i ] && continue
130 [ "${1%.rpmsave}" != "${1}" ] && continue
131 [ "${1%.rpmorig}" != "${1}" ] && continue
132 [ "${1%.rpmnew}" != "${1}" ] && continue
133 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
134 [ ! -f /var/lock/subsys/$subsys ] && \
135 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
136 kscripts=$(( kscripts + 1 ))
141 if test "$previous" == "N" -a "$runlevel" == "5" ; then
143 sscripts=$(( $sscripts + 15 ))
148 if is_yes "$VSERVER"; then
149 # if runlevel is not 0 (halt) or 6 (reboot) run rc.sysinit
150 # BUT only if rc is run standalone (not run by init, as init will run rc.sysinit)
151 if [ "$previous" != "N" -a "$runlevel" != "0" -a "$runlevel" != "6" ]; then
152 /etc/rc.d/rc.sysinit $runlevel
156 # set onlcr to avoid staircase effect and do not lock scrolling
157 stty onlcr -ixon 0>&1 2>/dev/null
160 af2=$(termput setaf $CRESMAN)
161 af6=$(termput setaf $CBRACKETS)
163 text="$(termput op)$(nls '%sResource Manager: %sEntering runlevel number' "$af2" "$af7")"
164 text_size="$(nls '%sResource Manager: %sEntering runlevel number' "" "")"
165 resp_size="$(nls 'DONE')"
167 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
168 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
170 # Is there an rc directory for this new runlevel?
171 if [ -d /etc/rc.d/rc$runlevel.d ]; then
172 # First, run the KILL scripts.
173 for i in /etc/rc.d/rc$runlevel.d/K*; do
174 # Check if the script is there.
175 [ ! -f $i ] && continue
177 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
178 [ "${1%.rpmsave}" != "${1}" ] && continue
179 [ "${1%.rpmorig}" != "${1}" ] && continue
180 [ "${1%.rpmnew}" != "${1}" ] && continue
182 # Check if the subsystem is already up.
183 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
184 [ ! -f /var/lock/subsys/$subsys ] && \
185 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
189 # Bring the subsystem down.
193 # Now run the START scripts.
194 for i in /etc/rc.d/rc$runlevel.d/S*; do
195 # Check if the script is there.
196 [ ! -f $i ] && continue
198 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
199 [ "${1%.rpmsave}" != "${1}" ] && continue
200 [ "${1%.rpmorig}" != "${1}" ] && continue
201 [ "${1%.rpmnew}" != "${1}" ] && continue
203 # Check if the subsystem is already up.
204 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
205 [ -f /var/lock/subsys/$subsys ] || \
206 [ -f /var/lock/subsys/${subsys}.init ] && continue
208 # If we're in confirmation mode, get user confirmation
226 # Bring the subsystem up.
231 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
232 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
245 unset LC_IDENTIFICATION
249 if [ "$argv2" != "chroot" ]; then
250 exec /etc/rc.d/rc.shutdown $runlevel $previous
255 if is_yes "$RUN_LDCONFIG" || [ ! -f /etc/ld.so.cache ] ; then
256 if [ -x /sbin/ldconfig ]; then
257 run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
265 text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
266 text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
268 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
269 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
274 # This must be last line !