/[baselayout]/trunk/sbin/rc
Gentoo

Diff of /trunk/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 143 Revision 144
1#!/bin/bash 1#!/bin/bash
2# Copyright 1999-2002 Gentoo Technologies, Inc. 2# Copyright 1999-2002 Gentoo Technologies, Inc.
3# Distributed under the terms of the GNU General Public License, v2 or later 3# Distributed under the terms of the GNU General Public License, v2 or later
4# $Header$ 4# $Header$
5 5
6
6#trap ":" INT QUIT TSTP 7trap ":" INT QUIT TSTP
7source /etc/init.d/functions.sh 8source /etc/init.d/functions.sh
8umask 022 9umask 022
9 10
10try() { 11try() {
11 eval $* >/dev/null 2>&1 12 local retval=0
12 if [ $? -ne 0 ] 13 #this works fine in test, but real life booting, fails for mounting /proc
14 #for instance, if we only check $?, thus we need to [ -n "${errstr}" ]
15 #as well
16 local errstr="$((eval $*) 2>&1 >/dev/null)"
17 retval=$?
18 if [ "${retval}" -ne 0 ] || [ -n "${errstr}" ]
13 then 19 then
14 echo -e "$ENDCOL$NORMAL[$BAD oops $NORMAL]" 20 echo -e "${ENDCOL}${NORMAL}[${BAD} oops ${NORMAL}]"
15 echo 21 echo
16 echo '!!! '"ERROR: the $1 command did not complete successfully." 22 eerror "The \"${1}\" command failed with error:"
17 echo '!!! '"(\" ${*} \")" 23 echo
24 echo "${errstr#*: }"
25 echo
18 echo '!!! '"Since this is a critical task, startup cannot continue." 26 eerror "Since this is a critical task, startup cannot continue."
19 echo 27 echo
20 /sbin/sulogin $CONSOLE 28 /sbin/sulogin ${CONSOLE}
21 reboot -f 29 /sbin/reboot -f
22 fi 30 fi
31 return ${retval}
23} 32}
24 33
25#save $1 34#save $1
26argv1=$1 35argv1="${1}"
27 36
28#first time boot stuff goes here 37#first time boot stuff goes here
29if [ "$RUNLEVEL" = "S" ] && [ "$argv1" = "boot" ] 38if [ "${RUNLEVEL}" = "S" ] && [ "${argv1}" = "boot" ]
30then 39then
40 #setup initial $PATH just in case
41 PATH="/bin:/sbin:/usr/bin:/usr/sbin:${PATH}"
42
31 echo 43 echo
32 echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; \e[34;01mhttp://www.gentoo.org${NORMAL}" 44 echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; \e[34;01mhttp://www.gentoo.org${NORMAL}"
33 echo -e " Copyright 2001 Gentoo Technologies, Inc.; Distributed under the GPL" 45 echo -e " Copyright 2001 Gentoo Technologies, Inc.; Distributed under the GPL"
34 echo 46 echo
35 47
36 ebegin "Mounting /proc" 48 ebegin "Mounting /proc"; \
37 try mount -n /proc 49 try mount -n /proc; \
38 eend $? 50 eend $?
39 51
52 #check if the user disabled devfs
40 devfs="yes" 53 devfs="yes"
41 get_bootparam "nodevfs" 54 get_bootparam "nodevfs"
42 if [ $? -eq 0 ] 55 if [ "$?" -eq 0 ]
43 then 56 then
44 devfs="no" 57 devfs="no"
45 fi 58 fi
46 59
47 #fix wierd bug where there is a /dev/.devfsd in a unmounted /dev 60 #fix wierd bug where there is a /dev/.devfsd in a unmounted /dev
48 mymounts="`cat /proc/mounts`" 61 mymounts="$(cat /proc/mounts)"
49 if [ -e /dev/.devfsd ] && [ "${mymounts/devfs//}" = "${mymounts}" ] 62 if [ -e /dev/.devfsd ] && [ "${mymounts/devfs//}" = "${mymounts}" ]
50 then 63 then
51 rm -f /dev/.devfsd >/dev/null 2>&1 64 rm -f /dev/.devfsd &>/dev/null
52 fi 65 fi
53 66
54 #with the new way, /dev can be mounted by the kernel ... 67 #with the new way, /dev can be mounted by the kernel ...
55 if [ "$devfs" = "yes" ] && [ ! -e /dev/.devfsd ] 68 if [ "${devfs}" = "yes" ] && [ ! -e /dev/.devfsd ]
56 then 69 then
57 mymounts="`cat /proc/filesystems`" 70 mymounts="$(cat /proc/filesystems)"
58 #is devfs support compiled in? 71 #is devfs support compiled in?
59 if [ "${mymounts/devfs//}" != "${mymounts}" ] 72 if [ "${mymounts/devfs//}" != "${mymounts}" ]
60 then 73 then
61 ebegin "Mounting devfs at /dev"; try mount -n -t devfs none /dev; eend 74 ebegin "Mounting devfs at /dev"; \
75 try mount -n -t devfs none /dev; \
76 eend $?
62 else 77 else
63 clear 78 clear
64 echo 79 echo
65 einfo "The Gentoo Linux system initialization scripts have detected that your" 80 einfo "The Gentoo Linux system initialization scripts have detected that your"
66 einfo "kernel has been compiled without DEVFS support. Because Gentoo Linux" 81 einfo "kernel has been compiled without DEVFS support. Because Gentoo Linux"
75 read -t 15 -p "(hit Enter to continue or wait 15 seconds...)" 90 read -t 15 -p "(hit Enter to continue or wait 15 seconds...)"
76 fi 91 fi
77 fi 92 fi
78 93
79 # need devfsd running now so that /dev/ram0 exists if we need it 94 # need devfsd running now so that /dev/ram0 exists if we need it
80 mymounts="`cat /proc/mounts`" 95 mymounts="$(cat /proc/mounts)"
81 if [ "$devfs" = "yes" ] && [ -e /dev/.devfsd ] && \ 96 if [ "${devfs}" = "yes" ] && [ -e /dev/.devfsd ] && \
82 [ "${mymounts/devfs//}" != "${mymounts}" ] 97 [ "${mymounts/devfs//}" != "${mymounts}" ]
83 then 98 then
84 ebegin "Starting devfsd"; /sbin/devfsd /dev >/dev/null 2>&1; eend $? 99 ebegin "Starting devfsd"
100 /sbin/devfsd /dev &>/dev/null
101 eend $?
85 fi 102 fi
86 103
87 #mount either a ramdisk or tmpfs and do dep scan 104 #mount either a ramdisk or tmpfs and do dep scan
88 105
106 #should we use tmpfs or a ramdisk ?
89 tmpfs="yes" 107 tmpfs="yes"
90 get_bootparam "notmpfs" 108 get_bootparam "notmpfs"
91 if [ $? -eq 0 ] 109 if [ "$?" -eq 0 ]
92 then 110 then
93 tmpfs="no" 111 tmpfs="no"
94 fi 112 fi
95 113
96 if [ ! -d $svcdir ] 114 if [ ! -d ${svcdir} ]
97 then 115 then
98 mkdir -p $svcdir >/dev/null 2>&1 116 echo
117 eerror "For Gentoo Linux to function properly, \"${svcdir}\" need to exist."
118 eerror "Please mount your root partition read/write, and execute:"
119 echo
120 eerror " # mkdir -p ${svcdir}"
121 echo
122 echo
123 /sbin/sulogin ${CONSOLE}
124 mount -a -o remount,ro &>/dev/null
125 /sbin/reboot -f
99 fi 126 fi
100 127
101 if [ "$tmpfs" = "yes" ] ; then 128 if [ "${tmpfs}" = "yes" ]
129 then
102 ebegin "Mounting tmpfs at ${svcdir}" 130 ebegin "Mounting tmpfs at ${svcdir}"; \
103 try mount -n -t tmpfs tmpfs ${svcdir} -o rw,mode=0644,size=${svcsize}k 131 try mount -n -t tmpfs tmpfs ${svcdir} \
132 -o rw,mode=0644,size=${svcsize}k; \
104 eend 0 133 eend 0
105 else 134 else
106 ebegin "Mounting ramdisk 0 at ${svcdir}" 135 ebegin "Mounting ramdisk 0 at ${svcdir}"; \
107 try dd if=/dev/zero of=/dev/ram0 bs=1k count=$svcsize 136 try dd if=/dev/zero of=/dev/ram0 bs=1k count=${svcsize}; \
108 try mke2fs -vm0 /dev/ram0 $svcsize 137 try /sbin/mke2fs -vm0 /dev/ram0 ${svcsize}; \
109 try mount -n -t ext2 /dev/ram0 ${svcdir} -o rw 138 try mount -n -t ext2 /dev/ram0 ${svcdir} -o rw; \
110 eend 0 139 eend 0
111 fi 140 fi
112 141
142 ebegin "Caching service dependencies"; \
113 /etc/init.d/depscan.sh 143 try /etc/init.d/depscan.sh; \
144 eend $?
114 145
115 #swap needs to be activated *after* devfs has been mounted and *after* 146 #swap needs to be activated *after* devfs has been mounted and *after*
116 #devfsd has been started, so that the fstab can be properly parsed 147 #devfsd has been started, so that the fstab can be properly parsed
117 148
118 ebegin "Activating swap" 149 ebegin "Activating swap"
119 swapon -a >/dev/null 2>&1 150 /sbin/swapon -a &>/dev/null
120 eend 151 eend 0
121 152
122 #set the console loglevel to 1 for a cleaner boot 153 #set the console loglevel to 1 for a cleaner boot
123 #the logger should anyhow dump the ring-0 buffer at start to the 154 #the logger should anyhow dump the ring-0 buffer at start to the
124 #logs, and that with dmesg can be used to check for problems 155 #logs, and that with dmesg can be used to check for problems
125 156
130 161
131 export BOOT="yes" 162 export BOOT="yes"
132 163
133fi #boot ends here 164fi #boot ends here
134 165
135if [ -z "$argv1" ] 166if [ -z "${argv1}" ]
136then 167then
137 if [ -e ${svcdir}/softlevel ] 168 if [ -e ${svcdir}/softlevel ]
138 then 169 then
139 export SOFTLEVEL="`cat ${svcdir}/softlevel`" 170 export SOFTLEVEL="$(cat ${svcdir}/softlevel)"
140 else 171 else
141 export SOFTLEVEL="boot" 172 export SOFTLEVEL="boot"
142 fi 173 fi
143else 174else
144 export SOFTLEVEL="$argv1" 175 export SOFTLEVEL="${argv1}"
145fi 176fi
146 177
147#for keeping a list of services that fails during boot/halt 178#for keeping a list of services that fails during boot/halt
148if [ ! -d ${svcdir}/fails ] 179if [ ! -d ${svcdir}/fails ]
149then 180then
150 mkdir -p ${svcdir}/fails >/dev/null 2>&1 181 install -d -m0755 ${svcdir}/fails
151else 182else
152 rm -rf ${svcdir}/fails/* >/dev/null 2>&1 183 rm -rf ${svcdir}/fails/*
153fi 184fi
154 185
155if [ "$SOFTLEVEL" = "reboot" ] || [ "$SOFTLEVEL" = "shutdown" ] 186if [ "${SOFTLEVEL}" = "reboot" ] || [ "${SOFTLEVEL}" = "shutdown" ]
156then 187then
157 myscripts="" 188 myscripts=""
158elif [ ! -d /etc/runlevels/${SOFTLEVEL} ] 189elif [ ! -d /etc/runlevels/${SOFTLEVEL} ]
159then 190then
160 echo "runlevel ${SOFTLEVEL} does not exist; exiting." 191 eerror "ERROR: runlevel ${SOFTLEVEL} does not exist; exiting..."
161 exit 1 192 exit 1
162else 193else
163 myscripts="" 194 myscripts=""
164 if [ "$SOFTLEVEL" != "boot" ] 195 if [ "${SOFTLEVEL}" != "boot" ]
165 then 196 then
166 #normal runlevels *include* boot scripts 197 #normal runlevels *include* boot scripts
167 mylevels="/etc/runlevels/${SOFTLEVEL}/* /etc/runlevels/boot/*" 198 mylevels="$(dolisting /etc/runlevels/${SOFTLEVEL}/)"
199 mylevels="${mylevels} $(dolisting /etc/runlevels/boot/)"
168 else 200 else
169 #non-normal runlevels don't include boot scripts as default 201 #non-normal runlevels don't include boot scripts as default
170 mylevels="/etc/runlevels/${SOFTLEVEL}/*" 202 mylevels="$(dolisting /etc/runlevels/${SOFTLEVEL}/)"
171 fi 203 fi
172 for x in $mylevels 204 for x in ${mylevels}
173 do 205 do
174 if [ -L $x ] 206 if [ -L ${x} ]
175 then 207 then
176 myscripts="$myscripts ${x##*/}" 208 myscripts="${myscripts} ${x##*/}"
177 fi 209 fi
178 done 210 done
179fi 211fi
180 212
181#the softscripts dir contains all scripts that belong to the 213#the softscripts dir contains all scripts that belong to the
183#it needs to be a new directory, else when stopping the services 215#it needs to be a new directory, else when stopping the services
184#and the old directory is not intact, things get broken 216#and the old directory is not intact, things get broken
185 217
186install -d -m0755 ${svcdir}/softscripts.new 218install -d -m0755 ${svcdir}/softscripts.new
187 219
188for x in $myscripts 220for x in ${myscripts}
189do 221do
190 if [ ! -e /etc/init.d/${x} ] 222 if [ ! -e /etc/init.d/${x} ]
191 then 223 then
192 echo "skipping, /etc/init.d/${x} missing" 224 ewarn "WARNING: /etc/init.d/${x} missing; skipping..."
193 continue 225 continue
194 fi 226 fi
195 #the -f eliminates a warning if the symlink already exists, 227 #the -f eliminates a warning if the symlink already exists,
196 #which can happen if a service is in both the boot level and 228 #which can happen if a service is in both the boot level and
197 #the current "normal" runlevel 229 #the current "normal" runlevel
208 then 240 then
209 #remove dud symlinks 241 #remove dud symlinks
210 rm ${1} 242 rm ${1}
211 continue 243 continue
212 fi 244 fi
213 myservice=${1##*/} 245 myservice="${1##*/}"
214 246
215 if [ ! -L ${svcdir}/softscripts.new/${myservice} ] 247 if [ ! -L ${svcdir}/softscripts.new/${myservice} ]
216 then 248 then
217 #candidate for zapping 249 #candidate for zapping
218 250
225 ${1} stop 257 ${1} stop
226 fi 258 fi
227 else 259 else
228 #something may depend on me 260 #something may depend on me
229 needsme=0 261 needsme=0
230 for mytype in need #use 262 for mytype in need
231 do 263 do
232 for dep in ${svcdir}/${mytype}/${myservice}/* 264 for dep in $(dolisting ${svcdir}/${mytype}/${myservice}/)
233 do 265 do
234 if [ -e ${dep} ] && [ -L /${svcdir}/softscripts.new/${dep##*/} ] 266 if [ -L ${svcdir}/softscripts.new/${dep##*/} ] && \
267 [ -e ${dep} ]
235 then 268 then
236 #this dep is valid 269 #this dep is valid
237 needsme=1 270 needsme=1
238 break 271 break
239 fi 272 fi
240 done 273 done
241 done 274 done
242 if [ $needsme -eq 0 ] 275 if [ "${needsme}" -eq 0 ]
243 then 276 then
244 if [ -L ${svcdir}/started/${myservice} ] 277 if [ -L ${svcdir}/started/${myservice} ]
245 then 278 then
246 ${1} stop 279 ${1} stop
247 fi 280 fi
249 fi 282 fi
250 fi 283 fi
251} 284}
252 285
253#stop services 286#stop services
254for i in ${svcdir}/started/* 287for i in $(dolisting ${svcdir}/started/)
255do 288do
256 dep_stop $i 289 dep_stop ${i}
257done 290done
258 291
259# Only change softlevel AFTER all the services have been stopped, 292# Only change softlevel AFTER all the services have been stopped,
260# else they will not get the depend's right (wrong SOFTLEVEL) 293# else they will not get the depend's right (wrong SOFTLEVEL)
261 294
262echo "$SOFTLEVEL" > ${svcdir}/softlevel 295echo "${SOFTLEVEL}" > ${svcdir}/softlevel
263 296
264if [ "$SOFTLEVEL" = "reboot" ] || [ "$SOFTLEVEL" = "shutdown" ] 297if [ "${SOFTLEVEL}" = "reboot" ] || [ "${SOFTLEVEL}" = "shutdown" ]
265then 298then
266 source /etc/init.d/functions.sh 299 source /etc/init.d/functions.sh
267 source /etc/init.d/halt.sh 300 source /etc/init.d/halt.sh
268 if [ "$SOFTLEVEL" = "reboot" ] 301 if [ "${SOFTLEVEL}" = "reboot" ]
269 then 302 then
270 source /etc/init.d/reboot.sh 303 source /etc/init.d/reboot.sh
271 else 304 else
272 source /etc/init.d/shutdown.sh 305 source /etc/init.d/shutdown.sh
273 fi 306 fi
274fi 307fi
275 308
276#move the old softscritps directory to a different one 309#move the old softscritps directory to a different one
277#and make the new softscripts directory the current 310#and make the new softscripts directory the current
278 311
279mv ${svcdir}/softscripts ${svcdir}/softscripts.old >/dev/null 2>&1 312mv ${svcdir}/softscripts ${svcdir}/softscripts.old &>/dev/null
280mv ${svcdir}/softscripts.new/ ${svcdir}/softscripts >/dev/null 2>&1 313mv ${svcdir}/softscripts.new ${svcdir}/softscripts &>/dev/null
281 314
282dep_start() { 315dep_start() {
283 local x="" 316 local x=""
284 local myservice="" 317 local myservice=""
285 local depservice="" 318 local depservice=""
286 if [ ! -L $1 ] 319 if [ ! -L ${1} ]
287 then 320 then
288 continue 321 continue
289 fi 322 fi
290 #only start a script if it isn't already running 323 #only start a script if it isn't already running
291 myservice=${1##*/} 324 myservice="${1##*/}"
292 if [ ! -L ${svcdir}/started/${myservice} ] 325 if [ ! -L ${svcdir}/started/${myservice} ]
293 then 326 then
294 $1 start 327 ${1} start
295 fi 328 fi
296} 329}
297 330
298#start scripts 331#start scripts
299for i in ${svcdir}/softscripts/* 332for i in $(dolisting ${svcdir}/softscripts/)
300do 333do
301 dep_start $i 334 dep_start ${i}
302done 335done
303 336
304#clean the old runlevel 337#clean the old runlevel
305rm -rf ${svcdir}/softscripts.old >/dev/null 2>&1 338rm -rf ${svcdir}/softscripts.old &>/dev/null
306 339
307#depends gets newked, so update them 340#depends gets newked, so update them
308#(this problem should be solved now, but i think it will be a good idea 341#(this problem should be solved now, but i think it will be a good idea
309# to recreate the deps after a change in runlevel) 342# to recreate the deps after a change in runlevel)
310 343
311/etc/init.d/depscan.sh >/dev/null 2>&1 344#/etc/init.d/depscan.sh &>/dev/null
312 345
313#we want devfsd running after a change of runlevel (this is mostly if we return 346#we want devfsd running after a change of runlevel (this is mostly if we return
314#from runlevel 'single') 347#from runlevel 'single')
315if [ "`cat /proc/mounts | grep -e '/dev devfs'`" ] && [ ! "`ps -A | grep devfsd`" ] 348if [ -z "$(ps -A | grep devfsd)" ] && \
349 [ -n "$(cat mounts | grep -e '/dev devfs')" ]
316then 350then
317 /sbin/devfsd /dev >/dev/null 2>&1 351 /sbin/devfsd /dev &>/dev/null
318fi 352fi
319 353
320#runlevel end, so clear stale fail list 354#runlevel end, so clear stale fail list
321rm -rf ${svcdir}/fails >/dev/null 2>&1 355rm -rf ${svcdir}/fails &>/dev/null
322 356
323#if we were in the boot runlevel, it is done now ... 357#if we were in the boot runlevel, it is done now ...
324[ -n "$BOOT" ] && unset BOOT 358[ -n "${BOOT}" ] && unset BOOT
325 359
360# vim:ts=4

Legend:
Removed from v.143  
changed lines
  Added in v.144

  ViewVC Help
Powered by ViewVC 1.1.20