#!/bin/sh

# Never run if systemd is running; it will do this.
[ -f /bin/systemctl ] && /bin/systemctl show-environment >/dev/null 2>&1 \
    && (sv down testbed ; exit 0)

if [ -f /usr/local/etc/emulab/initscripts/testbed ]; then
    /usr/local/etc/emulab/initscripts/testbed start
    if [ ! $? -eq 0 ]; then
	echo "Failed to start /usr/local/etc/emulab/initscripts/testbed: $?"
	exit $?
    fi
    #
    # runit expects the run file to continue execution until death.
    #
    while [ 1 -eq 1 ]; do
        sleep 60
    done
else
    sv down testbed
fi

exit 0
