]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
remove not needed subshell
[projects/rc-scripts.git] / rc.d / rc
1 #!/bin/sh
2 #
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.
7 #
8 # $Id$
9 #
10 # Original Author:
11 #               Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
12 #
13
14 # avoid being interrupted by child or keyboard
15 trap ":" INT QUIT TSTP
16
17 # Save argument
18 argv1="$1"
19 argv2="$2"
20
21 # Get terminal size of standard input of the system console
22 [ -z "$CONSOLE" ] && CONSOLE=/dev/console
23 if [ -c $CONSOLE ]; then
24         set -- $(stty size < $CONSOLE 2>/dev/null)
25         LINES=$1
26         COLUMNS=$2
27 else
28         LINES=
29         COLUMNS=
30 fi
31 export LINES COLUMNS CONSOLE
32
33 # NLS
34 if [ -f /etc/sysconfig/i18n ]; then
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
46 fi
47
48 # Source function library.
49 . /etc/rc.d/init.d/functions
50
51 if [ "$argv2" != "chroot" ]; then
52         # Now find out what the current and what the previous runlevel are.
53         set $(runlevel)
54         runlevel=$2
55         previous=$1
56         export runlevel previous
57 fi
58
59 # Get first argument. Set new runlevel to this argument.
60 [ -n "$argv1" ] && runlevel="$argv1"
61
62 # if previous runlevel = current runlevel do nothing
63 [ "$runlevel" = "$previous" ] && exit 0
64
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
68 # if runlevel is 0 (halt) or 6 (reboot) change to first
69 # virtual console, and send messages to /dev/console
70 # (it can be serial console too)
71 if [ "$COLUMNS" -gt 0 ]; then
72         if [ "$argv2" != "chroot" ] && ! is_yes "$VSERVER" && \
73                 [ "$runlevel" = "0" -o "$runlevel" = "6" ]; then
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
78 else
79         # Serial: columns and lines are not defined
80           LINES=24
81         COLUMNS=80
82 fi
83
84 # See if we want to be in user confirmation mode
85 if [ "$previous" = "N" ]; then
86         if ! is_yes "$VSERVER" && grep -qi confirm /proc/cmdline >/dev/null 2>/dev/null \
87                 || [ -f /var/run/confirm ]; then
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
95 fi
96
97 # calculate bootsplash variables
98 sscripts=0
99 for i in /etc/rc.d/rc$runlevel.d/S*; do
100         [ ! -f $i ] && continue
101         [ "${1%.rpmsave}" != "${1}" ] && continue
102         [ "${1%.rpmorig}" != "${1}" ] && continue
103         [ "${1%.rpmnew}" != "${1}" ] && continue
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 ))
108 done
109 export sscripts
110
111 if test "$previous" != "N" ; then
112         kscripts=0
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
118                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
119                 [ ! -f /var/lock/subsys/$subsys ] && \
120                 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
121                 kscripts=$(( kscripts + 1 ))
122         done
123         export kscripts
124 fi
125
126 if test "$previous" = "N" -a "$runlevel" = "5" ; then
127         export progress=16
128         sscripts=$(( $sscripts + 15 ))
129 else
130         export progress=0
131 fi
132
133 if 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
139 fi
140
141 # set onlcr to avoid staircase effect and do not lock scrolling
142 stty onlcr -ixon 0>&1 2>/dev/null
143
144 # Say something ;)
145 af2=$(termput setaf $CRESMAN)
146 af6=$(termput setaf $CBRACKETS)
147 af7=$(termput op)
148 text="$(termput op)$(nls '%sResource Manager: %sEntering runlevel number' "$af2" "$af7")"
149 text_size="$(nls '%sResource Manager: %sEntering runlevel number' "" "")"
150 resp_size="$(nls 'DONE')"
151 {
152         local _len=${#text_size}
153         local _last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
154         while [ $((_len++)) -lt $_last_col ]; do
155                 text="$text."
156         done
157         echo -n "$text"
158 }
159 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
160
161 # Is there an rc directory for this new runlevel?
162 if [ -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
168                 # Don't run [KS]??foo.{rpmsave,rpmorig,rpmnew} scripts
169                 [ "${1%.rpmsave}" != "${1}" ] && continue
170                 [ "${1%.rpmorig}" != "${1}" ] && continue
171                 [ "${1%.rpmnew}" != "${1}" ] && continue
172
173                 # Check if the subsystem is already up.
174                 subsys=${i#/etc/rc.d/rc$runlevel.d/K??}
175                 [ ! -f /var/lock/subsys/$subsys ] && \
176                 [ ! -f /var/lock/subsys/${subsys}.init ] && continue
177
178                 rc_splash "$i stop"
179
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
189                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
190                 [ "${1%.rpmsave}" != "${1}" ] && continue
191                 [ "${1%.rpmorig}" != "${1}" ] && continue
192                 [ "${1%.rpmnew}" != "${1}" ] && continue
193
194                 # Check if the subsystem is already up.
195                 subsys=${i#/etc/rc.d/rc$runlevel.d/S??}
196                 [ -f /var/lock/subsys/$subsys ] || \
197                 [ -f /var/lock/subsys/${subsys}.init ] && continue
198
199                 # Check if it is managed by upstart
200                 use_upstart && [ -f /etc/init/${subsys}.conf ] && continue
201
202                 # If we're in confirmation mode, get user confirmation
203                 [ -n "$CONFIRM" ] &&
204                 {
205                         confirm $subsys
206                         case $? in
207                           0)
208                                 :
209                                 ;;
210                           2)
211                                 CONFIRM=
212                                 ;;
213                           *)
214                                 continue
215                                 ;;
216                         esac
217                 }
218
219                 rc_splash "$i start"
220                 # Bring the subsystem up.
221                 $i start
222         done
223 fi
224
225 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
226 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
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
241         TMPDIR=/dev/null
242         export TMPDIR
243         if [ "$argv2" != "chroot" ]; then
244                 exec /etc/rc.d/rc.shutdown $runlevel $previous
245         else
246                 exit 0
247         fi
248 else
249         if is_yes "$RUN_LDCONFIG" || [ ! -f /etc/ld.so.cache ] ; then
250                 if [ -x /sbin/ldconfig ]; then
251                         run_cmd "Setting up /etc/ld.so.cache" /sbin/ldconfig -X
252                 fi
253         fi
254 fi
255
256 rc_splash "master"
257
258 # Say something ;)
259 text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
260 text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
261
262 _len=${#text_size}
263 _last_col=$(($INIT_COL+${#resp_size}-${#runlevel}))
264 while [ $((_len++)) -lt $_last_col ]; do
265         text="$text."
266 done
267 echo -n "$text"
268 unset _len _last_col
269
270 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
271 unset af2 af6 af7
272
273 exit 0
This page took 0.054658 seconds and 3 git commands to generate.