Make a distinction between disabled entries and running entries. Do not
[dragonfly.git] / sbin / rcrun / rcrun.sh
CommitLineData
75326d0e
MD
1#!/bin/sh
2#
3# rcng command
4#
d4e71ee3 5# $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.2 2003/12/12 00:00:10 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 ;;
d4e71ee3
MD
19 Xdisabled*)
20 echo "$i is currently disabled"
21 ;;
75326d0e
MD
22 *)
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*)
33 ;;
34 *)
35 echo "$i depends on $k, current state: $state"
36 _return=1
37 ;;
38 esac
39 fi
40 done
41 done
42 # $j contains the last dependancy, which we run
43 #
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 fi
50 ;;
51 esac
52 done
53}
54
55arg=$0
56case ${0##*/} in
57rcstart)
58 arg=start
59 ;;
60rcstop)
61 arg=stop
62 ;;
63rcrestart)
64 arg=restart
65 ;;
66rcvar)
67 arg=rcvar
68 ;;
69rcvars)
70 arg=rcvar
71 ;;
72rclist)
73 arg=list
74 ;;
75rcforce)
76 arg=forcestart
77 ;;
78rcfast)
79 arg=faststart
80 ;;
81*)
82 arg=$1
83 shift
84 ;;
85esac
86
87case $arg in
88start)
89 dostart start $@
90 ;;
91forcestart)
92 dostart forcestart $@
93 ;;
94faststart)
95 dostart faststart $@
96 ;;
97stop)
98 for i in $@; do
99 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
100 if [ X$j = X ]; then
101 echo "Unable to find keyword $i"
102 else
103 (cd /etc/rc.d; sh $j stop)
104 fi
105 done
106 ;;
107restart)
108 for i in $@; do
109 j=`rcorder -k $OS -o $i /etc/rc.d/* | tail -1`
110 if [ X$j = X ]; then
111 echo "Unable to find keyword $i"
112 else
113 (cd /etc/rc.d; sh $j restart)
114 fi
115 done
116 ;;
117rcvar)
118 for i in $@; do
119 if [ X$j = X ]; then
120 echo "Unable to find keyword $i"
121 else
122 (cd /etc/rc.d; sh $j rcvar)
123 fi
124 done
125 ;;
126list)
127 if [ X$@ = X ]; then
128 for i in `varsym -a -s | egrep '^rcng_'`; do
129 echo $i
130 done
131 else
132 for i in $@; do
133 varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i
134 done
135 fi
136 ;;
137*)
138 echo "$0 {start|stop|restart|rcvar|list|forcestart|faststart} <rcng_list>"
139 ;;
140esac
141