Magellan Linux

Contents of /trunk/magellan-initscripts/etc/rc.d/init.d/rc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 376 - (show annotations) (download)
Mon May 29 21:25:45 2006 UTC (17 years, 11 months ago) by niro
File size: 10310 byte(s)
fixed errors with pre-release kernels (kernel_version may contain _rc and similar)

1 #!/bin/bash
2 # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.9 2006-05-29 21:25:45 niro Exp $
3
4 source /etc/sysconfig/rc
5 source $rc_functions
6
7 # get mage version
8 MAGEVER="$(< /etc/mageversion)"
9
10 # source kernel config if exists
11 [ -f /etc/conf.d/kernel ] && source /etc/conf.d/kernel
12
13 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 # 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 populate_udev()
70 {
71 local loop
72
73 # populate /dev with devices already found by the kernel
74 if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -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 /sbin/udevstart
82 evaluate_retval
83 fi
84
85 # 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 seed_dev()
101 {
102 # 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 # not provided by sysfs but needed
109 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 [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core
114
115 # create problematic directories
116 mkdir -p /dev/{pts,shm}
117 )
118 evaluate_retval
119 }
120
121 trap "" INT QUIT TSTP
122
123 [ "$1" != "" ] && runlevel=$1
124
125 if [[ $runlevel = sysinit ]]
126 then
127 echo
128 echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}"
129 echo -e "Copyright 2001-2006 Niels Rogalla; http://magellan-linux.net"
130 echo
131
132 # mount proc filesystem, needed for bootsplash;
133 # no use of '/etc/rc.d/init.d/mountproc' anymore
134 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 # set default verbose level for kernel messages
142 [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3
143 echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk
144
145 # mount sys file system before udev or devfs (kernel-2.6)
146 if [[ $(kernel_major_version) = 2.6 ]]
147 then
148 if [ -d /sys ]
149 then
150 echo -e ${COLOREDSTAR}"Mounting sysfs file system ..."
151 mount -n -t sysfs sysfs /sys
152 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 # 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 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 mount -n -t devfs devfs /dev
172 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 # load udev only with a 2.6 kernel
195 if [[ $(kernel_major_version) = 2.6 ]] && [[ ${RC_USED_DEV} = udev ]]
196 then
197 # 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 evaluate_retval
203
204 # if a device tarball exists load it and if it is activated
205 echo -e ${COLOREDSTAR}"Configurating system to use udev ..."
206 if [[ ${RC_DEVICE_TARBALL} = yes ]]
207 then
208 echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..."
209 tar -jxpf /lib/udev-state/devices.tar.bz2 -C /dev
210 evaluate_retval
211 fi
212
213 # other eeded device nodes with udev
214 seed_dev
215
216 if [ -e /proc/sys/kernel/hotplug ]
217 then
218 if [ "$(kernel_version | sed 's:\.::g' | cut -d_ -f1)" -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 else
238 echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !"
239 print_status failure
240 fi
241
242 echo -e ${COLOREDSTAR}" Starting udevd daemon ..."
243 /sbin/udevd --daemon
244 evaluate_retval
245
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 fi
258
259 ## load devpts ##
260 # devfs/udev with 2.6 has no ptys, so devpts is also needed
261 if [[ $(kernel_major_version) = 2.6 ]]
262 then
263 # check if we really have devpts support
264 if kernel_supports_fs devpts
265 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 # 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 then
272 mkdir -p /dev/pts &> /dev/null || \
273 echo "Could not create /dev/pts !"
274 fi
275
276 # now mount devpts
277 if [ -d /dev/pts ]
278 then
279 echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..."
280 mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts
281 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 # load bootsplash
302 splash "rc_init" "${runlevel}"
303 fi
304
305
306 if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]]
307 then
308 # load bootsplash
309 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 if [[ ${RC_DEVICE_TARBALL} = yes ]] && \
315 [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ]
316 then
317 echo -e ${COLOREDSTAR}"Saving /dev device nodes ..."
318 ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null )
319 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
332 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 *