-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker-entrypoint.sh
executable file
·62 lines (48 loc) · 1.44 KB
/
docker-entrypoint.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
#!/bin/bash
LOG_FILE=/ebs/logs/enigma.log
CONTAINER_HASH=$(echo $RANDOM | md5sum | head -c 20)
trap ctrl_c INT
pid_to_kill=1
should_continue=0
function ctrl_c() {
echo "===== Stopping Service with pid $pid_to_kill ====="
kill $pid_to_kill
should_continue=1
}
function log() {
echo "$(date): $CONTAINER_HASH $@" 2>&1 | tee -a $LOG_FILE
}
function prepend() {
while read line; do
echo "${line}"
echo "$(date): $CONTAINER_HASH -- ${line}" >> $LOG_FILE
done
}
log "===== Cloning Access Modules ====="
python -m scripts.clone_access_modules 2>&1 | prepend
log "===== Install requirements for access modules ====="
pip install -r Access/access_modules/requirements.txt --no-cache-dir --ignore-installed 2>&1 | prepend
log "===== Ensure DB State ====="
python manage.py createcachetable 2>&1 | prepend
python manage.py migrate 2>&1 | prepend
log "===== Ensure Static Files ====="
python manage.py collectstatic --clear --noinput 2>&1 | prepend
python manage.py collectstatic --noinput 2>&1 | prepend
# directory for gunicorn logs and django app logs
log "===== Ensure Logs ====="
touch /ebs/logs/enigma.log
log "===== Running Service ====="
if [ "$#" -ne 0 ]; then
eval "$@" 2>&1 | prepend
else
echo "===== Starting Webserver ====="
python manage.py runserver --insecure 0.0.0.0:8000 2>&1 &
pid_to_kill=$!
echo "Server PID $pid_to_kill"
while true; do
if [ "$should_continue" -ne 0 ]; then
break
fi
sleep 5
done
fi