Annotation of /trunk/magellan-initscripts/rc/rc
Parent Directory | Revision Log
Revision 345 -
(hide annotations)
(download)
Sat Mar 4 18:55:54 2006 UTC (18 years, 6 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 10282 byte(s)
Sat Mar 4 18:55:54 2006 UTC (18 years, 6 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 10282 byte(s)
cleanups and updated copyright to 2006
1 | niro | 2 | #!/bin/bash |
2 | niro | 345 | # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.8 2006-03-04 18:55:54 niro Exp $ |
3 | niro | 2 | |
4 | source /etc/sysconfig/rc | ||
5 | source $rc_functions | ||
6 | |||
7 | niro | 50 | # get mage version |
8 | MAGEVER="$(< /etc/mageversion)" | ||
9 | niro | 2 | |
10 | niro | 150 | # source kernel config if exists |
11 | niro | 2 | [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel |
12 | |||
13 | niro | 319 | udev_version() |
14 | { | ||
15 | local version=0 | ||
16 | |||
17 | if [[ -x /sbin/udev ]] | ||
18 | then | ||
19 | version=$(/sbin/udev -V) | ||
20 | # We need it without a leading '0', else bash do the wrong thing | ||
21 | version=${version##0} | ||
22 | # Older udev's will print nothing | ||
23 | [[ -z ${version} ]] && version=0 | ||
24 | fi | ||
25 | |||
26 | echo "${version}" | ||
27 | } | ||
28 | |||
29 | niro | 318 | # this works only for 2.6.15 kernels and greater |
30 | trigger_events() | ||
31 | { | ||
32 | local list="" | ||
33 | local i | ||
34 | local first | ||
35 | local last | ||
36 | local default | ||
37 | |||
38 | # if you want real hotplug (with all modules being loaded for all | ||
39 | # devices in the system), uncomment out the next line. | ||
40 | #list="$list $(echo /sys/bus/*/devices/*/uevent)" | ||
41 | list="${list} $(echo /sys/class/*/*/uevent)" | ||
42 | list="${list} $(echo /sys/block/*/uevent /sys/block/*/*/uevent)" | ||
43 | for i in ${list} | ||
44 | do | ||
45 | case "${i}" in | ||
46 | */device/uevent) | ||
47 | # skip followed device symlinks | ||
48 | continue | ||
49 | ;; | ||
50 | */class/mem/*|*/class/tty/*) | ||
51 | first="${first} ${i}" | ||
52 | ;; | ||
53 | */block/md*) | ||
54 | last="${last} ${i}" | ||
55 | ;; | ||
56 | */*) | ||
57 | default="${default} ${i}" | ||
58 | ;; | ||
59 | esac | ||
60 | done | ||
61 | |||
62 | # trigger the sorted events | ||
63 | for i in ${first} ${default} ${last} | ||
64 | do | ||
65 | echo "add" > "${i}" | ||
66 | done | ||
67 | } | ||
68 | |||
69 | niro | 319 | populate_udev() |
70 | { | ||
71 | niro | 318 | local loop |
72 | |||
73 | # populate /dev with devices already found by the kernel | ||
74 | if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] | ||
75 | then | ||
76 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." | ||
77 | trigger_events | ||
78 | evaluate_retval | ||
79 | else | ||
80 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices with udevstart ..." | ||
81 | niro | 2 | /sbin/udevstart |
82 | niro | 318 | evaluate_retval |
83 | fi | ||
84 | niro | 2 | |
85 | niro | 318 | # loop until everything is finished |
86 | # there's gotta be a better way... | ||
87 | echo -e ${COLOREDSTAR}" Letting udev process events ..." | ||
88 | loop=0 | ||
89 | while test -d /dev/.udev/queue | ||
90 | do | ||
91 | sleep 0.1; | ||
92 | test "${loop}" -gt 300 && break | ||
93 | loop=$((${loop} + 1)) | ||
94 | done | ||
95 | evaluate_retval | ||
96 | |||
97 | return 0 | ||
98 | } | ||
99 | |||
100 | niro | 319 | seed_dev() |
101 | { | ||
102 | niro | 318 | # seed /dev with some things that we know we need |
103 | echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." | ||
104 | ( | ||
105 | # copy over any persistant things | ||
106 | cp --preserve=all --recursive --update /lib/udev/devices/* /dev | ||
107 | |||
108 | niro | 150 | # not provided by sysfs but needed |
109 | niro | 2 | ln -snf /proc/self/fd /dev/fd |
110 | ln -snf fd/0 /dev/stdin | ||
111 | ln -snf fd/1 /dev/stdout | ||
112 | ln -snf fd/2 /dev/stderr | ||
113 | niro | 318 | [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
114 | |||
115 | niro | 150 | # create problematic directories |
116 | niro | 2 | mkdir -p /dev/{pts,shm} |
117 | niro | 318 | ) |
118 | evaluate_retval | ||
119 | } | ||
120 | niro | 2 | |
121 | trap "" INT QUIT TSTP | ||
122 | |||
123 | [ "$1" != "" ] && runlevel=$1 | ||
124 | |||
125 | niro | 150 | if [[ $runlevel = sysinit ]] |
126 | niro | 2 | then |
127 | echo | ||
128 | echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" | ||
129 | niro | 345 | echo -e "Copyright 2001-2006 Niels Rogalla; http://magellan-linux.net" |
130 | niro | 2 | echo |
131 | |||
132 | niro | 150 | # mount proc filesystem, needed for bootsplash; |
133 | # no use of '/etc/rc.d/init.d/mountproc' anymore | ||
134 | niro | 2 | if [ ! -e /proc/mounts ] |
135 | then | ||
136 | echo -e ${COLOREDSTAR}"Mounting proc file system ..." | ||
137 | mount -n /proc | ||
138 | evaluate_retval | ||
139 | fi | ||
140 | |||
141 | niro | 150 | # set default verbose level for kernel messages |
142 | niro | 2 | [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
143 | echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk | ||
144 | |||
145 | niro | 150 | # mount sys file system before udev or devfs (kernel-2.6) |
146 | if [[ $(kernel_major_version) = 2.6 ]] | ||
147 | niro | 2 | then |
148 | if [ -d /sys ] | ||
149 | then | ||
150 | echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." | ||
151 | niro | 150 | mount -n -t sysfs sysfs /sys |
152 | niro | 2 | evaluate_retval |
153 | else | ||
154 | echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." | ||
155 | echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." | ||
156 | echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." | ||
157 | fi | ||
158 | fi | ||
159 | |||
160 | ## load devfs ## | ||
161 | niro | 150 | # load devfs only with a 2.4 kernel or its really wanted with a 2.6 |
162 | if [[ $(kernel_major_version) = 2.4 ]] || [[ ${RC_USED_DEV} = devfs ]] | ||
163 | niro | 2 | then |
164 | # start devfsd daemon, needed for bootsplash; | ||
165 | # no use of '/etc/rc.d/init.d/devfs' anymore | ||
166 | # check if devfs was mounted by the kernel, | ||
167 | # if not mount it (mbuild_livecd needs this one) | ||
168 | if [ ! -e /dev/.devfsd ] | ||
169 | then | ||
170 | echo -e ${COLOREDSTAR}"Mounting devfs file system ..." | ||
171 | niro | 150 | mount -n -t devfs devfs /dev |
172 | niro | 2 | evaluate_retval |
173 | fi | ||
174 | |||
175 | if [ -e /dev/.devfsd ] | ||
176 | then | ||
177 | echo -e ${COLOREDSTAR}"Starting devfsd ..." | ||
178 | ## directory /lib/dev-state !must! exists ## | ||
179 | /sbin/devfsd /dev &> /dev/null | ||
180 | evaluate_retval | ||
181 | else | ||
182 | echo -e ${COLRED}"No devfs filesystem found ..." | ||
183 | echo -e ${COLYELLOW}"Your Kernel doesn't support the devfs filesystem." | ||
184 | echo -e ${COLYELLOW}"Devfs is necessary to run Magellan-Linux." | ||
185 | echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." | ||
186 | echo | ||
187 | echo -e ${COLYELLOW}"Press any key to shutdown the system safely ..." | ||
188 | read | ||
189 | $rc_base/init.d/halt | ||
190 | fi | ||
191 | fi | ||
192 | |||
193 | #### load udev #### | ||
194 | niro | 150 | # load udev only with a 2.6 kernel |
195 | if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]] | ||
196 | niro | 2 | then |
197 | niro | 150 | # create a ramdisk for populating udev |
198 | echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." | ||
199 | # tmpfs was suggested by Greg Kroah-Hartman | ||
200 | # many video drivers needed exec access | ||
201 | mount -n -t ramfs udev /dev -o exec,nosuid,mode=0755 | ||
202 | niro | 2 | evaluate_retval |
203 | |||
204 | niro | 150 | # if a device tarball exists load it and if it is activated |
205 | niro | 2 | echo -e ${COLOREDSTAR}"Configurating system to use udev ..." |
206 | niro | 150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] |
207 | niro | 2 | then |
208 | niro | 318 | echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
209 | niro | 2 | tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev |
210 | evaluate_retval | ||
211 | fi | ||
212 | |||
213 | niro | 318 | # other eeded device nodes with udev |
214 | seed_dev | ||
215 | niro | 2 | |
216 | niro | 318 | if [ -e /proc/sys/kernel/hotplug ] |
217 | niro | 2 | then |
218 | niro | 318 | if [ "$(kernel_version | sed 's:\.::g')" -gt "2614" ] |
219 | then | ||
220 | echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." | ||
221 | echo "" > /proc/sys/kernel/hotplug | ||
222 | evaluate_retval | ||
223 | elif [[ $(udev_version) -ge "48" ]] | ||
224 | then | ||
225 | echo -e ${COLOREDSTAR}" Setting /sbin/udevsend as hotplug agent ..." | ||
226 | echo "/sbin/udevsend" > /proc/sys/kernel/hotplug | ||
227 | evaluate_retval | ||
228 | elif [[ -x /sbin/hotplug ]] | ||
229 | then | ||
230 | echo -e ${COLOREDSTAR}" Using /sbin/hotplug as hotplug agent ..." | ||
231 | print_status success | ||
232 | else | ||
233 | echo -e ${COLOREDSTAR}" Setting /sbin/udev as hotplug agent ..." | ||
234 | echo "/sbin/udev" > /proc/sys/kernel/hotplug | ||
235 | evaluate_retval | ||
236 | fi | ||
237 | niro | 2 | else |
238 | echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" | ||
239 | niro | 318 | print_status failure |
240 | niro | 2 | fi |
241 | niro | 318 | |
242 | echo -e ${COLOREDSTAR}" Starting udevd daemon ..." | ||
243 | /sbin/udevd --daemon | ||
244 | niro | 2 | evaluate_retval |
245 | niro | 318 | |
246 | populate_udev | ||
247 | |||
248 | # create nodes that udev can't | ||
249 | echo -e ${COLOREDSTAR}" Finializing udev configuration ..." | ||
250 | [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null | ||
251 | [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null | ||
252 | [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null | ||
253 | print_status success | ||
254 | |||
255 | # same thing as /dev/.devfsd | ||
256 | touch /dev/.udev | ||
257 | niro | 2 | fi |
258 | |||
259 | ## load devpts ## | ||
260 | # devfs/udev with 2.6 has no ptys, so devpts is also needed | ||
261 | niro | 150 | if [[ $(kernel_major_version) = 2.6 ]] |
262 | niro | 2 | then |
263 | # check if we really have devpts support | ||
264 | niro | 150 | if kernel_supports_fs devpts |
265 | niro | 2 | then |
266 | # /dev/pts maybe not exists. | ||
267 | # We only create this directory only if devfs was mounted, | ||
268 | # or it will fail as / is still mounted readonly | ||
269 | niro | 150 | # udev has this dir already, only a sanity check for devfs |
270 | if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs | ||
271 | niro | 2 | then |
272 | mkdir -p /dev/pts &> /dev/null || \ | ||
273 | echo "Could not create /dev/pts !" | ||
274 | fi | ||
275 | niro | 71 | |
276 | niro | 150 | # now mount devpts |
277 | niro | 2 | if [ -d /dev/pts ] |
278 | then | ||
279 | echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." | ||
280 | niro | 150 | mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts |
281 | niro | 2 | evaluate_retval |
282 | fi | ||
283 | else | ||
284 | # devpts is not supported, give a warning | ||
285 | echo -e ${COLRED}"No devpts filesystem found ..." | ||
286 | echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." | ||
287 | echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," | ||
288 | echo -e ${COLYELLOW}"or no pty's are available." | ||
289 | echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." | ||
290 | echo | ||
291 | echo -e ${COLYELLOW}"Press any key to continue ..." | ||
292 | read | ||
293 | fi | ||
294 | fi | ||
295 | |||
296 | ### services state dir ### | ||
297 | echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." | ||
298 | mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k | ||
299 | evaluate_retval | ||
300 | |||
301 | niro | 150 | # load bootsplash |
302 | niro | 2 | splash "rc_init" "${runlevel}" |
303 | fi | ||
304 | |||
305 | |||
306 | niro | 150 | if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
307 | niro | 2 | then |
308 | niro | 150 | # load bootsplash |
309 | niro | 2 | splash "rc_init" "${runlevel}" |
310 | |||
311 | # if requested save devices to a device tarball before halt | ||
312 | # only for kernels >=2.6 *and* udev | ||
313 | # make shure that udev is mounted but *not* devfs --> /dev/.devfsd | ||
314 | niro | 150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
315 | [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] | ||
316 | niro | 2 | then |
317 | echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." | ||
318 | niro | 150 | ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
319 | niro | 2 | mv -f "/tmp/devices-$$.tar.bz2" /lib/udev-state/devices.tar.bz2 |
320 | evaluate_retval | ||
321 | fi | ||
322 | fi | ||
323 | |||
324 | |||
325 | if [ "$runlevel" = "" ] | ||
326 | then | ||
327 | echo "Usage: $0 <runlevel>" >&2 | ||
328 | exit 1 | ||
329 | fi | ||
330 | |||
331 | niro | 150 | |
332 | niro | 2 | previous=$PREVLEVEL |
333 | [ "$previous" = "" ] && previous=N | ||
334 | |||
335 | if [ ! -d $rc_base/rc$runlevel.d ] | ||
336 | then | ||
337 | echo "$rc_base/rc$runlevel.d does not exist" | ||
338 | exit 1 | ||
339 | fi | ||
340 | |||
341 | if [ "$previous" != "N" ] | ||
342 | then | ||
343 | for i in $(ls -v $rc_base/rc$runlevel.d/K* 2> /dev/null) | ||
344 | do | ||
345 | |||
346 | check_script_status | ||
347 | |||
348 | suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]} | ||
349 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | ||
350 | sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix | ||
351 | |||
352 | if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ] | ||
353 | then | ||
354 | if [ ! -f $prev_start ] && [ ! -f $sysinit_start ] | ||
355 | then | ||
356 | $WARNING | ||
357 | echo "$i can't be executed because it was" | ||
358 | echo "not started in the previous runlevel ($previous)" | ||
359 | $NORMAL | ||
360 | continue | ||
361 | fi | ||
362 | fi | ||
363 | |||
364 | $i stop | ||
365 | error_value=$? | ||
366 | |||
367 | if [ "$error_value" != "0" ] | ||
368 | then | ||
369 | print_error_msg | ||
370 | fi | ||
371 | done | ||
372 | fi | ||
373 | |||
374 | for i in $( ls -v $rc_base/rc$runlevel.d/S* 2> /dev/null) | ||
375 | do | ||
376 | if [ "$previous" != "N" ] | ||
377 | then | ||
378 | suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]} | ||
379 | stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix | ||
380 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | ||
381 | |||
382 | [ -f $prev_start ] && [ ! -f $stop ] && continue | ||
383 | fi | ||
384 | |||
385 | check_script_status | ||
386 | |||
387 | $i start | ||
388 | error_value=$? | ||
389 | |||
390 | if [ "$error_value" != "0" ] | ||
391 | then | ||
392 | print_error_msg | ||
393 | fi | ||
394 | done |
Properties
Name | Value |
---|---|
svn:executable | * |