]> git.pld-linux.org Git - projects/rc-scripts.git/blame - rc.d/rc
mdadm: accept "DEVICE partitions" as indication to start mdadm
[projects/rc-scripts.git] / rc.d / rc
CommitLineData
12de71be 1#!/bin/sh
7742e157 2#
5e6dfc29
JR
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.
7742e157 7#
b0443108 8#
5e6dfc29
JR
9# Original Author:
10# Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7742e157
AF
11#
12
de1fc6ce
JR
13# avoid being interrupted by child or keyboard
14trap ":" INT QUIT TSTP
15
16# Save argument
17argv1="$1"
4ff93da3 18argv2="$2"
de1fc6ce
JR
19
20# Get terminal size of standard input of the system console
21[ -z "$CONSOLE" ] && CONSOLE=/dev/console
cc10e704
JR
22if [ -c $CONSOLE ]; then
23 set -- $(stty size < $CONSOLE 2>/dev/null)
b12d58e5 24 LINES=$1
cc10e704
JR
25 COLUMNS=$2
26else
b12d58e5 27 LINES=
cc10e704
JR
28 COLUMNS=
29fi
de1fc6ce 30export LINES COLUMNS CONSOLE
5e6dfc29 31
38198f50
AM
32# NLS
33if [ -f /etc/sysconfig/i18n ]; then
5e6dfc29
JR
34 . /etc/sysconfig/i18n
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
38198f50
AM
45fi
46
e298d489
JR
47# Source function library.
48. /etc/rc.d/init.d/functions
49
4ff93da3 50if [ "$argv2" != "chroot" ]; then
5e6dfc29 51 # Now find out what the current and what the previous runlevel are.
5bf237b7 52 set $(runlevel)
5e6dfc29
JR
53 runlevel=$2
54 previous=$1
55 export runlevel previous
4ff93da3 56fi
7742e157 57
3e182383
JR
58# Get first argument. Set new runlevel to this argument.
59[ -n "$argv1" ] && runlevel="$argv1"
60
de1fc6ce
JR
61# if previous runlevel = current runlevel do nothing
62[ "$runlevel" = "$previous" ] && exit 0
63
3e182383
JR
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
66
7e04fe0e 67# if runlevel is 0 (halt) or 6 (reboot) change to first
5e6dfc29
JR
68# virtual console, and send messages to /dev/console
69# (it can be serial console too)
de1fc6ce 70if [ "$COLUMNS" -gt 0 ]; then
cc10e704 71 if [ "$argv2" != "chroot" ] && ! is_yes "$VSERVER" && \
b12d58e5 72 [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
de1fc6ce
JR
73 CONSOLE=/dev/tty1
74 [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > $CONSOLE
75 exec 0<> /dev/console 1>&0 2>&0
76 fi
7e04fe0e 77else
de1fc6ce
JR
78 # Serial: columns and lines are not defined
79 LINES=24
80 COLUMNS=80
7e04fe0e 81fi
82
6b4a354c
AM
83# See if we want to be in user confirmation mode
84if [ "$previous" = "N" ]; then
1a722d30
JR
85 if ! is_yes "$VSERVER" && grep -qi confirm /proc/cmdline >/dev/null 2>/dev/null \
86 || [ -f /var/run/confirm ]; then
6b4a354c
AM
87 rm -f /var/run/confirm
88 CONFIRM="yes"
89 nls "Entering interactive startup"
90 else
91 CONFIRM=
92 nls "Entering non-interactive startup"
93 fi
94fi
b6509675
AM
95
96# calculate bootsplash variables
8bdd672f
AM
97sscripts=0
98for i in /etc/rc.d/rc$runlevel.d/S*; do
99 [ ! -f $i ] && continue
100 [ "${1%.rpmsave}" != "${1}" ] && continue
5e6dfc29
JR
101 [ "${1%.rpmorig}" != "${1}" ] && continue
102 [ "${1%.rpmnew}" != "${1}" ] && continue
8bdd672f
AM
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 ))
107done
b6509675
AM
108export sscripts
109
110if test "$previous" != "N" ; then
8bdd672f 111 kscripts=0
5e6dfc29
JR
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
8bdd672f 117 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
5e6dfc29 118 [ ! -f /var/lock/subsys/$subsys ] && \
b12d58e5 119 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
8bdd672f
AM
120 kscripts=$(( kscripts + 1 ))
121 done
b6509675
AM
122 export kscripts
123fi
124
2eb86030 125if test "$previous" = "N" -a "$runlevel" = "5" ; then
b6509675
AM
126 export progress=16
127 sscripts=$(( $sscripts + 15 ))
128else
129 export progress=0
130fi
131
cc10e704
JR
132if 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
137 fi
138fi
139
7e04fe0e 140# set onlcr to avoid staircase effect and do not lock scrolling
cc10e704 141stty onlcr -ixon 0>&1 2>/dev/null
7e04fe0e 142
7e04fe0e 143# Say something ;)
503bfc80
AM
144af2=$(termput setaf $CRESMAN)
145af6=$(termput setaf $CBRACKETS)
146af7=$(termput op)
de1fc6ce
JR
147text="$(termput op)$(nls '%sResource Manager: %sEntering runlevel number' "$af2" "$af7")"
148text_size="$(nls '%sResource Manager: %sEntering runlevel number' "" "")"
149resp_size="$(nls 'DONE')"
1e50dc5b 150{
944d6d80
ER
151 local _len=${#text_size}
152 local _last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
1e50dc5b
JR
153 while [ $((_len++)) -lt $_last_col ]; do
154 text="$text."
155 done
156 echo -n "$text"
157}
b3301c54 158echo "${af6}[${af2} $runlevel ${af6}]${af7}"
7e04fe0e 159
7742e157
AF
160# Is there an rc directory for this new runlevel?
161if [ -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
166
7e04fe0e 167 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
12de71be 168 [ "${1%.rpmsave}" != "${1}" ] && continue
169 [ "${1%.rpmorig}" != "${1}" ] && continue
7e04fe0e 170 [ "${1%.rpmnew}" != "${1}" ] && continue
12de71be 171
7742e157
AF
172 # Check if the subsystem is already up.
173 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
174 [ ! -f /var/lock/subsys/$subsys ] && \
b12d58e5 175 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
7742e157 176
fae22957 177 rc_splash "$i stop"
5e6dfc29 178
7742e157
AF
179 # Bring the subsystem down.
180 $i stop
181 done
182
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
187
12de71be 188 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
189 [ "${1%.rpmsave}" != "${1}" ] && continue
190 [ "${1%.rpmorig}" != "${1}" ] && continue
7e04fe0e 191 [ "${1%.rpmnew}" != "${1}" ] && continue
12de71be 192
7742e157
AF
193 # Check if the subsystem is already up.
194 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
195 [ -f /var/lock/subsys/$subsys ] || \
b12d58e5 196 [ -f /var/lock/subsys/${subsys}.init ] && continue
7742e157 197
d689a6c6 198 # Check if it is managed by upstart
9f0f5f5f 199 use_upstart && [ -f /etc/init/${subsys}.conf ] && continue
d689a6c6 200
6b4a354c 201 # If we're in confirmation mode, get user confirmation
5e6dfc29 202 [ -n "$CONFIRM" ] &&
6b4a354c
AM
203 {
204 confirm $subsys
205 case $? in
206 0)
207 :
5e6dfc29 208 ;;
6b4a354c
AM
209 2)
210 CONFIRM=
5e6dfc29 211 ;;
6b4a354c
AM
212 *)
213 continue
5e6dfc29 214 ;;
6b4a354c
AM
215 esac
216 }
217
fae22957 218 rc_splash "$i start"
7742e157
AF
219 # Bring the subsystem up.
220 $i start
221 done
222fi
7e04fe0e 223
791f7cd2
JR
224# if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
225if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
d0f42664
JR
226 unset LANG
227 unset LC_CTYPE
228 unset LC_NUMERIC
229 unset LC_TIME
230 unset LC_COLLATE
231 unset LC_MONETARY
232 unset LC_MESSAGES
233 unset LC_PAPER
234 unset LC_NAME
235 unset LC_ADDRESS
236 unset LC_TELEPHONE
237 unset LC_MEASUREMENT
238 unset LC_IDENTIFICATION
239 unset LC_ALL
a4775116
JR
240 TMPDIR=/dev/null
241 export TMPDIR
4ff93da3 242 if [ "$argv2" != "chroot" ]; then
5e6dfc29 243 exec /etc/rc.d/rc.shutdown $runlevel $previous
4ff93da3 244 else
5e6dfc29 245 exit 0
4ff93da3 246 fi
791f7cd2 247else
aec12e26 248 if is_yes "$RUN_LDCONFIG" || [ ! -f /etc/ld.so.cache ] ; then
bff05174
JR
249 if [ -x /sbin/ldconfig ]; then
250 run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
251 fi
791f7cd2
JR
252 fi
253fi
254
fae22957
AM
255rc_splash "master"
256
7e04fe0e 257# Say something ;)
de1fc6ce
JR
258text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
259text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
83da4c41
AM
260
261_len=${#text_size}
262_last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
263while [ $((_len++)) -lt $_last_col ]; do
264 text="$text."
265done
266echo -n "$text"
267unset _len _last_col
268
2a3ee214 269echo "${af6}[${af2} $runlevel ${af6}]${af7}"
436bfb51 270unset af2 af6 af7
7e04fe0e 271
de1fc6ce 272exit 0
This page took 0.310311 seconds and 4 git commands to generate.