start on runlevel [2345]
stop  on runlevel [06]

env SERVER_DIR="/opt/speedtest/SpeedTestServer"
env SERVER_BIN="/opt/speedtest/SpeedTestServer/SpeedTestServer"
env CONFIG_DIR="/opt/speedtest/SpeedTestServer/config"
env PORT_RANGE_START="7000"
env INSTANCE_COUNT=10
env MANAGEMENT_SERVER_URL="http://speedrr.bluewin.ch:80"
env NETWORK_IF="eth0"

description "SpeedTestServer"

pre-start script
	cd $SERVER_DIR
	export LOCAL_IP=`ifconfig $NETWORK_IF | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
	echo $LOCAL_IP
	./sts_generate_config.sh \
		"$CONFIG_DIR" \
		"$PORT_RANGE_START" \
		"$INSTANCE_COUNT" \
		"$MANAGEMENT_SERVER_URL" \
		"$LOCAL_IP"
	echo "Config generated"
	for number in `seq 1 $INSTANCE_COUNT`
	do
		echo "Starting instance $number"
		start speedtest-instance NUMBER=$number
	done
end script

post-stop script
	for number in `seq 1 $INSTANCE_COUNT`
	do
		echo "Stopping instance $number"
		stop speedtest-instance NUMBER=$number
	done
end script
