2019-11-26 09:57:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
ECHO_COLOR="\033[0;34m"
|
|
|
|
ECHO_COLOR_END="\033[0m"
|
2019-11-26 09:57:01 +00:00
|
|
|
SWARM_MANAGER_IP=""
|
|
|
|
SWARM_WORKER_NUMBER=4
|
|
|
|
|
|
|
|
if [ -z ${SWARM_MANAGER_IP} ]; then
|
|
|
|
# See https://stackoverflow.com/a/25851186
|
|
|
|
SWARM_MANAGER_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
|
|
|
|
fi
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Leave possible swarm and down all services...${ECHO_COLOR_END}"
|
2019-11-28 08:57:03 +00:00
|
|
|
docker swarm leave --force
|
2020-01-03 09:27:55 +00:00
|
|
|
docker-compose --file dind_swarm.yml down
|
2019-11-26 09:57:01 +00:00
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Start storage container...${ECHO_COLOR_END}"
|
2019-11-26 09:57:01 +00:00
|
|
|
docker-compose --file dind_swarm.yml up --detach storage
|
|
|
|
sleep 3
|
2019-11-26 10:43:08 +00:00
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Mount network storage to host system...${ECHO_COLOR_END}"
|
|
|
|
if [ ! -d "/mnt/nopaque" ]; then
|
|
|
|
sudo mkdir -p /mnt/nopaque
|
|
|
|
fi
|
|
|
|
if mountpoint -q /mnt/nopaque; then
|
|
|
|
sudo umount --force /mnt/nopaque
|
|
|
|
fi
|
|
|
|
sudo mount --types cifs --options gid=${USER},password=nopaque,uid=${USER},user=nopaque,vers=3.0 //localhost/storage.nopaque /mnt/nopaque
|
2019-11-26 10:43:08 +00:00
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Start worker service(s)...${ECHO_COLOR_END}"
|
2019-11-26 10:39:27 +00:00
|
|
|
docker-compose --file dind_swarm.yml up --detach --scale worker=${SWARM_WORKER_NUMBER} worker viz
|
2019-11-28 08:57:03 +00:00
|
|
|
sleep 7
|
2019-11-26 10:39:27 +00:00
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Init Docker swarm...${ECHO_COLOR_END}"
|
|
|
|
docker swarm init --advertise-addr ${SWARM_MANAGER_IP} > /dev/null
|
2019-11-26 10:39:27 +00:00
|
|
|
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -e "${ECHO_COLOR}Add workers to swarm...${ECHO_COLOR_END}"
|
2019-11-26 10:39:27 +00:00
|
|
|
SWARM_WORKER_TOKEN=$(docker swarm join-token -q worker)
|
2019-11-26 09:57:01 +00:00
|
|
|
for i in $(seq 1 ${SWARM_WORKER_NUMBER}); do
|
2020-01-03 09:27:55 +00:00
|
|
|
echo -n "[worker_${i}]: "
|
2019-11-26 09:57:01 +00:00
|
|
|
docker-compose --file dind_swarm.yml exec --index=${i} worker docker swarm join --token ${SWARM_WORKER_TOKEN} ${SWARM_MANAGER_IP}:2377
|
|
|
|
done
|