Fix a bug which was introduced in cvs-1.12.13.
[dragonfly.git] / sbin / rcrun / rcrun.sh
blob653350eaa18b87e2ee4a7e60f4b7d9803dc0f1b4
1 #!/bin/sh
3 # rcng command
5 # $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.4 2003/12/13 02:49:09 dillon Exp $
7 OS=`sysctl -n kern.ostype`
9 dostart()
11 arg=$1
12 shift
14 for i in $@; do
15 case X`varsym -s -q rcng_$i` in
16 Xrunning*)
17 echo "$i has already been started"
19 Xconfigured*)
20 echo "$i has already been configured"
23 _return=0
24 for j in `rcorder -k $OS -o $i /etc/rc.d/*`; do
25 need=1
26 for k in `rcorder -p $j`; do
27 if [ $k = $i ]; then
28 need=0
29 else
30 state=`varsym -s -q rcng_$k`
31 case X$state in
32 Xrunning*|Xconfigured*|Xirrelevant*|Xdisabled*)
35 echo "$i depends on $k, current state: $state"
36 _return=1
38 esac
40 done
41 done
42 # $j contains the last dependancy, which we run
44 if [ X$j = X ]; then
45 echo "Unable to find keyword $i"
46 elif [ $_return = 0 ]; then
47 echo "Running $j $arg"
48 (cd /etc/rc.d; sh $j $arg)
49 case X`varsym -s -q rcng_$i` in
50 Xdisabled*)
51 echo "$i is disabled, enable in rc.conf first or use rcforce"
53 Xfailed*)
54 echo "$i has failed to start"
57 esac
60 esac
61 done
64 arg=$0
65 case ${0##*/} in
66 rcstart)
67 arg=start
69 rcstop)
70 arg=stop
72 rcrestart)
73 arg=restart
75 rcvar)
76 arg=rcvar
78 rcvars)
79 arg=rcvar
81 rclist)
82 arg=list
84 rcforce)
85 arg=forcestart
87 rcfast)
88 arg=faststart
90 rcenable)
91 arg=enable
93 rcdisable)
94 arg=disable
97 arg=$1
98 shift
100 esac
102 case $arg in
103 start)
104 dostart start $@
106 forcestart)
107 dostart forcestart $@
109 faststart)
110 dostart faststart $@
112 stop)
113 for i in $@; do
114 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
115 if [ X$j = X ]; then
116 echo "Unable to find keyword $i"
117 else
118 (cd /etc/rc.d; sh $j stop)
120 done
122 restart)
123 for i in $@; do
124 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
125 if [ X$j = X ]; then
126 echo "Unable to find keyword $i"
127 else
128 (cd /etc/rc.d; sh $j restart)
130 done
132 disable|enable)
133 if [ "$arg" = "enable" ]; then
134 mode=YES
135 else
136 mode=NO
138 for i in $@; do
139 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
140 if [ X$j = X ]; then
141 echo "Unable to find provider id $i"
142 elif [ `varsym -s -q rcng_$i` = "$mode" ]; then
143 echo "$i is already $mode"
144 else
145 vars=`(cd /etc/rc.d; sh $j rcvar) 2>/dev/null | egrep '_enable' | sed -e 's/\\$//g' | sed -e 's/=.*//g'`
146 cp /etc/rc.conf /etc/rc.conf.bak
147 for k in $vars; do
148 rm -f /etc/rc.conf.$$
149 ( egrep -v "#rcrun ${k}" /etc/rc.conf; printf "${k}=${mode}\t#rcrun ${k}_enable\n" ) > /etc/rc.conf.$$
150 mv -f /etc/rc.conf.$$ /etc/rc.conf
151 echo "added/modified: ${k}=${mode}"
152 done
153 if [ $arg = enable ]; then
154 rcstart $i
155 else
156 rcstop $i
159 done
161 rcvar)
162 for i in $@; do
163 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
164 if [ X$j = X ]; then
165 echo "Unable to find provider id $i"
166 else
167 (cd /etc/rc.d; sh $j rcvar)
169 done
171 list)
172 if [ X$@ = X ]; then
173 for i in `varsym -a -s | egrep '^rcng_'`; do
174 echo $i
175 done
176 else
177 for i in $@; do
178 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
179 done
183 echo "$0 {start|stop|restart|rcvar|list|forcestart|faststart} <rcng_list>"
185 esac