-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit-storage-node
executable file
·76 lines (67 loc) · 2.77 KB
/
init-storage-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
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
#!/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-storage-node <instance-id> <nVols> [ -local <sizeGB> | <wait-PIDs> ]" && exit 1; }
[ $2 -gt -1 ] || { echo "ERROR nVols must be between 0 and 8" && exit 1; }
[ $2 -lt 9 ] || { echo "ERROR nVols must be between 0 and 8" && exit 1; }
if [ -n "$3" ]; then
if [ "$3" == "-local" ]; then
[ $4 -gt 0 ] || { echo "ERROR: sizeGB must be number greater than 0" && exit 1; }
else
until [ -z "$(ps h $3)" ]; do sleep 5; done
fi
fi
. $(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 ssh $SSH_OPTS ubuntu@$ADDR date 2>&1; do sleep 5; done
echo "setup iscsi" >&2
DEVS=(sdf sdg sdh sdi sdj sdk sdl sdm)
echo '' >/tmp/amazon/$1.iscsi.tmp
echo '#!/bin/bash' >/tmp/amazon/$1.iscsi
echo 'echo "ISCSITARGET_ENABLE=true" >/etc/default/iscsitarget' >>/tmp/amazon/$1.iscsi
echo 'cat <<EOF >>/etc/iet/ietd.conf' >>/tmp/amazon/$1.iscsi
echo "Target iqn.2006-11.com.ardentperf:storage.$1.17" >>/tmp/amazon/$1.iscsi
VOL=0
while [ $VOL -lt $2 ]; do
if [ "$3" == "-local" ]; then
echo "dd if=/dev/zero of=/mnt/iscsi-${DEVS[$VOL]}.dat bs=1 count=0 seek=${4}G" >>/tmp/amazon/$1.iscsi.tmp
echo " Lun $VOL Path=/mnt/iscsi-${DEVS[$VOL]}.dat,Type=fileio" >>/tmp/amazon/$1.iscsi
else
echo " Lun $VOL Path=/dev/${DEVS[$VOL]},Type=blockio" >>/tmp/amazon/$1.iscsi
fi
VOL=$((VOL + 1))
done
echo 'EOF' >>/tmp/amazon/$1.iscsi
cat /tmp/amazon/$1.iscsi.tmp >> /tmp/amazon/$1.iscsi
ssh $SSH_OPTS ubuntu@$ADDR sudo apt-get -y install iscsitarget 2>&1
scp $SSH_OPTS /tmp/amazon/$1.iscsi ubuntu@$ADDR:/tmp/amazon-iscsi.sh 2>&1
ssh $SSH_OPTS ubuntu@$ADDR sudo chmod +x /tmp/amazon-iscsi.sh 2>&1
ssh $SSH_OPTS ubuntu@$ADDR sudo bash /tmp/amazon-iscsi.sh 2>&1
ssh $SSH_OPTS ubuntu@$ADDR sudo invoke-rc.d iscsitarget restart 2>&1