chiark / gitweb /
[PATCH] LSB init script and other stuff
[elogind.git] / etc / init.d / udev.init.LSB
1 #! /bin/sh
2 #
3 # Author: Rolf Eike Beer <eike-hotplug@sf-tec.de>
4 #   derived from original RedHat udev init script
5 #   based on the SuSE 9.0 template (c) 1995-2002 SuSE Linux AG
6 #
7 # /etc/init.d/udev
8 #   and its symbolic link
9 # /(usr/)sbin/rcudev
10 #
11 # System startup script for udev
12 #
13 # LSB compatible service control script; see http://www.linuxbase.org/spec/
14
15 ### BEGIN INIT INFO
16 # Provides:          udev
17 # Required-Start:    
18 # Required-Stop:     
19 # Default-Start:     1 2 3 5
20 # Default-Stop:      0 6
21 # Short-Description: manage user-space device nodes in /udev
22 # Description:       Start udev to create the device files for all
23 #                    devices already present in system when script is
24 #                    called. All other devices files will be automatically
25 #                    created when udev is called via /sbin/hotplug.
26 #                    Requires at least a kernel 2.6 to work properly.
27 ### END INIT INFO
28
29 # Note on script names:
30 # http://www.linuxbase.org/spec/refspecs/LSB_1.2.0/gLSB/scrptnames.html
31 # A registry has been set up to manage the init script namespace.
32 # http://www.lanana.org/
33 # Please use the names already registered or register one or use a
34 # vendor prefix.
35
36
37 # Check for missing binaries (stale symlinks should not happen)
38 UDEV_BIN=/sbin/udev
39 test -x $UDEV_BIN || exit 5
40
41 # Check for existence of needed config file and read it
42 UDEV_CONFIG=/etc/udev/udev.conf
43 test -r $UDEV_CONFIG || exit 6
44 . $UDEV_CONFIG
45
46 # Directory where sysfs is mounted
47 SYSFS_DIR=/sys
48
49 # Source LSB init functions
50 . /lib/lsb/init-functions
51
52 run_udev () {
53         # handle block devices and their partitions
54         for i in ${SYSFS_DIR}/block/*; do
55                 # add each drive
56                 export DEVPATH=${i#${SYSFS_DIR}}
57                 $UDEV_BIN block &
58
59                 # add each partition, on each device
60                 for j in $i/*; do
61                         if [ -f $j/dev ]; then
62                                 export DEVPATH=${j#${SYSFS_DIR}}
63                                 $UDEV_BIN block &
64                         fi
65                 done
66         done
67         # all other device classes
68         for i in ${SYSFS_DIR}/class/*; do
69                 for j in $i/*; do
70                         if [ -f $j/dev ]; then
71                                 export DEVPATH=${j#${SYSFS_DIR}}
72                                 CLASS=`echo ${i#${SYSFS_DIR}} | \
73                                         cut --delimiter='/' --fields=3-`
74                                 $UDEV_BIN $CLASS &
75                         fi
76                 done
77         done
78 }
79
80 case "$1" in
81     start)
82         if [ ! -d $SYSFS_DIR ]; then
83                 log_failure_msg "${0}: SYSFS_DIR \"$SYSFS_DIR\" not found"
84                 exit 1
85         fi
86         if [ ! -d $udev_root ]; then
87                 mkdir $udev_root || exit 4
88         fi
89         # propogate /udev from /sys - we only need this while we do not
90         # have initramfs and an early user-space with which to do early
91         # device bring up
92         echo -n "Creating initial udev device nodes: "
93         export ACTION=add
94         run_udev
95         log_success_msg
96         ;;
97     stop)
98         # be careful
99         echo -n "Removing udev device nodes: "
100         export ACTION=remove
101         run_udev
102         rm -f $udev_db || exit 1
103         rmdir $udev_root || exit 1
104         log_success_msg
105         ;;
106     restart)
107         $0 stop
108         $0 start
109
110         exit $?
111         ;;
112     force-reload)
113         echo -n "Reload udev "
114         $0 stop  &&  $0 start
115         exit $?
116         ;;
117     reload)
118         exit 3
119         ;;
120     status)
121         echo -n "Checking for udev root directory: "
122         if [ -d $udev_root ]; then
123                 log_success_msg found
124         else
125                 log_warning_msg "not found"
126                 exit 3
127         fi
128         ;;
129     *)
130         echo "Usage: $0 {start|stop|status|restart|force-reload|reload}"
131         exit 1
132         ;;
133 esac