#!/bin/bash
#
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
. /etc/emulab/paths.sh

#
# testbed       Do some testbed stuff,
#
# description:	On shutdown, it informs the testbed we are rebooting
#		and terminates any lingering daemons.

RETVAL=0

# See how we were called.
case "$1" in
  start)
        # Fire off testbed startup.
        $BINDIR/rc/rc.testbed
        touch /var/lock/subsys/testbed
	;;
  stop) 
        rm /var/lock/subsys/testbed
	echo "Shutting down testbed daemons ..."
	killall trafgen
	killall program-agent
	killall slothd
	killall healthd
	killall watchdog
	killall evproxy
	killall linktest
	killall emulab-syncd
	killall tippty
	echo "Informing the testbed we're rebooting ..."
	$BINDIR/tmcc state SHUTDOWN
	RETVAL=$?
	;;
  status)
	echo "Peachy"
	;;
  restart)
	echo "Done"
	;;
  reload)
	echo "Done"
	;;
  *)
	echo "Usage: testbed {start|stop|restart|reload|status}"
	exit 1
esac

exit $RETVAL
