forked from grycap/ec4docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-cluster
executable file
·82 lines (74 loc) · 3 KB
/
setup-cluster
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
#
# EC4Docker - Elastic Cluster for Docker
# https://github.com/grycap/ec4docker
#
# Copyright (C) GRyCAP - I3M - UPV
# Developed by Carlos A. caralla@upv.es
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
function usage() {
echo "usage $0 [ --deploy-nodes | -d ] [ [ --config-file | -f ] <config-file> ] [ --help | -h ]"
}
CONFIG_FILE=$(dirname $0)/ec4docker.config
DEPLOY_NODES=False
ASSUME_YES=False
while [ $# -gt 0 ]; do
case $1 in
--deploy-nodes | -d) DEPLOY_NODES=True;;
--yes | -y) ASSUME_YES=True;;
--config-file | -f) [ $# -lt 2 ] && usage && exit 1
CONFIG_FILE=$2
shift;;
--help | -h) usage && exit 0;;
*) usage && exit 1;;
esac
shift
done
# Read the configuration if exists
if [ ! -e "$CONFIG_FILE" ]; then
echo "WARNING: file $CONFIG_FILE does not exist... ignoring and getting default variables" >&2
else
source $CONFIG_FILE
fi
# Set the default values if they are not set
EC4DOCK_SERVERNAME=${EC4DOCK_SERVERNAME:-ec4docker}
EC4DOCK_MAXNODES=${EC4DOCK_MAXNODES:-4}
EC4DOCK_FRONTEND_IMAGENAME=${EC4DOCK_FRONTEND_IMAGENAME:-ec4docker:frontend}
EC4DOCK_WN_IMAGENAME=${EC4DOCK_WN_IMAGENAME:-ec4docker:wn}
EC4DOCK_NODEBASENAME=${EC4DOCK_NODEBASENAME:-ec4docknode}
# We'll try to terminate the cluster if it exists
if [ "$ASSUME_YES" == "True" ]; then
$(dirname $0)/terminate-cluster -f $CONFIG_FILE -y
else
$(dirname $0)/terminate-cluster -f $CONFIG_FILE
fi
# We execute the container
# - we have to run it in privileged mode because of torque requirements
docker run -p 22 --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/bin/docker -e "EC4DOCK_FRONTEND_IMAGENAME=$EC4DOCK_FRONTEND_IMAGENAME" -e "EC4DOCK_WN_IMAGENAME=$EC4DOCK_WN_IMAGENAME" -e "EC4DOCK_SERVERNAME=$EC4DOCK_SERVERNAME" -e "EC4DOCK_MAXNODES=$EC4DOCK_MAXNODES" -e "EC4DOCK_NODEBASENAME=$EC4DOCK_NODEBASENAME" -h $EC4DOCK_SERVERNAME --name $EC4DOCK_SERVERNAME -id $EC4DOCK_FRONTEND_IMAGENAME
if [ "$DEPLOY_NODES" == "True" ]; then
echo "waiting a bit to deploy the frontend"
sleep 10s
for n in $(seq 1 $EC4DOCK_MAXNODES); do
NODENAME=${EC4DOCK_NODEBASENAME}${n}
echo -n "starting node $NODENAME ..."
docker exec $EC4DOCK_SERVERNAME /opt/ec4docker/poweron $NODENAME > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
echo -e "[\e[32msucceeded\e[0m]"
else
echo -e "[\e[31mfailed\e[0m]"
fi
done
fi
exit 0