-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit-network-node
executable file
·48 lines (40 loc) · 1.84 KB
/
init-network-node
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
#!/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: init-network-node <instance-id> [ public | private ]" && exit 1; }
[ "$2" != "public" ] && [ "$2" != "private" ] && { echo "ERROR: unrecognized parameter '$2'" && exit 1; }
. $(dirname $0)/env
echo "ec2 load instance" >&2
DOUT="$(ec2din $1)"
ADDR=$(echo "$DOUT"|awk '/running/{print$4}')
while [ -z "$ADDR" ]; do
[ -z "$(echo "$DOUT"|grep ^INSTANCE)" ] && echo "$DOUT" && echo "ERROR - can't find instance '$1'" && exit 1
DOUT="$(ec2din $1)"
ADDR=$(echo "$DOUT"|awk '/running/{print$4}')
done
echo "$DOUT"
echo "boot O.S." >&2
until curl -u vpncubed:$1 -k https://$ADDR:8000/ 2>&1 | grep "Upload runtime snapshot"; do sleep 5; done
echo "configure switch" >&2
TOKEN=$(curl -u vpncubed:$1 -k -c /tmp/amazon/$1.cookie https://$ADDR:8000/snapshot 2>/dev/null | grep "authenticity_token"|sed 's/.*value="\(.*\)".*/\1/')
curl -u vpncubed:$1 -k -b /tmp/amazon/$1.cookie -F snapshot=@snapshot_$2.gz -F authenticity_token=$TOKEN https://$ADDR:8000/snapshot 2>&1
echo "reboot O.S." >&2
until curl -u vpncubed:rac -k https://$ADDR:8000/status 2>&1 | grep "RAC-$2"; do sleep 5; done