-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_swarm.sh
executable file
·82 lines (55 loc) · 1.97 KB
/
create_swarm.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash -x
SWARMIP=$1
SWARMROLE=$2
SWARMMASTER_IP=$3
#DOWNLOAD_URL=$4
ENGINE_MODE=$4
echo ${ENGINE_MODE}|tr '[A-Z]' '[a-z]'
#SHARED Between Nodes..
TMPSHARED="/tmp_deploying_stage"
#Docker Multi Daemon
# DEFAULTS
DOCKER_ROOTDIR="${DOCKER_ROOTDIR:=/var/lib/docker}"
DOCKER_RUNDIR="${DOCKER_RUNDIR:=/var/run}"
DOCKER_CONFIGDIR="${DOCKER_CONFIGDIR:=/etc/docker}"
DOCKER_LOGDIR="${DOCKER_LOGDIR:=/var/log/docker}"
ErrorMessage(){
echo "$(date +%Y/%m/%d-%H:%M:%S) ERROR: $*"
exit 1
}
InfoMessage(){
echo "$(date +%Y/%m/%d-%H:%M:%S) INFO: $*"
}
# USER="vagrant"
# [ $(grep -c "${USER}" /etc/passwd) -ne 1 ] && USER="ubuntu"
# if ! dpkg -l docker >/dev/null 2>&1
# then
# #Install Engine (This way, we can reprovision)
# InfoMessage "Installing Docker"
# apt-get install -qq curl \
# && curl -sSk ${DOWNLOAD_URL} | sh \
# && usermod -aG docker ${USER}
# fi
#DOCKER_DAEMON="docker -H ${SWARMIP}:2375"
InfoMessage "SWARM MODE ROLE [${SWARMROLE}]"
# Enabling Experimetal Features
# [ "${ENGINE_MODE}" == "experimental" ] \
# && echo "{\"experimental\" : true}" > /etc/docker/daemon.json \
# && systemctl restart docker
case ${SWARMROLE} in
manager)
[ ! -f ${TMPSHARED}/manager.token ] && InfoMessage "Initiating Swarm Cluster" \
&& docker swarm init --advertise-addr ${SWARMIP} --listen-addr ${SWARMIP} \
&& docker swarm join-token manager -q > ${TMPSHARED}/manager.token \
&& docker swarm join-token worker -q > ${TMPSHARED}/worker.token \
&& touch ${TMPSHARED}/$(hostname).provisioned \
&& exit
[ -f ${TMPSHARED}/manager.token -a ! -f ${TMPSHARED}/$(hostname).provisioned ] && InfoMessage "Joining Swarm Cluster" \
&& docker swarm join ${SWARMMASTER_IP}:2377 --advertise-addr ${SWARMIP} --listen-addr ${SWARMIP} \
--token $(cat ${TMPSHARED}/manager.token)
;;
worker)
docker swarm join ${SWARMMASTER_IP}:2377 --advertise-addr ${SWARMIP} --listen-addr ${SWARMIP} \
--token $(cat ${TMPSHARED}/worker.token)
;;
esac