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