forked from appsembler/openedx-azure-scalable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-openedx.sh
165 lines (142 loc) · 4.95 KB
/
configure-openedx.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
#!/bin/bash
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT license. See LICENSE file on the project webpage for details.
# print commands and arguments as they are executed
set -x
echo "Starting Open edX scalable multiserver install on pid $$"
date
ps axjf
#############
# Parameters
#############
AZUREUSER=$1
PASSWORD=$2
NUM_SERVERS=$3
HOMEDIR="/home/$AZUREUSER"
VMNAME=`hostname`
echo "User: $AZUREUSER"
echo "User home dir: $HOMEDIR"
echo "vmname: $VMNAME"
###################
# Common Functions
###################
ensureAzureNetwork()
{
# ensure the host name is resolvable
hostResolveHealthy=1
for i in {1..120}; do
host $VMNAME
if [ $? -eq 0 ]
then
# hostname has been found continue
hostResolveHealthy=0
echo "the host name resolves"
break
fi
sleep 1
done
if [ $hostResolveHealthy -ne 0 ]
then
echo "host name does not resolve, aborting install"
exit 1
fi
# ensure the network works
networkHealthy=1
for i in {1..12}; do
wget -O/dev/null http://bing.com
if [ $? -eq 0 ]
then
# hostname has been found continue
networkHealthy=0
echo "the network is healthy"
break
fi
sleep 10
done
if [ $networkHealthy -ne 0 ]
then
echo "the network is not healthy, aborting install"
ifconfig
ip a
exit 2
fi
}
ensureAzureNetwork
###################################################
# Configure SSH keys
###################################################
time sudo apt-get -y update && sudo apt-get -y upgrade
sudo apt-get -y install sshpass
ssh-keygen -f $HOMEDIR/.ssh/id_rsa -t rsa -N ''
#copy ssh key to all app servers (including localhost)
for i in `seq 0 $(($NUM_SERVERS-1))`; do
cat $HOMEDIR/.ssh/id_rsa.pub | sshpass -p $PASSWORD ssh -o "StrictHostKeyChecking no" [email protected]$i 'cat >> .ssh/authorized_keys && echo "Key copied Appserver #$i"'
done
#terrible hack for getting keys onto db server
cat $HOMEDIR/.ssh/id_rsa.pub | sshpass -p $PASSWORD ssh -o "StrictHostKeyChecking no" [email protected] 'cat >> .ssh/authorized_keys && echo "Key copied MySQL"'
cat $HOMEDIR/.ssh/id_rsa.pub | sshpass -p $PASSWORD ssh -o "StrictHostKeyChecking no" [email protected] 'cat >> .ssh/authorized_keys && echo "Key copied MongoDB"'
#make sure premissions are correct
sudo chown -R $AZUREUSER:$AZUREUSER $HOMEDIR/.ssh/
###################################################
# Update Ubuntu and install prereqs
###################################################
time sudo apt-get -y update && sudo apt-get -y upgrade
time sudo apt-get install -y build-essential software-properties-common python-software-properties curl git-core libxml2-dev libxslt1-dev libfreetype6-dev python-pip python-apt python-dev libxmlsec1-dev swig
time sudo pip install pip==7.1.2
time sudo pip install --upgrade virtualenv
###################################################
# Pin specific version of Open edX (named-release/cypress for now)
###################################################
export OPENEDX_RELEASE='named-release/cypress'
cat >/tmp/extra_vars.yml <<EOL
---
edx_platform_version: "$OPENEDX_RELEASE"
certs_version: "$OPENEDX_RELEASE"
forum_version: "$OPENEDX_RELEASE"
xqueue_version: "$OPENEDX_RELEASE"
configuration_version: "appsembler/azureDeploy"
edx_ansible_source_repo: "https://github.com/chenriksson/configuration"
EOL
###################################################
# Set database vars
###################################################
cat >/tmp/db_vars.yml <<EOL
---
EDXAPP_MYSQL_USER_HOST: "%"
EDXAPP_MYSQL_HOST: "10.0.0.20"
EDXLOCAL_MYSQL_BIND_IP: "0.0.0.0"
XQUEUE_MYSQL_HOST: "10.0.0.20"
ORA_MYSQL_HOST: "10.0.0.20"
MONGO_BIND_IP: "0.0.0.0"
FORUM_MONGO_HOSTS: ["10.0.0.30"]
EDXAPP_MONGO_HOSTS: ["10.0.0.30"]
EDXAPP_MEMCACHE: ["10.0.0.20:11211"]
MEMCACHED_BIND_IP: "0.0.0.0"
EOL
###################################################
# Download configuration repo and start ansible
###################################################
cd /tmp
time git clone https://github.com/chenriksson/configuration.git
cd configuration
time git checkout appsembler/azureDeploy
time sudo pip install -r requirements.txt
cd playbooks/appsemblerPlaybooks
#create inventory.ini file
echo "[mongo-server]" > inventory.ini
echo "10.0.0.30" >> inventory.ini
echo "" >> inventory.ini
echo "[mysql-server]" >> inventory.ini
echo "10.0.0.20" >> inventory.ini
echo "" >> inventory.ini
echo "[edxapp-primary-server]" >> inventory.ini
echo "localhost" >> inventory.ini
echo "" >> inventory.ini
echo "[edxapp-additional-server]" >> inventory.ini
for i in `seq 1 $(($NUM_SERVERS-1))`; do
echo "10.0.0.1$i" >> inventory.ini
done
curl https://raw.githubusercontent.com/chenriksson/openedx-azure-scalable/master/server-vars.yml > /tmp/server-vars.yml
sudo ansible-playbook -i inventory.ini -u $AZUREUSER --private-key=$HOMEDIR/.ssh/id_rsa multiserver_deploy.yml -e@/tmp/server-vars.yml -e@/tmp/extra_vars.yml -e@/tmp/db_vars.yml
date
echo "Completed Open edX multiserver provision on pid $$"