-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·270 lines (249 loc) · 10.7 KB
/
install.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
_usage() {
echo "##### U S A G E : Help and ERROR ######"
echo "$0 $Options"
echo "*"
echo " Usage: $0 <[options]>"
echo " Options:"
echo " -a --atmosphere_only Execute crushbone to install Troposphere components ONLY."
echo " -h --help Show this message"
echo " -t --troposphere_only Execute crushbone to install Troposphere components ONLY."
echo " -T --test Execute crushbone in 'test' mode. Useful for jenkins"
echo ""
echo " -b --branch= Override git branch name in configuration file"
echo " -D --working_dir= Override source code dir in configuration file"
echo " -E --virtualenv= Override environment dir in configuration file"
echo " -s --server_name= Override server name in configuration file"
echo " --setup_files_dir= Set the directory containing setup files"
echo " --ssh_key_dir= Set the directory containing ssh key-related files"
echo " --db_name= Set the database name to be used on installation"
echo " --db_user= Set the database user to be used on installation"
echo " --db_pass= Set the database password to be used on installation"
echo ""
if [ "$1" != "" ]; then
echo "USAGE ERROR: $1"
fi
exit
}
_swap_variables() {
install_atmo=${install_atmo:-false}
install_tropo=${install_tropo:-false}
test_only=${test_only:-false}
db_name=${db_name:-${DBNAME:-"atmo_prod"}}
db_user=${db_user:-${DBUSER:-"atmo_app"}}
db_pass=${db_pass:-${DBPASS:-"atmosphere"}}
branch_name=${branch_name:-${BRANCH_NAME:-"master"}}
server_name=${server_name:-${SERVERNAME:-"localhost"}}
working_dir=${working_dir:-${WORKSPACE:-"/opt/dev"}}
virtualenv_dir=${virtualenv_dir:-${VIRTUALENV:-"/opt/env"}}
setup_files_dir=${setup_files_dir:-${LOCATIONOFSETUPFILE:-"/root"}}
ssh_key_dir=${ssh_key_dir:-${SSH_KEY_DIR:-"/root"}}
}
_derived_variables() {
#Variables for Atmosphere
if [[ "$install_atmo" = "true" && "$install_tropo" = "true" ]]; then
# BOTH Atmosphere and troposphere are being installed, so the environment will be generalized.
# In this case we need to append names to each virtualenv.
atmo_working_dir="$working_dir/atmosphere"
atmo_virtualenv="$virtualenv_dir/atmo"
tropo_working_dir="$working_dir/troposphere"
tropo_virtualenv="$virtualenv_dir/troposphere"
elif [[ "$install_atmo" = "true" ]]; then
atmo_working_dir="$working_dir"
atmo_virtualenv="$virtualenv_dir"
tropo_working_dir="N/A"
tropo_virtualenv="N/A"
elif [[ "$install_tropo" = "true" ]]; then
atmo_working_dir="N/A"
atmo_virtualenv="N/A"
tropo_working_dir="$working_dir/troposphere"
tropo_virtualenv="$virtualenv_dir/troposphere"
fi
#Variables derived from virtualenv/working_dir:
if [[ "$install_atmo" = "true" ]]; then
atmo_logs_dir="$atmo_working_dir/logs"
atmo_files_dir="$setup_files_dir"
else
atmo_logs_dir="N/A"
atmo_files_dir="N/A"
fi
if [[ "$install_tropo" = "true" ]]; then
tropo_logs_dir="$tropo_working_dir/logs"
tropo_files_dir="$setup_files_dir/tropo"
else
tropo_logs_dir="N/A"
tropo_files_dir="N/A"
fi
ssh_keys_storage_dir="$ssh_key_dir/.ssh"
host_name=$(sed -E 's/^((ftp|www)\.)?([^.]*)\..*/\3/' <<< "$server_name")
}
main() {
Options=$@
OptNum=$#
## Source the configuration variables
mkdir -p logs
. src/01_configurationVariables.sh
## Initialize command line vars
install_atmo=true
install_tropo=true
test_only=false
jenkins=false
branch_name=""
working_dir=""
virtualenv_dir=""
ssh_key_dir=""
setup_files_dir=""
server_name=""
## Collect command line vars
while getopts ':atT-b:D:E:s:' OPTION ; do
case "$OPTION" in
a ) install_tropo=false ;;
b ) branch_name="$OPTARG" ;;
D ) working_dir="$OPTARG" ;;
E ) virtualenv_dir="$OPTARG" ;;
h ) _usage ;;
j ) jenkins=true ;;
s ) server_name="$OPTARG" ;;
t ) install_atmo=false ;;
T ) test_only=true ;;
- ) [ $OPTIND -ge 1 ] && optind=$(expr $OPTIND - 1 ) || optind=$OPTIND
eval OPTION="\$$optind"
OPTARG=$(echo $OPTION | cut -d'=' -f2)
OPTION=$(echo $OPTION | cut -d'=' -f1)
case $OPTION in
--atmosphere_only ) install_tropo=false ;;
--branch ) branch_name="$OPTARG" ;;
--jenkins) jenkins=true ;;
--working_dir ) working_dir="$OPTARG" ;;
--ssh_key_dir ) ssh_key_dir="$OPTARG" ;;
--setup_files_dir ) setup_files_dir="$OPTARG" ;;
--virtualenv ) virtualenv_dir="$OPTARG" ;;
--help ) _usage ;;
--server_name ) server_name="$OPTARG" ;;
--troposphere_only ) install_atmo=false ;;
--test ) test_only=true ;;
--db_user ) db_user="$OPTARG" ;;
--db_name ) db_name="$OPTARG" ;;
--db_pass ) db_pass="$OPTARG" ;;
* ) _usage " Unknown long option provided: $OPTION:$OPTARG" ;;
esac
OPTIND=1
shift
;;
? ) _usage " Unknown short option provided: $OPTION:$OPTARG" ;;
esac
done
echo $branch_name
_swap_variables
_derived_variables
echo $branch_name
echo "---------------------------------------------------"
echo "Your Configuration:"
echo "Jenkins Rebuild: $jenkins"
echo "Test Mode: $test_only"
echo "Branch Name: $branch_name"
echo "Server Name: $server_name"
echo "Install Atmosphere: $install_atmo"
echo "Atmosphere Source Code Dir: $atmo_working_dir"
echo "Atmosphere Environment Dir: $atmo_virtualenv"
echo "Atmosphere Setup Files Dir: $atmo_files_dir"
echo "Install Troposphere: $install_tropo"
echo "Troposphere Source Code Dir: $tropo_working_dir"
echo "Troposphere Environment Dir: $tropo_virtualenv"
echo "Troposphere Setup Files Dir: $tropo_files_dir"
echo "---------------------------------------------------"
echo -n "Ctrl+C to exit and change your configuration...3..."
sleep 1
echo -n "2..."
sleep 1
echo -n "1..."
sleep 1
echo "Executing build."
}
install_dependencies() {
./src/02_dependencies.sh
./src/03_pip_install.sh
}
build_troposphere() {
echo "These commands will be run when Troposphere should be installed"
. src/15_troposphere_virtual_env.sh $tropo_virtualenv
. src/16_troposphere_setup.sh $tropo_working_dir $tropo_virtualenv $tropo_files_dir $server_name $branch_name
. src/14_virtual_env_deactivate.sh
. src/19_troposphere_new_relic.sh $setup_files_dir $tropo_working_dir
}
build_atmosphere() {
echo "These commands will be run when Atmosphere should be installed"
./src/04_postgres.sh $db_name $db_user $db_pass
./src/05_setuptools.sh
. ./src/06_atmo_virtual_env.sh $atmo_virtualenv
./src/07_atmo_git_clone.sh $atmo_working_dir $branch_name
./src/08_atmo_setup.sh $setup_files_dir $atmo_working_dir $atmo_logs_dir $atmo_virtualenv $server_name $db_name $db_user $db_pass
./src/09_pip_install_atmo_requirements.sh $atmo_working_dir $atmo_virtualenv $jenkins $test_only
./src/10_atmo_python_db_migrations.sh $atmo_working_dir $atmo_virtualenv
. src/14_virtual_env_deactivate.sh
./src/18_atmo_setup_new_relic.sh $setup_files_dir $atmo_working_dir
}
build_production_server() {
./src/11_apache_configuration.sh $atmo_working_dir $atmo_virtualenv $tropo_working_dir $server_name
./src/12_ssl_configuration.sh $atmo_working_dir $ssh_key_dir
./src/13_start_atmosphere.sh "apache" $atmo_working_dir
./src/17_celery_setup.sh $atmo_working_dir
./src/13_start_atmosphere.sh "atmosphere" $atmo_working_dir
}
atmo_rebuild_jenkins() {
#Jenkins already has postgresql setup properly
#Jenkins already has atmosphere cloned in the correct workspace
. ./src/06_atmo_virtual_env.sh $atmo_virtualenv
./src/08_atmo_setup.sh $setup_files_dir $atmo_working_dir $atmo_logs_dir $atmo_virtualenv $server_name $db_name $db_user $db_pass
./src/09_pip_install_atmo_requirements.sh $atmo_working_dir $atmo_virtualenv $jenkins $test_only
./src/10_atmo_python_db_migrations.sh $atmo_working_dir $atmo_virtualenv
#Jenkins already has the correct apache settings, no overwrites
#required
. src/14_virtual_env_deactivate.sh
./src/17_celery_setup.sh $atmo_working_dir
./src/13_start_atmosphere.sh "atmosphere" $atmo_working_dir
}
tropo_rebuild_jenkins() {
#TODO: Find out if we need to do anything special here..
echo "Building Troposphere-Jenkins"
. src/16_troposphere_setup.sh $tropo_working_dir $tropo_virtualenv $tropo_files_dir $server_name $branch_name true
}
run_steps() {
#NOTE: The dependencies could be split out for tropo/atmo later on..
#FIXME: Using . relative paths will lead to issues finding correct paths
# when executed outside of the 'crushbone' directory.
#FIXME: instead of exit 0 we should track $? for non-zero and always bubble
# up non-zero when they are encountered so jenkins/script knows a
# non-standard install occurred..
install_dependencies
if [[ "$jenkins" = "true" && "$install_atmo" = "true" ]]; then
echo "Rebuilding Jenkins on Atmosphere"
atmo_rebuild_jenkins
return 0
elif [[ "$jenkins" = "true" && "$install_tropo" = "true" ]]; then
echo "Rebuilding Jenkins on Troposphere"
tropo_rebuild_jenkins
return 0
fi
#Troposphere has no dependency on atmosphere, so build it first
if [ "$install_tropo" = "true" ]; then
echo "Building Troposphere"
build_troposphere
fi
if [ "$install_atmo" = "true" ]; then
echo "Building Atmosphere"
build_atmosphere
fi
#ONLY create apache/SSL configurations if atmosphere AND troposphere is being built AND we are
# building server for a non-test run
#TODO: A secret file for 'atmo_only' Vs. 'tropo_only' Vs. 'atmo & tropo'
if [[ "$test_only" = "false" && "$install_tropo" = "true" && "$install_atmo" = "true" ]]
then
echo "Building Production Server"
build_production_server
fi
return 0
}
#EXECUTION PATH:
main "$@"
run_steps