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