-
Notifications
You must be signed in to change notification settings - Fork 2
/
tis.sh
40 lines (32 loc) · 1.31 KB
/
tis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
if [ $# != 3 ]; then
echo "USAGE: $0 TsungConfigFile ClientAmount CanClientRunOnControler"
echo "e.g.: $0 config.xml 1 0"
exit 1;
fi
IMAGE_NAME=ffantasy/tsung-in-swarm:19101203
PREFIX=ff-tsung-
NETWORK_NAME=${PREFIX}network
CONTROLER_NAME=${PREFIX}controler
CLIENT_NAME=${PREFIX}client
echo -e "\e[33mcreate tsung network...\e[0m"
docker network create -d overlay $NETWORK_NAME
echo -e "\e[33mcreate tsung controler...\e[0m"
docker service create -d --name $CONTROLER_NAME --constraint 'node.role == manager' --replicas=1 -p8091:8091 --network $NETWORK_NAME --mount type=bind,source=$1,destination=/tmp/config.xml $IMAGE_NAME sleep 3650000d
controlerId=''
while [ -z $controlerId ]; do
sleep 1s
controlerId=$(docker ps -qf "name=$CONTROLER_NAME")
done
echo -e "\e[33mcreate tsung clients...\e[0m"
CONSTRAINT=""
if [ $3 -eq 0 ]; then
CONSTRAINT="--constraint 'node.role != manager'"
fi
eval docker service create -d --name $CLIENT_NAME $CONSTRAINT --replicas=$2 --network $NETWORK_NAME $IMAGE_NAME bash runclient.sh $CONTROLER_NAME
echo -e "\e[33mrun contorler...\e[0m"
docker exec -it $controlerId bash runcontroler.sh $2
echo -e "\e[33mremove service...\e[0m"
docker service rm $CLIENT_NAME $CONTROLER_NAME
#make sure remove controler container
docker rm -f $(docker ps -aqf "name=$CONTROLER_NAME") > /dev/null