#!/bin/sh
#
#    Copyright (c) 1996-2005 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    Runlevel control script.
#

# Find out what the current and what the previous runlevel are.
argv1="$1"
set `/sbin/runlevel`
runlevel=$2
previous=$1
export runlevel previous

# Get first argument. Set new runlevel to this argument.

[ "$1" != "" ] && runlevel="$argv1"

if [ -d /etc/rc.d/rc$runlevel.d ]; then

	#  First, run the KILL scripts.

	for i in /etc/rc.d/rc$runlevel.d/K*; do
		# Check if the script is there.
		[ ! -f $i ] && continue

		# Bring the subsystem down.
		$i stop
	done

	#  Now run the START scripts.

	for i in /etc/rc.d/rc$runlevel.d/S*; do
		# Check if the script is there.
		[ ! -f $i ] && continue

		# Bring the subsystem up, using a wrapper if needed
		W=${i/\/S//wrap-S}
		if [ -x "$W" ]
		then	"$W" "$i" start
		else	$i start
		fi
	done
fi
