File:  [DragonFly] / src / sbin / rcrun / rcrun.sh
Revision 1.3: download - view: text, annotated - select for diffs
Fri Dec 12 00:14:28 2003 UTC (10 years, 8 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
Be smarter about services which are in a disabled state.  If the
service is disabled, first try to run the RCNG script.  If it is still
disabled report the fact (the user needs to use rcforce to run a disabled
service).

    1: #!/bin/sh
    2: #
    3: # rcng command
    4: #
    5: # $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.3 2003/12/12 00:14:28 dillon Exp $
    6: 
    7: OS=`sysctl -n kern.ostype`
    8: 
    9: dostart()
   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: 			Xdisabled*)
   32: 			    ;;
   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)
   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
   53: 	    fi
   54: 	    ;;
   55: 	esac
   56:     done
   57: }
   58: 
   59: arg=$0
   60: case ${0##*/} in
   61: rcstart)
   62:     arg=start
   63:     ;;
   64: rcstop)
   65:     arg=stop
   66:     ;;
   67: rcrestart)
   68:     arg=restart
   69:     ;;
   70: rcvar)
   71:     arg=rcvar
   72:     ;;
   73: rcvars)
   74:     arg=rcvar
   75:     ;;
   76: rclist)
   77:     arg=list
   78:     ;;
   79: rcforce)
   80:     arg=forcestart
   81:     ;;
   82: rcfast)
   83:     arg=faststart
   84:     ;;
   85: *)
   86:     arg=$1
   87:     shift
   88:     ;;
   89: esac
   90: 
   91: case $arg in
   92: start)
   93: 	dostart start $@
   94: 	;;
   95: forcestart)
   96: 	dostart forcestart $@
   97: 	;;
   98: faststart)
   99: 	dostart faststart $@
  100: 	;;
  101: stop)
  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: 	;;
  111: restart)
  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: 	;;
  121: rcvar)
  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: 	;;
  130: list)
  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: 	;;
  144: esac
  145: