-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployVM.sh
executable file
·127 lines (116 loc) · 3.39 KB
/
deployVM.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
usage() {
echo "usage: $0 [-z <zookeeper host list, default: dqc:2181>] -n <cluster_name> -h <help message>"
}
ZKLIST=''
while getopts ":z:n:h" opt_char
do
case $opt_char in
z)
ZKLIST=$OPTARG
;;
n)
CLUSTER=$OPTARG
;;
\h)
usage
exit 0
;;
\?)
echo "$OPTARG is not a valid option."
usage
exit
;;
esac
done
if (( $# < 2 )); then
echo "You must provide the cluster configuration path."
usage
exit
fi
CFGDIR="/var/lib/rapids/cfg/clusters/$CLUSTER"
echo "CLUSTER: $CLUSTER"
if [[ ! (-d ${CFGDIR}) ]]; then
echo "The provided path is not correct, fix the problem and rerun the script."
exit
elif [[ ! ( -e $CFGDIR/cluster.csv && -f $CFGDIR/cluster.csv ) ]]; then
echo "There is no cluster.cfg file in provided directory."
exit
fi
declare -A templist
for line in `cat template.lst`
do
KEY=`echo $line | cut -d: -f1`
VALUE=`echo $line | cut -d: -f2`
templist[${KEY}]=${VALUE}
done
find $CFGDIR -type f \( -name *.cmd \) -exec rm {} +
echo "Generating container deployment instructions for each joining VM host..."
while IFS=, read HOST IP MASK CPU MEM RDPROLE DSTYPE DSROLE VMHOST
do
case $RDPROLE in
none)
if [[ $DSTYPE == "memsql" && $DSROLE == "master" ]]; then
TEMPLATE=${templist["memsql"]}
else
TEMPLATE=${templist["bare"]}
fi
;;
dqc)
if [[ $DSROLE == "master" && $RDPROLE == "dqc" ]]; then
TEMPLATE=${templist["rdpmemsql"]}
else
TEMPLATE=${templist["rdp"]}
fi
;;
dqe)
TEMPLATE=${templist["rdp"]}
;;
esac
if [[ $RDPROLE == "dqc" ]]; then
if [[ $ZKLIST=="" ]]; then
sed 's/localhost/'"$IP"'/' template/zk.config.sample > zk.config
else
sed 's/localhost/'"$ZKLIST"'/' template/zk.config.sample > zk.config
fi
mv zk.config $CFGDIR
fi
VCPU=`expr $CPU \* 100`
echo "setup_lxc.sh -d $CLUSTER -n $HOST -i $IP -m $MASK -c $VCPU -M $MEM -t $TEMPLATE" >> $CFGDIR/${VMHOST}.cmd
done < $CFGDIR/cluster.csv
# Prepare RapidsDB cluster configuration file for RapidsDB cluster
grep rapidsdb $CFGDIR/cluster.type > /dev/null
if (( $? == 0 )); then
echo "Generating RapidsDB configuration file"
python mk_rdpConfig.py $CFGDIR/rdp.cluster
mv cluster.config $CFGDIR
fi
# Copy specific config files to remote VM hosts
REMOTE_ROOT="/var/lib/rapids/cfg/clusters/${CLUSTER}"
echo "Remote root: $REMOTE_ROOT"
for VMHOST in `cat $CFGDIR/vhost.lst`
do
echo "Processing $VMHOST..."
if [[ -e $CFGDIR/$VMHOST.cmd ]]; then
mv $CFGDIR/$VMHOST.cmd $CFGDIR/install_container.cmd
chmod +x $CFGDIR/install_container.cmd
ssh $VMHOST "if [[ ! (-d $REMOTE_ROOT) ]]; then mkdir -p $REMOTE_ROOT; fi"
pdcp -w $VMHOST $CFGDIR/install_container.cmd $CFGDIR/hosts $REMOTE_ROOT
grep rapidsdb $CFGDIR/cluster.type > /dev/null
if (( $? == 0 )); then
if [[ -e $CFGDIR/cluster.config ]]; then
pdcp -w $VMHOST $CFGDIR/cluster.config $REMOTE_ROOT
elif [[ -e $CFGDIR/zk.config ]]; then
pdcp -w $VMHOST $CFGDIR/zk.config $REMOTE_ROOT
fi
fi
fi
done
echo "The deployment script for all VM Hosts are ready"
for vhost in `cat $CFGDIR/vhost.lst`
do
pdsh -w $vhost "cd /var/lib/rapids/cfg/clusters/$CLUSTER; ./install_container.cmd"
done
echo
echo
echo "The containers for cluster $CLUSTER is finished deployment, you may still need to run further configuration tools to finish the application configuration."