Annotation of /trunk/magellan-initscripts/rc/rc
Parent Directory | Revision Log
Revision 694 -
(hide annotations)
(download)
Sat Mar 22 19:59:32 2008 UTC (16 years, 6 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 8585 byte(s)
Sat Mar 22 19:59:32 2008 UTC (16 years, 6 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/rc
File size: 8585 byte(s)
-respect /lib/udev-state /lib/udev/state location change
1 | niro | 2 | #!/bin/bash |
2 | niro | 694 | # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/rc,v 1.20 2008-03-22 19:58:58 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 | niro | 431 | elif [[ -x /sbin/udevd ]] |
25 | then | ||
26 | version=$(/sbin/udevd --version) | ||
27 | version=${version##0} | ||
28 | [[ -z ${version} ]] && version=0 | ||
29 | niro | 319 | fi |
30 | |||
31 | echo "${version}" | ||
32 | } | ||
33 | |||
34 | populate_udev() | ||
35 | { | ||
36 | niro | 394 | local opts |
37 | niro | 318 | |
38 | niro | 428 | # tell modprobe.sh to be verbose to $CONSOLE |
39 | echo CONSOLE=${CONSOLE} > /dev/.udev_populate | ||
40 | |||
41 | niro | 318 | # populate /dev with devices already found by the kernel |
42 | niro | 692 | echo -e ${COLOREDSTAR}" Populating /dev with existing devices through uevents ..." |
43 | if [[ ${RC_COLDPLUG} = yes ]] | ||
44 | niro | 318 | then |
45 | niro | 692 | /sbin/udevtrigger |
46 | niro | 318 | else |
47 | niro | 692 | # do not run any init-scripts |
48 | /sbin/udevadm control --env do_not_run_plug_service=1 | ||
49 | |||
50 | # only create device nodes | ||
51 | /sbin/udevtrigger --attr-match=dev | ||
52 | |||
53 | # run persistent-net stuff | ||
54 | /sbin/udevtrigger --subsystem-match=net | ||
55 | niro | 318 | fi |
56 | niro | 692 | evaluate_retval |
57 | niro | 2 | |
58 | niro | 318 | # loop until everything is finished |
59 | echo -e ${COLOREDSTAR}" Letting udev process events ..." | ||
60 | niro | 394 | /sbin/udevsettle --timeout=60 |
61 | niro | 318 | evaluate_retval |
62 | |||
63 | niro | 692 | # unset this variable |
64 | udevadm control --env do_not_run_plug_service= | ||
65 | |||
66 | niro | 428 | rm -f /dev/.udev_populate |
67 | niro | 318 | return 0 |
68 | } | ||
69 | |||
70 | niro | 319 | seed_dev() |
71 | { | ||
72 | niro | 318 | # seed /dev with some things that we know we need |
73 | echo -e ${COLOREDSTAR}" Seeding /dev with needed nodes ..." | ||
74 | ( | ||
75 | niro | 428 | [ ! -c /dev/console ] && mknod /dev/console c 5 1 |
76 | [ ! -c /dev/tty1 ] && mknod /dev/tty1 c 4 1 | ||
77 | [ ! -c /dev/null ] && mknod /dev/null c 1 3 | ||
78 | |||
79 | niro | 318 | # copy over any persistant things |
80 | niro | 394 | if [[ -d /lib/udev/devices ]] |
81 | then | ||
82 | niro | 692 | cp -RPp /lib/udev/devices/* /dev 2>/dev/null |
83 | niro | 394 | fi |
84 | niro | 428 | |
85 | niro | 150 | # not provided by sysfs but needed |
86 | niro | 2 | ln -snf /proc/self/fd /dev/fd |
87 | ln -snf fd/0 /dev/stdin | ||
88 | ln -snf fd/1 /dev/stdout | ||
89 | ln -snf fd/2 /dev/stderr | ||
90 | niro | 318 | [[ -e /proc/kcore ]] && ln -snf /proc/kcore /dev/core |
91 | niro | 692 | |
92 | niro | 150 | # create problematic directories |
93 | niro | 692 | mkdir -p /dev/pts /dev/shm |
94 | niro | 318 | ) |
95 | evaluate_retval | ||
96 | } | ||
97 | niro | 2 | |
98 | trap "" INT QUIT TSTP | ||
99 | |||
100 | [ "$1" != "" ] && runlevel=$1 | ||
101 | |||
102 | niro | 150 | if [[ $runlevel = sysinit ]] |
103 | niro | 2 | then |
104 | echo | ||
105 | echo -e "${COLGREEN}Starting ${COLBLUE}MAGELLAN (v${MAGEVER}) ${COLGREEN}Linux${COLDEFAULT}" | ||
106 | niro | 643 | echo -e "Copyright 2001-2008 Niels Rogalla; http://magellan-linux.net" |
107 | niro | 2 | echo |
108 | |||
109 | niro | 150 | # mount proc filesystem, needed for bootsplash; |
110 | # no use of '/etc/rc.d/init.d/mountproc' anymore | ||
111 | niro | 2 | if [ ! -e /proc/mounts ] |
112 | then | ||
113 | echo -e ${COLOREDSTAR}"Mounting proc file system ..." | ||
114 | mount -n /proc | ||
115 | evaluate_retval | ||
116 | fi | ||
117 | |||
118 | niro | 150 | # set default verbose level for kernel messages |
119 | niro | 2 | [ -z "${RC_VERBOSE_LEVEL}" ] && RC_VERBOSE_LEVEL=3 |
120 | echo "${RC_VERBOSE_LEVEL}" > /proc/sys/kernel/printk | ||
121 | |||
122 | niro | 692 | # mount sys file system before udev |
123 | if [ -d /sys ] | ||
124 | niro | 2 | then |
125 | niro | 692 | echo -e ${COLOREDSTAR}"Mounting sysfs file system ..." |
126 | mount -n -t sysfs sysfs /sys | ||
127 | evaluate_retval | ||
128 | else | ||
129 | echo -e ${COLORED}"Fatal: mountpoint /sys missing ..." | ||
130 | echo -e ${COLYELLOW}"Please create the directory /sys (mkdir -p /sys)." | ||
131 | echo -e ${COLYELLOW}"It's essential for a 2.6 kernel." | ||
132 | niro | 2 | fi |
133 | |||
134 | |||
135 | niro | 692 | #### load udev #### |
136 | # check if /dev/console exists outside tmpfs | ||
137 | [ -c /dev/console ] ; need_redirect=$? | ||
138 | niro | 2 | |
139 | niro | 692 | # create a ramdisk for populating udev |
140 | echo -e ${COLOREDSTAR}"Mounting udev at /dev ..." | ||
141 | # many video drivers needed exec access | ||
142 | fstype=ramfs | ||
143 | # tmpfs was suggested by Greg Kroah-Hartman | ||
144 | kernel_supports_fs tmpfs && fstype=tmpfs | ||
145 | mount -n -t ${fstype} udev /dev -o exec,nosuid,mode=0755,size=10M | ||
146 | evaluate_retval | ||
147 | |||
148 | # if a device tarball exists load it and if it is activated | ||
149 | echo -e ${COLOREDSTAR}"Configurating system to use udev ..." | ||
150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] | ||
151 | niro | 2 | then |
152 | niro | 692 | echo -e ${COLOREDSTAR}" Populating /dev with saved device nodes ..." |
153 | niro | 694 | tar -jxpf /lib/udev/state/devices.tar.bz2 -C /dev |
154 | niro | 2 | evaluate_retval |
155 | niro | 692 | fi |
156 | niro | 2 | |
157 | niro | 692 | # other eeded device nodes with udev |
158 | seed_dev | ||
159 | niro | 2 | |
160 | niro | 692 | if [ -e /proc/sys/kernel/hotplug ] |
161 | then | ||
162 | echo -e ${COLOREDSTAR}" Using netlink for hotplug events ..." | ||
163 | echo "" > /proc/sys/kernel/hotplug | ||
164 | evaluate_retval | ||
165 | else | ||
166 | echo -e ${COLOREDSTAR}${COLYELLOW}" Kernel was not compiled with hotplug support !" | ||
167 | print_status failure | ||
168 | fi | ||
169 | niro | 2 | |
170 | niro | 692 | echo -e ${COLOREDSTAR}" Starting udevd daemon ..." |
171 | if [ ${need_redirect} -eq 1 ] | ||
172 | then | ||
173 | # we need to open fds 0 1 2 | ||
174 | /sbin/udevd --daemon </dev/console >/dev/console 2>/dev/console | ||
175 | else | ||
176 | /sbin/udevd --daemon | ||
177 | fi | ||
178 | evaluate_retval | ||
179 | niro | 318 | |
180 | niro | 692 | # write root_link rule |
181 | /lib/udev/write_root_link_rule | ||
182 | # populate udev device nodes | ||
183 | populate_udev | ||
184 | niro | 318 | |
185 | niro | 692 | # create nodes that udev can't |
186 | echo -e ${COLOREDSTAR}" Finializing udev configuration ..." | ||
187 | [[ -x /sbin/dmsetup ]] && /sbin/dmsetup mknodes &>/dev/null | ||
188 | [[ -x /sbin/lvm ]] && /sbin/lvm vgscan -P --mknodes --ignorelockingfailure &>/dev/null | ||
189 | [[ -x /sbin/evms_activate ]] && /sbin/evms_activate -q &>/dev/null | ||
190 | print_status success | ||
191 | niro | 318 | |
192 | niro | 692 | # same thing as /dev/.devfsd |
193 | touch /dev/.udev | ||
194 | ## end udev ## | ||
195 | niro | 318 | |
196 | niro | 2 | |
197 | ## load devpts ## | ||
198 | # devfs/udev with 2.6 has no ptys, so devpts is also needed | ||
199 | niro | 692 | # check if we really have devpts support |
200 | if kernel_supports_fs devpts | ||
201 | niro | 2 | then |
202 | niro | 692 | # /dev/pts maybe not exists. |
203 | # We only create this directory only if devfs was mounted, | ||
204 | # or it will fail as / is still mounted readonly | ||
205 | # udev has this dir already, only a sanity check for devfs | ||
206 | if [ ! -d "/dev/pts" -a -e "/dev/.devfsd" ] && is_fs_mounted devfs | ||
207 | niro | 2 | then |
208 | niro | 692 | mkdir -p /dev/pts &> /dev/null || \ |
209 | echo "Could not create /dev/pts !" | ||
210 | fi | ||
211 | niro | 71 | |
212 | niro | 692 | # now mount devpts |
213 | if [ -d /dev/pts ] | ||
214 | then | ||
215 | echo -e ${COLOREDSTAR}"Mounting devpts at /dev/pts ..." | ||
216 | mount -n -t devpts -o gid=4,mode=0620 devpts /dev/pts | ||
217 | evaluate_retval | ||
218 | niro | 2 | fi |
219 | niro | 692 | else |
220 | # devpts is not supported, give a warning | ||
221 | echo -e ${COLRED}"No devpts filesystem found ..." | ||
222 | echo -e ${COLYELLOW}"Your Kernel doesn't support the devpts filesystem." | ||
223 | echo -e ${COLYELLOW}"Devfs with a kernel-2.6.x needs devpts," | ||
224 | echo -e ${COLYELLOW}"or no pty's are available." | ||
225 | echo -e ${COLYELLOW}"Please make shure that this is enabled in your kernel." | ||
226 | echo | ||
227 | echo -e ${COLYELLOW}"Press any key to continue ..." | ||
228 | read | ||
229 | niro | 2 | fi |
230 | niro | 692 | ## end devpts ## |
231 | niro | 2 | |
232 | niro | 692 | |
233 | niro | 515 | ## load usbfs ## |
234 | if kernel_supports_fs usbfs | ||
235 | then | ||
236 | echo -e ${COLOREDSTAR}"Mounting usbfs at /proc/bus/usb ..." | ||
237 | mount -n -t usbfs usbfs /proc/bus/usb | ||
238 | evaluate_retval | ||
239 | fi | ||
240 | niro | 692 | ## end usbfs ## |
241 | niro | 515 | |
242 | niro | 692 | ## services state dir ## |
243 | niro | 2 | echo -e ${COLOREDSTAR}"Mounting tmpfs at ${svcdir} ..." |
244 | mount -n -t tmpfs tmpfs "${svcdir}" -o rw,mode=0644,size="${svcsize}"k | ||
245 | evaluate_retval | ||
246 | |||
247 | niro | 150 | # load bootsplash |
248 | niro | 2 | splash "rc_init" "${runlevel}" |
249 | fi | ||
250 | |||
251 | |||
252 | niro | 150 | if [[ $runlevel = 0 ]] || [[ $runlevel = 6 ]] |
253 | niro | 2 | then |
254 | niro | 150 | # load bootsplash |
255 | niro | 2 | splash "rc_init" "${runlevel}" |
256 | |||
257 | # if requested save devices to a device tarball before halt | ||
258 | # only for kernels >=2.6 *and* udev | ||
259 | # make shure that udev is mounted but *not* devfs --> /dev/.devfsd | ||
260 | niro | 150 | if [[ ${RC_DEVICE_TARBALL} = yes ]] && \ |
261 | [ -e /dev/.udev -a ! -e /dev/.devfsd -a ! -e /.bootdev ] | ||
262 | niro | 2 | then |
263 | echo -e ${COLOREDSTAR}"Saving /dev device nodes ..." | ||
264 | niro | 150 | ( cd /dev; tar -jclpf "/tmp/devices-$$.tar.bz2" * &> /dev/null ) |
265 | niro | 694 | mv -f "/tmp/devices-$$.tar.bz2" /lib/udev/state/devices.tar.bz2 |
266 | niro | 2 | evaluate_retval |
267 | fi | ||
268 | fi | ||
269 | |||
270 | |||
271 | if [ "$runlevel" = "" ] | ||
272 | then | ||
273 | echo "Usage: $0 <runlevel>" >&2 | ||
274 | exit 1 | ||
275 | fi | ||
276 | |||
277 | niro | 150 | |
278 | niro | 2 | previous=$PREVLEVEL |
279 | [ "$previous" = "" ] && previous=N | ||
280 | |||
281 | if [ ! -d $rc_base/rc$runlevel.d ] | ||
282 | then | ||
283 | echo "$rc_base/rc$runlevel.d does not exist" | ||
284 | exit 1 | ||
285 | fi | ||
286 | |||
287 | if [ "$previous" != "N" ] | ||
288 | then | ||
289 | for i in $(ls -v $rc_base/rc$runlevel.d/K* 2> /dev/null) | ||
290 | do | ||
291 | |||
292 | check_script_status | ||
293 | |||
294 | suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]} | ||
295 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | ||
296 | sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix | ||
297 | |||
298 | if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ] | ||
299 | then | ||
300 | if [ ! -f $prev_start ] && [ ! -f $sysinit_start ] | ||
301 | then | ||
302 | $WARNING | ||
303 | echo "$i can't be executed because it was" | ||
304 | echo "not started in the previous runlevel ($previous)" | ||
305 | $NORMAL | ||
306 | continue | ||
307 | fi | ||
308 | fi | ||
309 | |||
310 | $i stop | ||
311 | error_value=$? | ||
312 | |||
313 | if [ "$error_value" != "0" ] | ||
314 | then | ||
315 | print_error_msg | ||
316 | fi | ||
317 | done | ||
318 | fi | ||
319 | |||
320 | for i in $( ls -v $rc_base/rc$runlevel.d/S* 2> /dev/null) | ||
321 | do | ||
322 | if [ "$previous" != "N" ] | ||
323 | then | ||
324 | suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]} | ||
325 | stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix | ||
326 | prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix | ||
327 | |||
328 | [ -f $prev_start ] && [ ! -f $stop ] && continue | ||
329 | fi | ||
330 | |||
331 | check_script_status | ||
332 | |||
333 | $i start | ||
334 | error_value=$? | ||
335 | |||
336 | if [ "$error_value" != "0" ] | ||
337 | then | ||
338 | print_error_msg | ||
339 | fi | ||
340 | done |
Properties
Name | Value |
---|---|
svn:executable | * |