175326d0eSMatthew Dillon#!/bin/sh 275326d0eSMatthew Dillon# 375326d0eSMatthew Dillon# rcng command 475326d0eSMatthew Dillon# 536e1ae1aSSascha Wildner# $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.9 2008/07/21 23:42:02 swildner Exp $ 675326d0eSMatthew Dillon 775326d0eSMatthew Dillondostart() 875326d0eSMatthew Dillon{ 975326d0eSMatthew Dillon arg=$1 1075326d0eSMatthew Dillon shift 1175326d0eSMatthew Dillon 1275326d0eSMatthew Dillon for i in $@; do 1375326d0eSMatthew Dillon case X`varsym -s -q rcng_$i` in 1475326d0eSMatthew Dillon Xrunning*) 1575326d0eSMatthew Dillon echo "$i has already been started" 1675326d0eSMatthew Dillon ;; 176d94234bSMatthew Dillon Xconfigured*) 186d94234bSMatthew Dillon echo "$i has already been configured" 196d94234bSMatthew Dillon ;; 2075326d0eSMatthew Dillon *) 2175326d0eSMatthew Dillon _return=0 222a510934SSimon Schubert for j in `rcorder -o $i /etc/rc.d/*`; do 2375326d0eSMatthew Dillon need=1 2475326d0eSMatthew Dillon for k in `rcorder -p $j`; do 2575326d0eSMatthew Dillon if [ $k = $i ]; then 2675326d0eSMatthew Dillon need=0 2775326d0eSMatthew Dillon else 2875326d0eSMatthew Dillon state=`varsym -s -q rcng_$k` 2975326d0eSMatthew Dillon case X$state in 306d94234bSMatthew Dillon Xrunning*|Xconfigured*|Xirrelevant*|Xdisabled*) 31453375e0SMatthew Dillon ;; 3275326d0eSMatthew Dillon *) 3375326d0eSMatthew Dillon echo "$i depends on $k, current state: $state" 3475326d0eSMatthew Dillon _return=1 3575326d0eSMatthew Dillon ;; 3675326d0eSMatthew Dillon esac 3775326d0eSMatthew Dillon fi 3875326d0eSMatthew Dillon done 3975326d0eSMatthew Dillon done 4036e1ae1aSSascha Wildner # $j contains the last dependency, which we run 4175326d0eSMatthew Dillon # 4275326d0eSMatthew Dillon if [ X$j = X ]; then 4375326d0eSMatthew Dillon echo "Unable to find keyword $i" 4475326d0eSMatthew Dillon elif [ $_return = 0 ]; then 4575326d0eSMatthew Dillon echo "Running $j $arg" 4675326d0eSMatthew Dillon (cd /etc/rc.d; sh $j $arg) 47453375e0SMatthew Dillon case X`varsym -s -q rcng_$i` in 48453375e0SMatthew Dillon Xdisabled*) 49453375e0SMatthew Dillon echo "$i is disabled, enable in rc.conf first or use rcforce" 50453375e0SMatthew Dillon ;; 516d94234bSMatthew Dillon Xfailed*) 526d94234bSMatthew Dillon echo "$i has failed to start" 536d94234bSMatthew Dillon ;; 546d94234bSMatthew Dillon 55453375e0SMatthew Dillon esac 5675326d0eSMatthew Dillon fi 5775326d0eSMatthew Dillon ;; 5875326d0eSMatthew Dillon esac 5975326d0eSMatthew Dillon done 6075326d0eSMatthew Dillon} 6175326d0eSMatthew Dillon 6275326d0eSMatthew Dillonarg=$0 6375326d0eSMatthew Dilloncase ${0##*/} in 6475326d0eSMatthew Dillonrcstart) 6575326d0eSMatthew Dillon arg=start 6675326d0eSMatthew Dillon ;; 6775326d0eSMatthew Dillonrcstop) 6875326d0eSMatthew Dillon arg=stop 6975326d0eSMatthew Dillon ;; 7075326d0eSMatthew Dillonrcrestart) 7175326d0eSMatthew Dillon arg=restart 7275326d0eSMatthew Dillon ;; 7375326d0eSMatthew Dillonrcvar) 7475326d0eSMatthew Dillon arg=rcvar 7575326d0eSMatthew Dillon ;; 7675326d0eSMatthew Dillonrcvars) 7775326d0eSMatthew Dillon arg=rcvar 7875326d0eSMatthew Dillon ;; 7975326d0eSMatthew Dillonrclist) 8075326d0eSMatthew Dillon arg=list 8175326d0eSMatthew Dillon ;; 8275326d0eSMatthew Dillonrcforce) 8375326d0eSMatthew Dillon arg=forcestart 8475326d0eSMatthew Dillon ;; 8575326d0eSMatthew Dillonrcfast) 8675326d0eSMatthew Dillon arg=faststart 8775326d0eSMatthew Dillon ;; 886d94234bSMatthew Dillonrcenable) 896d94234bSMatthew Dillon arg=enable 906d94234bSMatthew Dillon ;; 916d94234bSMatthew Dillonrcdisable) 926d94234bSMatthew Dillon arg=disable 936d94234bSMatthew Dillon ;; 9475326d0eSMatthew Dillon*) 9575326d0eSMatthew Dillon arg=$1 9675326d0eSMatthew Dillon shift 9775326d0eSMatthew Dillon ;; 9875326d0eSMatthew Dillonesac 9975326d0eSMatthew Dillon 10075326d0eSMatthew Dilloncase $arg in 10175326d0eSMatthew Dillonstart) 10275326d0eSMatthew Dillon dostart start $@ 10375326d0eSMatthew Dillon ;; 10475326d0eSMatthew Dillonforcestart) 10575326d0eSMatthew Dillon dostart forcestart $@ 10675326d0eSMatthew Dillon ;; 10775326d0eSMatthew Dillonfaststart) 10875326d0eSMatthew Dillon dostart faststart $@ 10975326d0eSMatthew Dillon ;; 11075326d0eSMatthew Dillonstop) 11175326d0eSMatthew Dillon for i in $@; do 1122a510934SSimon Schubert j=`rcorder -o $i /etc/rc.d/* | tail -1` 11375326d0eSMatthew Dillon if [ X$j = X ]; then 11475326d0eSMatthew Dillon echo "Unable to find keyword $i" 11575326d0eSMatthew Dillon else 11675326d0eSMatthew Dillon (cd /etc/rc.d; sh $j stop) 11775326d0eSMatthew Dillon fi 11875326d0eSMatthew Dillon done 11975326d0eSMatthew Dillon ;; 12075326d0eSMatthew Dillonrestart) 12175326d0eSMatthew Dillon for i in $@; do 1222a510934SSimon Schubert j=`rcorder -o $i /etc/rc.d/* | tail -1` 12375326d0eSMatthew Dillon if [ X$j = X ]; then 12475326d0eSMatthew Dillon echo "Unable to find keyword $i" 12575326d0eSMatthew Dillon else 12675326d0eSMatthew Dillon (cd /etc/rc.d; sh $j restart) 12775326d0eSMatthew Dillon fi 12875326d0eSMatthew Dillon done 12975326d0eSMatthew Dillon ;; 1306d94234bSMatthew Dillondisable|enable) 1316d94234bSMatthew Dillon if [ "$arg" = "enable" ]; then 1326d94234bSMatthew Dillon mode=YES 1336d94234bSMatthew Dillon else 1346d94234bSMatthew Dillon mode=NO 1356d94234bSMatthew Dillon fi 1366d94234bSMatthew Dillon for i in $@; do 1372a510934SSimon Schubert j=`rcorder -o $i /etc/rc.d/* | tail -1` 1386d94234bSMatthew Dillon if [ X$j = X ]; then 1396d94234bSMatthew Dillon echo "Unable to find provider id $i" 1406d94234bSMatthew Dillon elif [ `varsym -s -q rcng_$i` = "$mode" ]; then 1416d94234bSMatthew Dillon echo "$i is already $mode" 1426d94234bSMatthew Dillon else 143*6eb624aaSSascha Wildner vars=`(cd /etc/rc.d; sh $j rcvar) 2>/dev/null | grep = | sed -e 's/\\$//g' | sed -e 's/=.*//g'` 1446d94234bSMatthew Dillon cp /etc/rc.conf /etc/rc.conf.bak 145*6eb624aaSSascha Wildner if [ $arg = disable ]; then 146*6eb624aaSSascha Wildner rcstop $i 147*6eb624aaSSascha Wildner fi 1486d94234bSMatthew Dillon for k in $vars; do 1496d94234bSMatthew Dillon rm -f /etc/rc.conf.$$ 150*6eb624aaSSascha Wildner ( egrep -v "# rcrun enable ${k}$" /etc/rc.conf; printf "${k}=${mode}\t# rcrun enable ${k}\n" ) > /etc/rc.conf.$$ 1516d94234bSMatthew Dillon mv -f /etc/rc.conf.$$ /etc/rc.conf 1526d94234bSMatthew Dillon echo "added/modified: ${k}=${mode}" 1536d94234bSMatthew Dillon done 1546d94234bSMatthew Dillon if [ $arg = enable ]; then 1556d94234bSMatthew Dillon rcstart $i 1566d94234bSMatthew Dillon fi 1576d94234bSMatthew Dillon fi 1586d94234bSMatthew Dillon done 1596d94234bSMatthew Dillon ;; 16075326d0eSMatthew Dillonrcvar) 16175326d0eSMatthew Dillon for i in $@; do 1622a510934SSimon Schubert j=`rcorder -o $i /etc/rc.d/* | tail -1` 16375326d0eSMatthew Dillon if [ X$j = X ]; then 1646d94234bSMatthew Dillon echo "Unable to find provider id $i" 16575326d0eSMatthew Dillon else 16675326d0eSMatthew Dillon (cd /etc/rc.d; sh $j rcvar) 16775326d0eSMatthew Dillon fi 16875326d0eSMatthew Dillon done 16975326d0eSMatthew Dillon ;; 17075326d0eSMatthew Dillonlist) 17123da15d3SSascha Wildner if [ "X$*" = X ]; then 17275326d0eSMatthew Dillon for i in `varsym -a -s | egrep '^rcng_'`; do 17375326d0eSMatthew Dillon echo $i 17475326d0eSMatthew Dillon done 17575326d0eSMatthew Dillon else 17675326d0eSMatthew Dillon for i in $@; do 17775326d0eSMatthew Dillon varsym -s rcng_$i 2>/dev/null || varsym -s rcng_$i 17875326d0eSMatthew Dillon done 17975326d0eSMatthew Dillon fi 18075326d0eSMatthew Dillon ;; 18175326d0eSMatthew Dillon*) 182c56fbe27SSascha Wildner echo "usage: rcrun start|stop|restart|rcvar|list|forcestart|faststart|disable|enable" 183c56fbe27SSascha Wildner echo " script ..." 18475326d0eSMatthew Dillon ;; 18575326d0eSMatthew Dillonesac 18675326d0eSMatthew Dillon 187