Skip to content

Commit 3f12b07

Browse files
author
Quentin Perez
committed
Merge pull request #30 from scaleway/improve-rancher-script
Improve rancher script
2 parents 0eb3dca + 96518f7 commit 3f12b07

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

examples/start-rancher.sh

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,75 @@
11
#!/bin/sh
2+
## depends on docker client, curl, docker-machine + docker-machine-driver-scaleway, jq
3+
4+
5+
# looking for existing rancher-server
6+
if docker-machine inspect rancher-server >/dev/null; then
7+
echo "[-] rancher-server already exists."
8+
echo " you need to remove your previous rancher machines from docker-machine before running this script."
9+
exit 1
10+
fi
11+
12+
13+
set -xe
14+
SLAVES=3
15+
216

317
# create a machine for the Rancher server
4-
docker-machine create -d scaleway --scaleway-name=rancher-server rancher-server || exit 1
18+
docker-machine create -d scaleway --scaleway-name=rancher-server rancher-server
19+
520

621
# configure shell to use rancher-server
722
eval $(docker-machine env rancher-server)
823

9-
# create a machine for a Rancher host
10-
docker-machine create -d scaleway --scaleway-name=rancher-host-1 rancher-host-1 || exit 1 &
24+
25+
# create machines for a Rancher host (slaves)
26+
for i in $(seq 1 ${SLAVES}); do
27+
docker-machine create -d scaleway --scaleway-name=rancher-host-$i rancher-host-$i &
28+
done
29+
1130

1231
# start a Rancher Server on rancher-server
13-
docker run -d --restart=always -p 8080:8080 rancher/server || exit 1
32+
docker run -d --restart=always -p 8080:8080 rancher/server
33+
(
34+
set +xe
35+
false
36+
while [ "$?" != "0" ]
37+
do
38+
# wait for Rancher Server installation
39+
docker logs $(docker ps -q) | grep "Startup Succeeded"
40+
done
41+
)
1442

15-
false
16-
while [ "$?" != "0" ]
17-
do
18-
# wait for Rancher Server installation
19-
docker logs $(docker ps -q) | grep "Startup Succeeded"
20-
done
2143

2244
# wait for background tasks
23-
wait `jobs -p` || true
45+
wait `jobs -p`; sleep 10
2446

25-
IP=$(docker-machine ip rancher-server)
2647

27-
sleep 10
2848

2949
# generate a token
30-
curl 'http://'$IP':8080/v1/registrationtoken' -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --data-binary '{"type":"registrationToken"}' --compressed > /dev/null
50+
RANCHER_IP=$(docker-machine ip rancher-server)
51+
curl "http://${RANCHER_IP}:8080/v1/registrationtoken" \
52+
-H 'x-api-project-id: 1a5' \
53+
-H 'Accept: application/json' \
54+
--data-binary '{"type":"registrationToken"}' \
55+
--compressed > /dev/null
3156
sleep 5
32-
CMD=$(curl 'http://'$IP':8080/v1/registrationtokens?state=active&limit=-1' -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --compressed | jq '.data[0].command' | sed 's/sudo//g' | tr -d '"')
57+
3358

3459
# start a Rancher Agent on rancher-server
35-
$CMD || exit 1
60+
AGENT_CMD=$(
61+
curl "http://${RANCHER_IP}:8080/v1/registrationtokens?state=active&limit=-1" -H 'x-api-project-id: 1a5' -H 'Accept: application/json' --compressed \
62+
| jq -r '.data[0].command' \
63+
| sed 's/sudo//g'
64+
)
65+
${AGENT_CMD}
66+
3667

37-
# configure shell to use rancher-host-1
38-
eval $(docker-machine env rancher-host-1)
68+
# start a Rancher Agent on rancher-host-X (slaves)
69+
for i in $(seq 1 ${SLAVES}); do
70+
eval $(docker-machine env rancher-host-$i)
71+
${AGENT_CMD}
72+
done
3973

40-
# start a Rancher Agent on rancher-host-1
41-
$CMD || exit 1
4274

43-
echo "Open your browser at http://"$IP":8080"
75+
echo "Open your browser at http://${RANCHER_IP}:8080"

0 commit comments

Comments
 (0)