HAMMER Utility - cleanup
[dragonfly.git] / sbin / rcrun / rcrun.sh
blobf5b23351f9d455401e9208beb3079ea6124c120d
1 #!/bin/sh
3 # rcng command
5 # $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.9 2008/07/21 23:42:02 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 dependency, 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 | grep = | sed -e 's/\\$//g' | sed -e 's/=.*//g'`
144 cp /etc/rc.conf /etc/rc.conf.bak
145 if [ $arg = disable ]; then
146 rcstop $i
148 for k in $vars; do
149 rm -f /etc/rc.conf.$$
150 ( egrep -v "# rcrun enable ${k}$" /etc/rc.conf; printf "${k}=${mode}\t# rcrun enable ${k}\n" ) > /etc/rc.conf.$$
151 mv -f /etc/rc.conf.$$ /etc/rc.conf
152 echo "added/modified: ${k}=${mode}"
153 done
154 if [ $arg = enable ]; then
155 rcstart $i
158 done
160 rcvar)
161 for i in $@; do
162 j=`rcorder -o $i /etc/rc.d/* | tail -1`
163 if [ X$j = X ]; then
164 echo "Unable to find provider id $i"
165 else
166 (cd /etc/rc.d; sh $j rcvar)
168 done
170 list)
171 if [ "X$*" = X ]; then
172 for i in `varsym -a -s | egrep '^rcng_'`; do
173 echo $i
174 done
175 else
176 for i in $@; do
177 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
178 done
182 echo "usage: rcrun start|stop|restart|rcvar|list|forcestart|faststart|disable|enable"
183 echo " script ..."
185 esac