-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-compute
executable file
·58 lines (47 loc) · 1.98 KB
/
run-compute
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
#!/bin/bash
#
# Copyright 2010 Jeremy Schneider
#
# This file is part of EC2-RAC-BUILDER.
#
# EC2-RAC-BUILDER is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# EC2-RAC-BUILDER is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EC2-RAC-BUILDER. If not, see <http://www.gnu.org/licenses/>.
#
#
[ -n "$DEBUG" ] && set -x
[ -z "$2" ] && { echo "Usage: run-compute <cluster#> <#nodes> [<net-id-start>]" && exit 1; }
[ $1 -gt 0 ] || { echo "ERROR: cluster# must be number greater than 0" && exit 1; }
[ $2 -gt 0 ] || { echo "ERROR: #nodes must be between 1 and 20" && exit 1; };
[ $2 -lt 21 ] || { echo "ERROR: #nodes must be between 1 and 20" && exit 1; };
[ -n "$3" ] && { [ $3 -gt 0 ] || { echo "ERROR: net-id-start must be between 1 and 20" && exit 1; }; };
[ -n "$3" ] && { [ $3 -lt 21 ] || { echo "ERROR: net-id-start must be between 1 and 20" && exit 1; }; };
echo "starting" >&2
. $(dirname $0)/env
echo 0 > /tmp/amazon/cluster$1-compute
RUNOUT="$(ec2run -z $EC2_ZONE -t m1.small -k $EC2_KEY -n $2 ami-d7d43abe)"
echo "$RUNOUT"
INST=$(echo "$RUNOUT"|awk '/^INSTANCE/{print$2}')
ec2tag $INST -t "Name=c$1-compute" -t "Cluster=$1" -t "Function=compute" &
I_PIDS=""
NET_ID=${3:-1}
for I in $INST; do
$(dirname $0)/init-compute-node $I $NET_ID &
I_PIDS="$I_PIDS $!"
NET_ID=$((NET_ID + 1))
[ $NET_ID -gt 20 ] && break
done
# $! is PID of most recently executed bg job
# ps h list_of_pids will give 1 line for each running process, empty when they all complete
until [ -z "$(ps h $I_PIDS)" ]; do sleep 5; done
echo 1 > /tmp/amazon/cluster$1-compute
echo "finished" >&2