forked from Arjun-Chaudhary/projectGreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
190 lines (135 loc) · 4.2 KB
/
main.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#CCC2016-1, Melbourne, ARJUN CHAUDHARY, 727553
#CCC2016-1, Melbourne, HARSHIT KAPOOR, 666810
#CCC2016-1, Melbourne, LUPIYA MUJALA, 610273
#CCC2016-1, Melbourne, Templeton Tsai, 723957
#CCC2016-1, Melbourne, MUHAMMAD UMER ALTAF, 778566
root_dir=$(pwd)
ssh_public_key="cloud.key"
ssh_public_key_path=$root_dir/$ssh_public_key
master_node=""
instance_num=1
EC2_ACCESS_KEY=be15849f4a08410695bd961bb1b6f3a0
EC2_SECRET_KEY=bd0621e269dd4eb28a2e30840e25e050
checkPackages() {
#Checking if ansible exists or not
command -v ansible-playbook >/dev/null || { echo "ansible-playbook command not found."; exit 1;}
#Checking if python exists or not
command -v python >/dev/null || { echo "python command not found."; exit 1;}
#Checking if python exists or not
command -v sed >/dev/null || { echo "sed command not found."; exit 1;}
}
deployInatance() {
EC2_ACCESS_KEY=be15849f4a08410695bd961bb1b6f3a0
EC2_SECRET_KEY=bd0621e269dd4eb28a2e30840e25e050
python boto_main.py $EC2_ACCESS_KEY $EC2_SECRET_KEY $instance_num
}
deployCouchDB() {
#deploy CouchDB
if [ -f $ssh_public_key_path ]; then
echo deploy CouchDB
cd $root_dir/deployCouchDB
sed -i "/- hosts: all/c\- hosts: ${master_node}" couchDB.yml
echo cd to $(pwd)
python deployCouchDB.py -f $ssh_public_key_path -o $master_node
else
echo "cloud.key file doesn't exist, please make sure it is in the project root folder, $(pwd)"
fi
}
deployHarvester() {
cd $root_dir
#deploy tweetHarvester
echo deploy tweetHarvester
cd $root_dir/deployHarvester
echo cd to $(pwd)
python deployHarvester.py -f $ssh_public_key_path -o $master_node -d $dbServer
}
runHarvester() {
cd $root_dir
echo deploy runHarvester
cd $root_dir/deployHarvester
ansible-playbook runHarvester.yml
}
deployDataProcessor() {
cd $root_dir
#deploy dataProcessor
echo deploy dataProcessor
cd $root_dir/deployDataProcessor
echo cd to $(pwd)
python deployDataProcessor.py -f $ssh_public_key_path -o $master_node -d $dbServer
}
runDataProcessor() {
cd $root_dir
echo deploy dataProcessor
cd $root_dir/deployDataProcessor
ansible-playbook runDataProcessor.yml
}
deployFrontend() {
cd $root_dir
#deploy frontend
echo deploy Frontend
cd $root_dir/deployFrontend
echo cd to $(pwd)
python deployFrontend.py -f $ssh_public_key_path -o $master_node -d $dbServer
}
preCheck() {
export ANSIBLE_INVENTORY=$(pwd)/ansible_hosts
checkPackages
}
usage() {
echo "main.sh <options> <instance_num>|<host_dest_ip> <dbServer_ip>"
echo "option 1: deployInatance, main.sh <options> <instance_num> ex: main.sh 1 1"
echo "option 2: deployCouchDB, main.sh <options> <host_dest_ip> ex: main.sh 2 127.0.0.1"
echo "option 3: deployHarvester, main.sh <options> <host_dest_ip> <dbServer_ip> ex: main.sh 3 127.0.0.1 127.0.0.1"
echo "option 4: runHarvester, main.sh <options> <host_dest_ip> <dbServer_ip> ex: main.sh 4 127.0.0.1"
echo "option 5: deployyDataProcessor, main.sh <options> <host_dest_ip> <dbServer_ip> ex: main.sh 5 127.0.0.1 127.0.0.1"
echo "option 6: runDataProcessor, main.sh <options> <host_dest_ip>ex: main.sh 6 127.0.0.1"
echo "option 7: deployFrontend, main.sh <options> <host_dest_ip> <dbServer_ip> ex: main.sh 7 127.0.0.1 1 127.0.0.1"
}
preCheck
deploy_option=$1
if [ "$#" -ne 4 ]
then
if [ "$deploy_option" = "1" ]
then
instance_num=$2
deployInatance
elif [ "$deploy_option" = "2" ]
then
master_node=$2
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
deployCouchDB
elif [ "$deploy_option" = "3" ]
then
master_node=$2
dbServer=$3
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
deployHarvester
elif [ "$deploy_option" = "4" ]
then
master_node=$2
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
runHarvester
elif [ "$deploy_option" = "5" ]
then
master_node=$2
dbServer=$3
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
deployDataProcessor
elif [ "$deploy_option" = "6" ]
then
master_node=$2
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
runDataProcessor
elif [ "$deploy_option" = "7" ]
then
master_node=$2
dbServer=$3
python saveAnsibleFile.py -f $ssh_public_key_path -o $master_node
deployFrontend
else
usage
fi
else
usage
fi