#!/bin/bash
set -e # stop if anything fails
set -x

session="influxd-3-shard-test"

# start the world if we're not already in session
if ! tmux ls | grep -q "$session"; then
	cd $GOPATH/src/github.com/influxdb/influxdb/tests/tmux
	tmux new-session -d -s $session

	# create and split main window into three panes
	tmux split-window -h -t $session
	tmux split-window -h -t $session

	# Fire up the servers
	tmux send-keys -t $session:1.1 'influxd -config server_8086.toml' C-m
	sleep 1
	tmux send-keys -t $session:1.2 'influxd -config server_8087.toml -join http://127.0.0.1:8086' C-m
	tmux send-keys -t $session:1.3 'influxd -config server_8088.toml -join http://127.0.0.1:8086' C-m
	sleep 1
	
	./seed.sh

	# even out the layouts
	tmux select-layout -t $session even-horizontal
fi