Minor grammatical fix.
[dragonfly.git] / sbin / rcrun / rcrun.sh
CommitLineData
75326d0e
MD
1#!/bin/sh
2#
3# rcng command
4#
453375e0 5# $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.3 2003/12/12 00:14:28 dillon Exp $
75326d0e
MD
6
7OS=`sysctl -n kern.ostype`
8
9dostart()
10{
11 arg=$1
12 shift
13
14 for i in $@; do
15 case X`varsym -s -q rcng_$i` in
16 Xrunning*)
17 echo "$i has already been started"
18 ;;
19 *)
20 _return=0
21 for j in `rcorder -k $OS -o $i /etc/rc.d/*`; do
22 need=1
23 for k in `rcorder -p $j`; do
24 if [ $k = $i ]; then
25 need=0
26 else
27 state=`varsym -s -q rcng_$k`
28 case X$state in
29 Xrunning*)
30 ;;
453375e0
MD
31 Xdisabled*)
32 ;;
75326d0e
MD
33 *)
34 echo "$i depends on $k, current state: $state"
35 _return=1
36 ;;
37 esac
38 fi
39 done
40 done
41 # $j contains the last dependancy, which we run
42 #
43 if [ X$j = X ]; then
44 echo "Unable to find keyword $i"
45 elif [ $_return = 0 ]; then
46 echo "Running $j $arg"
47 (cd /etc/rc.d; sh $j $arg)
453375e0
MD
48 case X`varsym -s -q rcng_$i` in
49 Xdisabled*)
50 echo "$i is disabled, enable in rc.conf first or use rcforce"
51 ;;
52 esac
75326d0e
MD
53 fi
54 ;;
55 esac
56 done
57}
58
59arg=$0
60case ${0##*/} in
61rcstart)
62 arg=start
63 ;;
64rcstop)
65 arg=stop
66 ;;
67rcrestart)
68 arg=restart
69 ;;
70rcvar)
71 arg=rcvar
72 ;;
73rcvars)
74 arg=rcvar
75 ;;
76rclist)
77 arg=list
78 ;;
79rcforce)
80 arg=forcestart
81 ;;
82rcfast)
83 arg=faststart
84 ;;
85*)
86 arg=$1
87 shift
88 ;;
89esac
90
91case $arg in
92start)
93 dostart start $@
94 ;;
95forcestart)
96 dostart forcestart $@
97 ;;
98faststart)
99 dostart faststart $@
100 ;;
101stop)
102 for i in $@; do
103 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
104 if [ X$j = X ]; then
105 echo "Unable to find keyword $i"
106 else
107 (cd /etc/rc.d; sh $j stop)
108 fi
109 done
110 ;;
111restart)
112 for i in $@; do
113 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
114 if [ X$j = X ]; then
115 echo "Unable to find keyword $i"
116 else
117 (cd /etc/rc.d; sh $j restart)
118 fi
119 done
120 ;;
121rcvar)
122 for i in $@; do
123 if [ X$j = X ]; then
124 echo "Unable to find keyword $i"
125 else
126 (cd /etc/rc.d; sh $j rcvar)
127 fi
128 done
129 ;;
130list)
131 if [ X$@ = X ]; then
132 for i in `varsym -a -s | egrep '^rcng_'`; do
133 echo $i
134 done
135 else
136 for i in $@; do
137 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
138 done
139 fi
140 ;;
141*)
142 echo "$0 {start|stop|restart|rcvar|list|forcestart|faststart} <rcng_list>"
143 ;;
144esac
145