]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/rc
- add support for running inside vservers, the diff may seem huge but it's
[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 # Changes:      Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
13 #
14
15 # avoid being interrupted by child or keyboard
16 trap ":" INT QUIT TSTP
17
18 # Save argument
19 argv1="$1"
20 argv2="$2"
21
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)
26           LINES=$1
27         COLUMNS=$2
28 else
29           LINES=
30         COLUMNS=
31 fi
32 export LINES COLUMNS CONSOLE
33   
34 # NLS
35 if [ -f /etc/sysconfig/i18n ]; then
36         . /etc/sysconfig/i18n
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
47 fi
48
49 # Read system config data.
50 if [ -f /etc/sysconfig/system ]; then
51         . /etc/sysconfig/system
52 else
53         RUN_SULOGIN_ON_ERR=yes
54         RUN_ISAPNP=yes
55         PANIC_REBOOT_TIME=0
56         DELAY_LOGIN=yes
57         CLEAN_TMP=no
58         CONSOLE_LOGLEVEL=1
59         SET_SLINKS=yes
60         RUN_LDCONFIG=yes
61 fi
62
63 # Source function library.
64 . /etc/rc.d/init.d/functions
65
66 if [ "$argv2" != "chroot" ]; then
67     # Now find out what the current and what the previous runlevel are.
68     set $(/sbin/runlevel)
69     runlevel=$2
70     previous=$1
71     export runlevel previous
72 fi
73
74 # Get first argument. Set new runlevel to this argument.
75 [ -n "$argv1" ] && runlevel="$argv1"
76
77 # if previous runlevel = current runlevel do nothing
78 [ "$runlevel" = "$previous" ] && exit 0
79
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
82
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
89                 CONSOLE=/dev/tty1
90                 [ -x /usr/bin/chvt ] && /usr/bin/chvt 1 && echo > $CONSOLE
91                 exec 0<> /dev/console 1>&0 2>&0
92         fi
93 else
94         # Serial: columns and lines are not defined
95           LINES=24
96         COLUMNS=80
97 fi
98
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
104                 CONFIRM="yes"
105                 nls "Entering interactive startup"
106         else
107                 CONFIRM=
108                 nls "Entering non-interactive startup"
109         fi
110 fi
111
112 # calculate bootsplash variables
113 sscripts=0
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 ))
123 done
124 export sscripts
125
126 if test "$previous" != "N" ; then
127         kscripts=0
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 ))
137         done
138         export kscripts
139 fi
140
141 if test "$previous" == "N" -a "$runlevel" == "5" ; then
142         export progress=16
143         sscripts=$(( $sscripts + 15 ))
144 else
145         export progress=0
146 fi
147
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
153         fi
154 fi
155
156 # set onlcr to avoid staircase effect and do not lock scrolling
157 stty onlcr -ixon 0>&1 2>/dev/null
158
159 # Say something ;)
160 af2=$(termput setaf $CRESMAN)
161 af6=$(termput setaf $CBRACKETS)
162 af7=$(termput op)
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')"
166 echo -n "$text"
167 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
168 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
169
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
176
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
181
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
186
187                 rc_splash "$i stop"
188                 
189                 # Bring the subsystem down.
190                 $i stop
191         done
192
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
197
198                 # Don't run [KS]??foo.{rpmsave,rpmorig} scripts
199                 [ "${1%.rpmsave}" != "${1}" ] && continue
200                 [ "${1%.rpmorig}" != "${1}" ] && continue
201                 [ "${1%.rpmnew}" != "${1}" ] && continue
202
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
207
208                 # If we're in confirmation mode, get user confirmation
209                 [ -n "$CONFIRM" ]  &&
210                 {
211                         confirm $subsys
212                         case $? in
213                           0)
214                                 :
215                           ;;
216                           2)
217                                 CONFIRM=
218                           ;;
219                           *)
220                                 continue
221                           ;;
222                         esac
223                 }
224
225                 rc_splash "$i start"
226                 # Bring the subsystem up.
227                 $i start
228         done
229 fi
230
231 # if runlevel is 0 (halt) or 6 (reboot) run rc.shutdown
232 if [ "$runlevel" = "0" ] || [ "$runlevel" = "6" ]; then
233         unset LANG
234         unset LC_CTYPE
235         unset LC_NUMERIC
236         unset LC_TIME
237         unset LC_COLLATE
238         unset LC_MONETARY
239         unset LC_MESSAGES
240         unset LC_PAPER
241         unset LC_NAME
242         unset LC_ADDRESS
243         unset LC_TELEPHONE
244         unset LC_MEASUREMENT
245         unset LC_IDENTIFICATION
246         unset LC_ALL
247         TMPDIR=/dev/null
248         export TMPDIR
249         if [ "$argv2" != "chroot" ]; then
250             exec /etc/rc.d/rc.shutdown $runlevel $previous
251         else
252             exit 0
253         fi
254 else
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
258                 fi
259         fi
260 fi
261
262 rc_splash "master"
263
264 # Say something ;)
265 text="$(nls '%sResource Manager: %sRunlevel has been reached' "$af2" "$af7")"
266 text_size="$(nls '%sResource Manager: %sRunlevel has been reached' "" "")"
267 echo -n "$text"
268 awk "BEGIN { for (j=length(\"$text_size\"); j<$INIT_COL+${#resp_size}-${#runlevel}; j++) printf \".\" }"
269 echo "${af6}[${af2} $runlevel ${af6}]${af7}"
270 unset af2 af6 af7
271
272 exit 0
273
274 # This must be last line !
275 # vi:syntax=sh
This page took 0.044091 seconds and 4 git commands to generate.