forked from edx/edx-ora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_controller.sh
executable file
·349 lines (268 loc) · 8.16 KB
/
setup_controller.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/usr/bin/env bash
set -e
# posix compliant sanity check
if [ -z $BASH ] || [ $BASH = "/bin/sh" ]; then
echo "Please use the bash interpreter to run this script"
exit 1
fi
trap "ouch" ERR
ouch() {
printf '\E[31m'
cat<<EOL
!! ERROR !!
The last command did not complete successfully,
For more details or trying running the
script again with the -v flag.
Output of the script is recorded in $LOG
EOL
printf '\E[0m'
}
error() {
printf '\E[31m'; echo "$@"; printf '\E[0m'
}
output() {
printf '\E[36m'; echo "$@"; printf '\E[0m'
}
usage() {
cat<<EO
Usage: $PROG [-c] [-h]
-c compile scipy and numpy
-h this
EO
info
}
info() {
cat<<EO
MITx base dir : $BASE
Python dir : $PYTHON_DIR
EO
}
clone_repos() {
cd "$BASE"
if [[ -d "$BASE/edx-ora/.git" ]]; then
output "Pulling grading controller"
cd "$BASE/edx-ora"
git pull
else
output "Cloning grading controller"
if [[ -d "$BASE/edx-ora" ]]; then
mv "$BASE/edx-ora" "${BASE}/edx-ora.bak.$$"
fi
git clone [email protected]:edx/edx-ora.git
fi
# Also need machine learning repo for everything to work properly
cd "$BASE"
if [[ -d "$BASE/ease/.git" ]]; then
output "Pulling ease"
cd "$BASE/ease"
git pull
else
output "Cloning machine learning"
if [[ -d "$BASE/ease" ]]; then
mv "$BASE/ease" "${BASE}/ease.bak.$$"
fi
git clone [email protected]:edx/ease.git
fi
# Also need xqueue for everything to work properly
cd "$BASE"
if [[ -d "$BASE/xqueue/.git" ]]; then
output "Pulling xqueue"
cd "$BASE/xqueue"
git pull
else
output "Cloning xqueue"
if [[ -d "$BASE/xqueue" ]]; then
mv "$BASE/xqueue" "${BASE}/xqueue.bak.$$"
fi
git clone [email protected]:edx/xqueue.git
fi
}
### START
PROG=${0##*/}
BASE="$HOME/mitx_all"
PYTHON_DIR="$BASE/python"
LOG="/var/tmp/install-controller-$(date +%Y%m%d-%H%M%S).log"
# Read arguments
if [[ $EUID -eq 0 ]]; then
error "This script should not be run using sudo or as the root user"
usage
exit 1
fi
ARGS=$(getopt "cvhs" "$*")
if [[ $? != 0 ]]; then
usage
exit 1
fi
eval set -- "$ARGS"
while true; do
case $1 in
-c)
compile=true
shift
;;
-h)
usage
exit 0
;;
--)
shift
break
;;
esac
done
cat<<EO
This script will setup the grading controller.
includes
* Grading controller
* Machine learning
* Dependencies
It will also attempt to install operating system dependencies
with apt(debian) or brew(OSx).
To compile scipy and numpy from source use the -c option
!!! Do not run this script from an existing virtualenv !!!
If you are in a ruby/python virtualenv please start a new
shell.
EO
info
output "Press return to begin or control-C to abort"
read dummy
# Log all stdout and stderr
exec > >(tee $LOG)
exec 2>&1
# Install basic system requirements
mkdir -p $BASE
case `uname -s` in
[Ll]inux)
command -v lsb_release &>/dev/null || {
error "Please install lsb-release."
exit 1
}
distro=`lsb_release -cs`
case $distro in
maya|lisa|natty|oneiric|precise|quantal)
sudo apt-get install git
;;
*)
error "Unsupported distribution - $distro"
exit 1
;;
esac
;;
Darwin)
if [[ ! -w /usr/local ]]; then
cat<<EO
You need to be able to write to /usr/local for
the installation of brew and brew packages.
Either make sure the group you are in (most likely 'staff')
can write to that directory or simply execute the following
and re-run the script:
$ sudo chown -R $USER /usr/local
EO
exit 1
fi
;;
*)
error "Unsupported platform"
exit 1
;;
esac
# Clone MITx repositories
clone_repos
# Install system-level dependencies
bash $BASE/edx-ora/install_system_req.sh
bash $BASE/ease/install_system_req.sh
# Activate Python virtualenv
source $PYTHON_DIR/bin/activate
# compile numpy and scipy if requested
NUMPY_VER="1.6.2"
SCIPY_VER="0.10.1"
if [[ -n $compile ]]; then
output "Downloading numpy and scipy"
curl -sL -o numpy.tar.gz http://downloads.sourceforge.net/project/numpy/NumPy/${NUMPY_VER}/numpy-${NUMPY_VER}.tar.gz
curl -sL -o scipy.tar.gz http://downloads.sourceforge.net/project/scipy/scipy/${SCIPY_VER}/scipy-${SCIPY_VER}.tar.gz
tar xf numpy.tar.gz
tar xf scipy.tar.gz
rm -f numpy.tar.gz scipy.tar.gz
output "Compiling numpy"
cd "$BASE/numpy-${NUMPY_VER}"
python setup.py install
output "Compiling scipy"
cd "$BASE/scipy-${SCIPY_VER}"
python setup.py install
cd "$BASE"
rm -rf numpy-${NUMPY_VER} scipy-${SCIPY_VER}
fi
case `uname -s` in
Darwin)
# on mac os x get the latest distribute and pip
curl http://python-distribute.org/distribute_setup.py | python
pip install -U pip
# need latest pytz before compiling numpy and scipy
pip install -U pytz
pip install numpy
# fixes problem with scipy on 10.8
pip install -e git+https://github.com/scipy/scipy#egg=scipy-dev
;;
esac
output "Installing Controller pre-requirements"
pip install -r $BASE/edx-ora/pre-requirements.txt
output "Installing ML pre-requirements"
pip install -r $BASE/ease/pre-requirements.txt
output "Installing Controller requirements"
# Need to be in the mitx dir to get the paths to local modules right
cd $BASE/edx-ora
pip install -r requirements.txt
output "Installing ml requirements"
# Need to be in the mitx dir to get the paths to local modules right
cd $BASE/ease
pip install -r requirements.txt
output "Installing xqueue requirements"
# Need to be in the mitx dir to get the paths to local modules right
cd $BASE/xqueue
pip install -r requirements.txt
mkdir "$BASE/log" || true
mkdir "$BASE/edx-ora/log" || true
mkdir "$BASE/ease/log" || true
mkdir "$BASE/xqueue/log" || true
touch "$BASE/edx-ora/log/edx.log" || true
touch "$BASE/ease/log/edx.log" || true
touch "$BASE/xqueue/log/edx.log" || true
#Sync controller db
cd $BASE/edx-ora
yes | django-admin.py syncdb --settings=edx_ora.settings --pythonpath=.
yes | django-admin.py migrate --settings=edx_ora.settings --pythonpath=.
#sync xquque db
cd $BASE/xqueue
yes | django-admin.py syncdb --settings=xqueue.settings --pythonpath=.
yes | django-admin.py migrate --settings=xqueue.settings --pythonpath=.
touch "$BASE/auth.json"
echo '{ "USERS": {"lms": "abcd", "xqueue_pull": "abcd"} }' > "$BASE/auth.json"
#Update controller users
cd $BASE/edx-ora
django-admin.py update_users --pythonpath=$BASE/edx-ora --settings=edx_ora.settings
#Update xqueue users
cd $BASE/xqueue
django-admin.py update_users --pythonpath=$BASE/xqueue --settings=xqueue.settings
#Install machine learning nltk stuff
python -m nltk.downloader maxent_treebank_pos_tagger wordnet
### DONE
cat<<END
Success!!
See full instructions below if you run into trouble:
https://edx-wiki.atlassian.net/wiki/display/ENG/Setting+up+Grading+Controller+and+XQueue
Next steps are to point the LMS to the xqueue and grading controller (lms/envs/dev.py),
then run the xqueue and the grading controller on the correct ports:
To start the controller:
$ django-admin.py runserver 127.0.0.1:3033 --settings=edx_ora.settings --pythonpath=$BASE/edx-ora
To start the xqueue:
$ django-admin.py runserver 127.0.0.1:3032 --settings=xqueue.settings --pythonpath=. --pythonpath=$BASE/xqueue
Then start the celery processes associated with the grading controller:
python manage.py celeryd -B --settings = edx_ora.settings --pythonpath=$BASE/edx-ora
If the Django development server starts properly you
should see:
Development server is running at http://127.0.0.1:<port#>/
Quit the server with CONTROL-C.
Connect your browser to http://127.0.0.1:<port#> to
view the Django site.
END
exit 0