forked from mattface/jobserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_run.sh
executable file
·37 lines (30 loc) · 929 Bytes
/
docker_run.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
#!/bin/sh -e
create_flock_script () {
# /usr/bin/flock uses the "flock" call instead of fcntl.
# fcntl is required for NFS shares
cat > /tmp/flock <<EOF
#!/usr/bin/python3
import fcntl
import subprocess
import sys
with open(sys.argv[1], 'a') as f:
fcntl.flock(f, fcntl.LOCK_EX)
subprocess.check_call(sys.argv[2:])
EOF
chmod +x /tmp/flock
}
if [ -n "$FLASK_AUTO_MIGRATE" ] ; then
create_flock_script
echo "Peforming DB migration"
mkdir -p $(dirname $FLASK_AUTO_MIGRATE)
/tmp/flock $FLASK_AUTO_MIGRATE flask db upgrade heads
fi
# if FLASK_DEBUG is defined, we'll run via flask with dynamic reloading of
# code changes to disk. This is helpful for debugging something already in k8s
if [ -z "$FLASK_DEBUG" ] ; then
if [ -n "$STATSD_HOST" ] ; then
STATSD="--statsd-host $STATSD_HOST"
fi
exec /usr/bin/gunicorn $STATSD -n jobserv -w4 -b 0.0.0.0:8000 $FLASK_APP
fi
exec /usr/bin/flask run -h 0.0.0.0 -p 8000