Repair rcenable(8) and rcdisable(8).
[dragonfly.git] / sbin / rcrun / rcrun.sh
CommitLineData
75326d0e
MD
1#!/bin/sh
2#
3# rcng command
4#
36e1ae1a 5# $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.9 2008/07/21 23:42:02 swildner Exp $
75326d0e
MD
6
7dostart()
8{
9 arg=$1
10 shift
11
12 for i in $@; do
13 case X`varsym -s -q rcng_$i` in
14 Xrunning*)
15 echo "$i has already been started"
16 ;;
6d94234b
MD
17 Xconfigured*)
18 echo "$i has already been configured"
19 ;;
75326d0e
MD
20 *)
21 _return=0
2a510934 22 for j in `rcorder -o $i /etc/rc.d/*`; do
75326d0e
MD
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
6d94234b 30 Xrunning*|Xconfigured*|Xirrelevant*|Xdisabled*)
453375e0 31 ;;
75326d0e
MD
32 *)
33 echo "$i depends on $k, current state: $state"
34 _return=1
35 ;;
36 esac
37 fi
38 done
39 done
36e1ae1a 40 # $j contains the last dependency, which we run
75326d0e
MD
41 #
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)
453375e0
MD
47 case X`varsym -s -q rcng_$i` in
48 Xdisabled*)
49 echo "$i is disabled, enable in rc.conf first or use rcforce"
50 ;;
6d94234b
MD
51 Xfailed*)
52 echo "$i has failed to start"
53 ;;
54
453375e0 55 esac
75326d0e
MD
56 fi
57 ;;
58 esac
59 done
60}
61
62arg=$0
63case ${0##*/} in
64rcstart)
65 arg=start
66 ;;
67rcstop)
68 arg=stop
69 ;;
70rcrestart)
71 arg=restart
72 ;;
73rcvar)
74 arg=rcvar
75 ;;
76rcvars)
77 arg=rcvar
78 ;;
79rclist)
80 arg=list
81 ;;
82rcforce)
83 arg=forcestart
84 ;;
85rcfast)
86 arg=faststart
87 ;;
6d94234b
MD
88rcenable)
89 arg=enable
90 ;;
91rcdisable)
92 arg=disable
93 ;;
75326d0e
MD
94*)
95 arg=$1
96 shift
97 ;;
98esac
99
100case $arg in
101start)
102 dostart start $@
103 ;;
104forcestart)
105 dostart forcestart $@
106 ;;
107faststart)
108 dostart faststart $@
109 ;;
110stop)
111 for i in $@; do
2a510934 112 j=`rcorder -o $i /etc/rc.d/* | tail -1`
75326d0e
MD
113 if [ X$j = X ]; then
114 echo "Unable to find keyword $i"
115 else
116 (cd /etc/rc.d; sh $j stop)
117 fi
118 done
119 ;;
120restart)
121 for i in $@; do
2a510934 122 j=`rcorder -o $i /etc/rc.d/* | tail -1`
75326d0e
MD
123 if [ X$j = X ]; then
124 echo "Unable to find keyword $i"
125 else
126 (cd /etc/rc.d; sh $j restart)
127 fi
128 done
129 ;;
6d94234b
MD
130disable|enable)
131 if [ "$arg" = "enable" ]; then
132 mode=YES
133 else
134 mode=NO
135 fi
136 for i in $@; do
2a510934 137 j=`rcorder -o $i /etc/rc.d/* | tail -1`
6d94234b
MD
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
6eb624aa 143 vars=`(cd /etc/rc.d; sh $j rcvar) 2>/dev/null | grep = | sed -e 's/\\$//g' | sed -e 's/=.*//g'`
6d94234b 144 cp /etc/rc.conf /etc/rc.conf.bak
6eb624aa
SW
145 if [ $arg = disable ]; then
146 rcstop $i
147 fi
6d94234b
MD
148 for k in $vars; do
149 rm -f /etc/rc.conf.$$
6eb624aa 150 ( egrep -v "# rcrun enable ${k}$" /etc/rc.conf; printf "${k}=${mode}\t# rcrun enable ${k}\n" ) > /etc/rc.conf.$$
6d94234b
MD
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
6d94234b
MD
156 fi
157 fi
158 done
159 ;;
75326d0e
MD
160rcvar)
161 for i in $@; do
2a510934 162 j=`rcorder -o $i /etc/rc.d/* | tail -1`
75326d0e 163 if [ X$j = X ]; then
6d94234b 164 echo "Unable to find provider id $i"
75326d0e
MD
165 else
166 (cd /etc/rc.d; sh $j rcvar)
167 fi
168 done
169 ;;
170list)
23da15d3 171 if [ "X$*" = X ]; then
75326d0e
MD
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
179 fi
180 ;;
181*)
c56fbe27
SW
182 echo "usage: rcrun start|stop|restart|rcvar|list|forcestart|faststart|disable|enable"
183 echo " script ..."
75326d0e
MD
184 ;;
185esac
186