File:  [DragonFly] / src / sbin / rcrun / rcrun.sh
Revision 1.2: download - view: text, annotated - select for diffs
Fri Dec 12 00:00:10 2003 UTC (10 years, 8 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
Make a distinction between disabled entries and running entries.  Do not
start disabled services.  Still TODO: add 'enable' and 'disable' commands
which modify /etc/rc.conf!

    1: #!/bin/sh
    2: #
    3: # rcng command
    4: #
    5: # $DragonFly: src/sbin/rcrun/rcrun.sh,v 1.2 2003/12/12 00:00:10 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: 	Xdisabled*)
   20: 	    echo "$i is currently disabled"
   21: 	    ;;
   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: 
   55: arg=$0
   56: case ${0##*/} in
   57: rcstart)
   58:     arg=start
   59:     ;;
   60: rcstop)
   61:     arg=stop
   62:     ;;
   63: rcrestart)
   64:     arg=restart
   65:     ;;
   66: rcvar)
   67:     arg=rcvar
   68:     ;;
   69: rcvars)
   70:     arg=rcvar
   71:     ;;
   72: rclist)
   73:     arg=list
   74:     ;;
   75: rcforce)
   76:     arg=forcestart
   77:     ;;
   78: rcfast)
   79:     arg=faststart
   80:     ;;
   81: *)
   82:     arg=$1
   83:     shift
   84:     ;;
   85: esac
   86: 
   87: case $arg in
   88: start)
   89: 	dostart start $@
   90: 	;;
   91: forcestart)
   92: 	dostart forcestart $@
   93: 	;;
   94: faststart)
   95: 	dostart faststart $@
   96: 	;;
   97: stop)
   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: 	;;
  107: restart)
  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: 	;;
  117: rcvar)
  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: 	;;
  126: list)
  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: 	;;
  140: esac
  141: