@@ -28,32 +28,40 @@ get_node_id()
28
28
echo " NODE: $NODE_ID "
29
29
}
30
30
31
- get_tokens_db ()
31
+ get_tokens ()
32
32
{
33
- echo " Get tokens from Azure Table"
34
- DATA=$( python azuretokens.py get-tokens)
35
- export MANAGER_IP=$( echo $DATA | cut -d' |' -f 1)
36
- export MANAGER_TOKEN=$( echo $DATA | cut -d' |' -f 2)
37
- export WORKER_TOKEN=$( echo $DATA | cut -d' |' -f 3)
38
-
39
- echo " MANAGER_TOKEN=$MANAGER_TOKEN "
40
- echo " WORKER_TOKEN=$WORKER_TOKEN "
33
+ echo " Get MANAGER IP from Azure Table"
34
+ export MANAGER_IP=$( python azureleader.py get-ip)
35
+ get_manager_token
36
+ get_worker_token
41
37
}
42
38
43
- get_tokens_local ()
39
+ get_manager_token ()
44
40
{
45
- export MANAGER_TOKEN=$( docker swarm join-token manager -q)
46
- export WORKER_TOKEN=$( docker swarm join-token worker -q)
47
- echo " MANAGER_TOKEN=$MANAGER_TOKEN "
48
- echo " WORKER_TOKEN=$WORKER_TOKEN "
41
+ if [ -n " $MANAGER_IP " ]; then
42
+ export MANAGER_TOKEN=$( wget -qO- http://$MANAGER_IP :9024/token/manager/)
43
+ echo " MANAGER_TOKEN=$MANAGER_TOKEN "
44
+ else
45
+ echo " MANAGER_TOKEN can't be found yet. MANAGER_IP isn't set yet."
46
+ fi
47
+ }
48
+
49
+ get_worker_token ()
50
+ {
51
+ if [ -n " $MANAGER_IP " ]; then
52
+ export WORKER_TOKEN=$( wget -qO- http://$MANAGER_IP :9024/token/worker/)
53
+ echo " WORKER_TOKEN=$WORKER_TOKEN "
54
+ else
55
+ echo " WORKER_TOKEN can't be found yet. MANAGER_IP isn't set yet."
56
+ fi
49
57
}
50
58
51
59
confirm_primary_ready ()
52
60
{
53
61
n=0
54
62
until [ $n -ge 5 ]
55
63
do
56
- get_tokens_db
64
+ get_tokens
57
65
echo " PRIMARY_MANAGER_IP=$MANAGER_IP "
58
66
# if Manager IP or manager_token is empty or manager_token is null, not ready yet.
59
67
# token would be null for a short time between swarm init, and the time the
@@ -97,7 +105,7 @@ join_as_secondary_manager()
97
105
n=$[$n +1]
98
106
99
107
# query azure table again, incase the manager changed
100
- get_tokens_db
108
+ get_tokens
101
109
else
102
110
echo " Connected to primary manager, NODE_ID=$NODE_ID , SWARM_ID=$SWARM_ID "
103
111
break
@@ -118,21 +126,20 @@ setup_manager()
118
126
# try to create the azure table that will store tokens, if it succeeds then it is the first
119
127
# and it is the primary manager. If it fails, then it isn't first, and treat the record
120
128
# that is there, as the primary manager, and join that swarm.
121
- python azuretokens .py create-table
129
+ python azureleader .py create-table
122
130
PRIMARY_RESULT=$?
123
131
echo " PRIMARY_RESULT=$PRIMARY_RESULT "
124
132
125
133
if [ $PRIMARY_RESULT -eq 0 ]; then
126
134
echo " Primary Manager init"
127
135
# we are the primary, so init the cluster
128
136
docker swarm init --listen-addr $PRIVATE_IP :2377 --advertise-addr $PRIVATE_IP :2377
129
- # we can now get the tokens.
130
- get_tokens_local
137
+ # we can now get the swarm id and node id.
131
138
get_swarm_id
132
139
get_node_id
133
140
134
- # update azure table with the tokens
135
- python azuretokens .py insert-tokens $PRIVATE_IP $MANAGER_TOKEN $WORKER_TOKEN
141
+ # update azure table with the ip
142
+ python azureleader .py insert-ip $PRIVATE_IP
136
143
137
144
echo " Primary Manager init complete"
138
145
# send identify message
@@ -177,7 +184,7 @@ setup_worker()
177
184
n=$[$n +1]
178
185
179
186
# query azure table again, incase the manager changed
180
- get_tokens_db
187
+ get_tokens
181
188
else
182
189
echo " Connected to manager, NODE_ID=$NODE_ID , SWARM_ID=$SWARM_ID "
183
190
break
@@ -187,14 +194,16 @@ setup_worker()
187
194
}
188
195
189
196
# init variables based on azure token table contents (if populated)
190
- get_tokens_db
197
+ get_tokens
191
198
192
199
# if it is a manager, setup as manager, if not, setup as worker node.
193
200
if [ " $ROLE " == " MANAGER" ] ; then
194
201
echo " It's a Manager, run setup"
202
+ get_manager_token
195
203
setup_manager
196
204
else
197
205
echo " It's a worker Node, run setup"
206
+ get_worker_token
198
207
setup_worker
199
208
fi
200
209
0 commit comments