/[baselayout]/branches/baselayout-1_12/sbin/rc
Gentoo

Contents of /branches/baselayout-1_12/sbin/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (show annotations) (download)
Sun Feb 17 02:24:47 2002 UTC (12 years, 6 months ago) by azarah
Original Path: trunk/sbin/rc
File size: 6642 byte(s)
misc fixes

1 #!/bin/bash
2 # Copyright 1999-2002 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License, v2 or later
4 # $Header$
5
6 #trap ":" INT QUIT TSTP
7 source /etc/init.d/functions.sh
8 umask 022
9
10 try() {
11 eval $*
12 if [ $? -ne 0 ]
13 then
14 echo -e "$ENDCOL$NORMAL[$BAD oops $NORMAL]"
15 echo
16 echo '!!! '"ERROR: the $1 command did not complete successfully."
17 echo '!!! '"(\" ${*} \")"
18 echo '!!! '"Since this is a critical task, startup cannot continue."
19 echo
20 /sbin/sulogin $CONSOLE
21 reboot -f
22 fi
23 }
24
25 #save $1
26 argv1=$1
27
28 #first time boot stuff goes here
29 if [ "$RUNLEVEL" = "S" ] && [ "$argv1" = "boot" ]
30 then
31 echo
32 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"
34 echo
35
36 ebegin "Mounting /proc"
37 try mount -n /proc
38 eend $?
39
40 devfs="yes"
41 for copt in `cat /proc/cmdline`
42 do
43 if [ "${copt%=*}" = "gentoo" ]
44 then
45 parms=${copt##*=}
46 #parse gentoo option
47 if [ "${parms/nodevfs//}" != "${parms}" ]
48 then
49 devfs="no"
50 fi
51 fi
52 done
53
54 #with the new way, /dev can be mounted by the kernel ...
55
56 if [ "$devfs" = "yes" ] && [ ! -e /dev/.devfsd ]
57 then
58 mymounts="`cat /proc/filesystems`"
59 #is devfs support compiled in?
60 if [ "${mymounts/devfs//}" != "${mymounts}" ]
61 then
62 ebegin "Mounting devfs at /dev"; try mount -n -t devfs none /dev; eend
63 else
64 clear
65 echo
66 einfo "The Gentoo Linux system initialization scripts have detected that your"
67 einfo "kernel has been compiled without DEVFS support. Because Gentoo Linux"
68 einfo "has been designed to work with DEVFS, it is required that you compile"
69 einfo "support for it into your kernel. Please read the 'Gentoo Linux from"
70 einfo "source (build) CD Installation Guide' at:"
71 echo
72 einfo " http://www.gentoo.org/doc/build.html"
73 echo
74 einfo "for more information on how to do this."
75 echo
76 read -t 15 -p "(hit Enter to continue or wait 15 seconds...)"
77 fi
78 fi
79
80 #mount shm and do dep scan
81
82 ebegin "Mounting tmpfs at /dev/shm"
83 try mount -n -t tmpfs tmpfs /dev/shm -o rw,mode=0644,size=4m
84 eend
85
86 /etc/init.d/depscan.sh
87
88 if [ "$devfs" = "yes" ] && [ -e /dev/.devfsd ]
89 then
90 ebegin "Starting devfsd"; /sbin/devfsd /dev >/dev/null 2>&1; eend $?
91 fi
92
93 #swap needs to be activated *after* devfs has been mounted and *after*
94 #devfsd has been started, so that the fstab can be properly parsed
95
96 ebegin "Activating swap"
97 swapon -a
98 eend
99
100 #set the console loglevel to 1 for a cleaner boot
101 #the logger should anyhow dump the ring-0 buffer at start to the
102 #logs, and that with dmesg can be used to check for problems
103
104 /bin/dmesg -n 1
105
106 #$BOOT can be used by rc-scripts to test if it is the first time
107 #the 'boot' runlevel is executed
108
109 export BOOT="yes"
110
111 fi #boot ends here
112
113 if [ -z "$argv1" ]
114 then
115 export SOFTLEVEL="`cat /dev/shm/.init.d/softlevel`"
116 else
117 export SOFTLEVEL=$argv1
118 fi
119 svcdir=/dev/shm/.init.d
120
121 if [ "$SOFTLEVEL" = "reboot" ] || [ "$SOFTLEVEL" = "shutdown" ]
122 then
123 myscripts=""
124 elif [ ! -d /etc/runlevels/${SOFTLEVEL} ]
125 then
126 echo "runlevel ${SOFTLEVEL} does not exist; exiting."
127 exit 1
128 else
129 myscripts=""
130 if [ "$SOFTLEVEL" != "boot" ]
131 then
132 #normal runlevels *include* boot scripts
133 mylevels="/etc/runlevels/${SOFTLEVEL}/* /etc/runlevels/boot/*"
134 else
135 #non-normal runlevels don't include boot scripts as default
136 mylevels="/etc/runlevels/${SOFTLEVEL}/*"
137 fi
138 for x in $mylevels
139 do
140 if [ -L $x ]
141 then
142 myscripts="$myscripts ${x##*/}"
143 fi
144 done
145 fi
146
147 #the softscripts dir contains all scripts that belong to the
148 #runlevel specified in ${svcdir}/softlevel
149 #it needs to be a new directory, else when stopping the services
150 #and the old directory is not intact, things get broken
151
152 install -d -m0755 ${svcdir}/softscripts.new
153
154 for x in $myscripts
155 do
156 if [ ! -e /etc/init.d/${x} ]
157 then
158 echo "skipping, /etc/init.d/${x} missing"
159 continue
160 fi
161 #the -f eliminates a warning if the symlink already exists,
162 #which can happen if a service is in both the boot level and
163 #the current "normal" runlevel
164 ln -sf /etc/init.d/${x} ${svcdir}/softscripts.new/${x}
165 done
166
167 dep_stop() {
168 local x
169 local needsme
170 local myservice
171 local depservice
172 [ ! -L ${1} ] && continue
173 if [ ! -e ${1} ]
174 then
175 #remove dud symlinks
176 rm ${1}
177 continue
178 fi
179 myservice=${1##*/}
180
181 if [ ! -L ${svcdir}/softscripts.new/${myservice} ]
182 then
183 #candidate for zapping
184
185 #should not work for 'use'
186 if [ ! -d ${svcdir}/need/${myservice} ] #&& [ ! -d ${svcdir}/use/${myservice} ]
187 then
188 #nothing depends on me
189 if [ -L ${svcdir}/started/${myservice} ]
190 then
191 ${1} stop
192 fi
193 else
194 #something may depend on me
195 needsme=0
196 for mytype in need #use
197 do
198 for dep in ${svcdir}/${mytype}/${myservice}/*
199 do
200 if [ -e ${dep} ] && [ -L /${svcdir}/softscripts.new/${dep##*/} ]
201 then
202 #this dep is valid
203 needsme=1
204 break
205 fi
206 done
207 done
208 if [ $needsme -eq 0 ]
209 then
210 if [ -L ${svcdir}/started/${myservice} ]
211 then
212 ${1} stop
213 fi
214 fi
215 fi
216 fi
217 }
218
219 #stop services
220 for i in ${svcdir}/started/*
221 do
222 dep_stop $i
223 done
224
225 # Only change softlevel AFTER all the services have been stopped,
226 # else they will not get the depend's right (wrong SOFTLEVEL)
227
228 echo $SOFTLEVEL > /dev/shm/.init.d/softlevel
229
230 if [ "$SOFTLEVEL" = "reboot" ] || [ "$SOFTLEVEL" = "shutdown" ]
231 then
232 source /etc/init.d/functions.sh
233 source /etc/init.d/halt.sh
234 if [ "$SOFTLEVEL" = "reboot" ]
235 then
236 source /etc/init.d/reboot.sh
237 else
238 source /etc/init.d/shutdown.sh
239 fi
240 fi
241
242 #move the old softscritps directory to a different one
243 #and make the new softscripts directory the current
244
245 mv ${svcdir}/softscripts ${svcdir}/softscripts.old
246 mv ${svcdir}/softscripts.new/ ${svcdir}/softscripts
247
248 dep_start() {
249 local x
250 local myservice
251 local depservice
252 if [ ! -L $1 ]
253 then
254 continue
255 fi
256 #only start a script if it isn't already running
257 myservice=${1##*/}
258 if [ ! -L ${svcdir}/started/${myservice} ]
259 then
260 $1 start
261 fi
262 }
263 #start scripts
264 for i in ${svcdir}/softscripts/*
265 do
266 dep_start $i
267 done
268
269 #clean the old runlevel
270 rm -rf ${svcdir}/softscripts.old
271
272 #depends gets newked, so update them
273 #(this problem should be solved now, but i think it will be a good idea
274 # to recreate the deps after a change in runlevel)
275
276 /etc/init.d/depscan.sh >/dev/null 2>/dev/null
277
278 #we want devfsd running after a change of runlevel (this is mostly if we return
279 #from runlevel 'single')
280 if [ "`cat /proc/mounts | grep '/dev devfs'`" ] && [ ! "`ps -A |grep devfsd`" ]
281 then
282 /sbin/devfsd /dev >/dev/null 2>&1
283 fi
284
285 #if we were in the boot runlevel, it is done now ...
286 [ -n "$BOOT" ] && unset BOOT

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20