#!/bin/sh # # Created by William Astle, December 2002 # # This script is hereby placed in the public domain with no warrantee at all. # # read rctab and start/stop various services as defined by it # we do the stopping before we do the starting # note that for simplicity we read the rctab file twice # # note that services are stopped in the reverse order to which # they are started. That is from the bottom of rctab to the top. # # /var/run/rcstate is used to keep track of whether a service is started # or not RCTAB=/etc/rc.d/rctab STATEDIR=/var/run/rcstate runlevel="$1" # read the rctab file curindex=0 #grep -v "^\#" "$RCTAB" | grep -v "^$" | 3<"$RCTAB" while read <&3 do if echo "$REPLY" | egrep '^$' > /dev/null; then continue fi if echo "$REPLY" | grep "^\#" > /dev/null; then continue fi rcentries[$curindex]="$REPLY" curindex=$[$curindex+1] done # run the stop commands (done in reverse order) for (( ctr=$[curindex-1]; 0 <= $ctr; ctr=$[$ctr-1] )); do IDENTIFIER=`echo "${rcentries[$ctr]}" | cut -d: -f1` RUNLEVELS=`echo "${rcentries[$ctr]}" | cut -d: -f2` STARTCMD=`echo "${rcentries[$ctr]}" | cut -d: -f3` STOPCMD=`echo "${rcentries[$ctr]}" | cut -d: -f4` if ! echo "$RUNLEVELS" | grep "$runlevel" > /dev/null; then if [ -f "$STATEDIR/$IDENTIFIER" ]; then eval "$STOPCMD" rm -f "$STATEDIR/$IDENTIFIER" fi fi done # run the start commands for (( ctr=0; $ctr < $curindex; ctr=$[$ctr+1] )); do IDENTIFIER=`echo "${rcentries[$ctr]}" | cut -d: -f1` RUNLEVELS=`echo "${rcentries[$ctr]}" | cut -d: -f2` STARTCMD=`echo "${rcentries[$ctr]}" | cut -d: -f3` STOPCMD=`echo "${rcentries[$ctr]}" | cut -d: -f4` if echo "$RUNLEVELS" | grep "$runlevel" > /dev/null; then if [ ! -f "$STATEDIR/$IDENTIFIER" ]; then eval "$STARTCMD" touch "$STATEDIR/$IDENTIFIER" fi fi done