Create the USB task queues before creating the event thread to avoid
[dragonfly/vkernel-mp.git] / sbin / rcrun / rcrun.sh
blobf385af8f54ddd3228d23783b5b04dde29bffb6a2
1 #!/bin/sh
3 # rcng command
5 # $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.6 2005/12/20 16:25:45 swildner Exp $
7 dostart()
9 arg=$1
10 shift
12 for i in $@; do
13 case X`varsym -s -q rcng_$i` in
14 Xrunning*)
15 echo "$i has already been started"
17 Xconfigured*)
18 echo "$i has already been configured"
21 _return=0
22 for j in `rcorder -o $i /etc/rc.d/*`; do
23 need=1
24 for k in `rcorder -p $j`; do
25 if [ $k = $i ]; then
26 need=0
27 else
28 state=`varsym -s -q rcng_$k`
29 case X$state in
30 Xrunning*|Xconfigured*|Xirrelevant*|Xdisabled*)
33 echo "$i depends on $k, current state: $state"
34 _return=1
36 esac
38 done
39 done
40 # $j contains the last dependancy, which we run
42 if [ X$j = X ]; then
43 echo "Unable to find keyword $i"
44 elif [ $_return = 0 ]; then
45 echo "Running $j $arg"
46 (cd /etc/rc.d; sh $j $arg)
47 case X`varsym -s -q rcng_$i` in
48 Xdisabled*)
49 echo "$i is disabled, enable in rc.conf first or use rcforce"
51 Xfailed*)
52 echo "$i has failed to start"
55 esac
58 esac
59 done
62 arg=$0
63 case ${0##*/} in
64 rcstart)
65 arg=start
67 rcstop)
68 arg=stop
70 rcrestart)
71 arg=restart
73 rcvar)
74 arg=rcvar
76 rcvars)
77 arg=rcvar
79 rclist)
80 arg=list
82 rcforce)
83 arg=forcestart
85 rcfast)
86 arg=faststart
88 rcenable)
89 arg=enable
91 rcdisable)
92 arg=disable
95 arg=$1
96 shift
98 esac
100 case $arg in
101 start)
102 dostart start $@
104 forcestart)
105 dostart forcestart $@
107 faststart)
108 dostart faststart $@
110 stop)
111 for i in $@; do
112 j=`rcorder -o $i /etc/rc.d/* | tail -1`
113 if [ X$j = X ]; then
114 echo "Unable to find keyword $i"
115 else
116 (cd /etc/rc.d; sh $j stop)
118 done
120 restart)
121 for i in $@; do
122 j=`rcorder -o $i /etc/rc.d/* | tail -1`
123 if [ X$j = X ]; then
124 echo "Unable to find keyword $i"
125 else
126 (cd /etc/rc.d; sh $j restart)
128 done
130 disable|enable)
131 if [ "$arg" = "enable" ]; then
132 mode=YES
133 else
134 mode=NO
136 for i in $@; do
137 j=`rcorder -o $i /etc/rc.d/* | tail -1`
138 if [ X$j = X ]; then
139 echo "Unable to find provider id $i"
140 elif [ `varsym -s -q rcng_$i` = "$mode" ]; then
141 echo "$i is already $mode"
142 else
143 vars=`(cd /etc/rc.d; sh $j rcvar) 2>/dev/null | egrep '_enable' | sed -e 's/\\$//g' | sed -e 's/=.*//g'`
144 cp /etc/rc.conf /etc/rc.conf.bak
145 for k in $vars; do
146 rm -f /etc/rc.conf.$$
147 ( egrep -v "#rcrun ${k}" /etc/rc.conf; printf "${k}=${mode}\t#rcrun ${k}_enable\n" ) > /etc/rc.conf.$$
148 mv -f /etc/rc.conf.$$ /etc/rc.conf
149 echo "added/modified: ${k}=${mode}"
150 done
151 if [ $arg = enable ]; then
152 rcstart $i
153 else
154 rcstop $i
157 done
159 rcvar)
160 for i in $@; do
161 j=`rcorder -o $i /etc/rc.d/* | tail -1`
162 if [ X$j = X ]; then
163 echo "Unable to find provider id $i"
164 else
165 (cd /etc/rc.d; sh $j rcvar)
167 done
169 list)
170 if [ X$@ = X ]; then
171 for i in `varsym -a -s | egrep '^rcng_'`; do
172 echo $i
173 done
174 else
175 for i in $@; do
176 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
177 done
181 echo "$0 {start|stop|restart|rcvar|list|forcestart|faststart} <rcng_list>"
183 esac