-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartscript.sh
187 lines (158 loc) · 5.17 KB
/
startscript.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
#!/bin/bash
usage () {
echo "Usage:
docker run <container> [help|list|test-experiments|start]
docker run -p 80:80 -v /tmp/data:/scif/data <container> start
Headless Mode (requires token)
docker run -p 80:80 -d --name experiments -v /tmp/data:/scif/data <container> --headless start
docker exec experiments expfactory users 3
Commands:
help: show help and exit
list: list installed experiments
lib: list experiments in the library
test: test experiments installed in container
start: start the container to do the experiments*
env: search for an environment variable set in the container
*you are required to map port 80, otherwise you won't see the portal at localhost
Options [start]:
--db: specify a database url to override the default filesystem
[sqlite|mysql|postgresql]:///
--vars: specify an experiment variables file
--delim: specify a delimiter for the variables file (default is csv)
--studyid: specify a studyid to override the default
--randomize: select experiment order at random
--no-randomize: select experiment order manually in the GUI
--experiments: a comma separated list of experiments (manual ordering)
Examples:
docker run <container> test
docker run <container> list
docker run <container> start
docker run -p 80:80 <container> --database mysql+pymysql://username:password@host/dbname start
docker run -p 80:80 <container> --database sqlite start
docker run -p 80:80 <container> --database postgresql://username:password@host/dbname start
"
}
if [ $# -eq 0 ]; then
usage
exit
fi
EXPFACTORY_START="no"
EXPFACTORY_DATABASE="filesystem"
while true; do
case ${1:-} in
-h|--help|help)
usage
exit
;;
--database|--db)
shift
EXPFACTORY_DATABASE=${1:-}
export EXPFACTORY_DATABASE
shift
;;
--delim|delim)
shift
EXPFACTORY_RUNTIME_DELIM=${1:-}
shift
export EXPFACTORY_RUNTIME_DELIM
;;
--env|env)
shift
env | grep ${1:-}
exit
;;
-e|experiments|--experiments)
shift
EXPFACTORY_EXPERIMENTS="${1:-}"
shift
export EXPFACTORY_EXPERIMENTS
;;
--headless|headless)
shift
EXPFACTORY_HEADLESS="true"
export EXPFACTORY_HEADLESS
;;
--lib)
echo "Experiments in the library:"
expfactory list
echo
exit
;;
-ls|--list|list)
echo "Experiments in this image:"
ls /scif/apps -1
echo
exit
;;
--randomize)
shift
EXPFACTORY_RANDOM="true"
export EXPFACTORY_RANDOM
;;
--no-randomize)
shift
EXPFACTORY_RANDOM="false"
export EXPFACTORY_RANDOM
;;
-s|--start|start)
EXPFACTORY_START="yes"
shift
;;
--studyid)
shift
EXPFACTORY_STUDY_ID=${1:-}
echo "Study ID selected as ${EXPFACTORY_STUDYID}"
export EXPFACTORY_STUDY_ID
shift
;;
-test-experiments|--te|test)
cd /opt/expfactory/expfactory/templates/build
exec python3 -m unittest tests.test_experiment
exit
;;
--vars|vars)
shift
EXPFACTORY_RUNTIME_VARS=${1:-}
shift
if [ -f "${EXPFACTORY_RUNTIME_VARS}" ]; then
echo "Found Variable File: ${EXPFACTORY_RUNTIME_VARS}"
export EXPFACTORY_RUNTIME_VARS
else
echo "WARNING: Cannot find ${EXPFACTORY_RUNTIME_VARS}"
fi
;;
-*)
echo "Unknown option: ${1:-}"
exit 1
;;
*)
break
;;
esac
done
# Are we starting the server?
if [ "${EXPFACTORY_START}" == "yes" ]; then
echo "Database set as ${EXPFACTORY_DATABASE}"
export EXPFACTORY_DATABASE
echo "Starting Web Server"
echo
service nginx start
touch /scif/logs/gunicorn.log
touch /scif/logs/gunicorn-access.log
tail -n 0 -f /scif/logs/gunicorn*.log &
exec gunicorn expfactory.wsgi:app \
--bind 0.0.0.0:5000 \
--name expfactory_experiments
--workers 5
--log-level=info
--log-file=/scif/logs/gunicorn.log \
--access-logfile=/scif/logs/gunicorn-access.log \
"$@" & service nginx restart
# simple manual command could be
# service nginx start
# gunicorn --bind 0.0.0.0:5000 expfactory.wsgi:app
#service nginx restart
# Keep container running if we get here
tail -f /dev/null
exit
fi