-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
98 lines (79 loc) · 2.09 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
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
#!/bin/bash
# Initialize option variables
WITH_CELERY_BEAT=""
WITH_KERBEROS=false
WITH_INIT=false
WITH_LOGGING=false
WITHOUT_APP_SERVER=false
WITH_DB_MIGRATION=false
# Parse options using getopts
while getopts "bkilnd" opt; do
case $opt in
b)
WITH_CELERY_BEAT="-B"
;;
k)
WITH_KERBEROS=true
;;
i)
WITH_INIT=true
;;
l)
WITH_LOGGING=true
;;
n)
WITHOUT_APP_SERVER=true
;;
d)
WITH_DB_MIGRATION=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# Shift off the options and optional --.
shift "$((OPTIND-1))"
set -e
mkdir -p log
sudo sed -i s/{{BACK_HOST}}/"$BACK_HOST"/g /etc/nginx/nginx.conf;
sudo service nginx restart
source "$VIRTUAL_ENV"/bin/activate
if [ "$WITH_DB_MIGRATION" = true ]; then
python manage.py migrate --database="default"
fi
if [ "$WITH_INIT" = true ]; then
set +e
python manage.py load_initial_data --perimeters-conf /perimeters.csv
set -e
fi
if [ "$WITH_KERBEROS" = true ]; then
kinit "$KERBEROS_USER" -k -t akouachi.keytab || echo "kinit failed, continue app launching"
# Cron kerberos token refresh
crontab -l | { cat; echo "0 0 * * */1 /usr/bin/kinit [email protected] -k -t akouachi.keytab"; } | crontab -
sudo service cron start
fi
if [ "$WITH_LOGGING" = true ]; then
python setup_logging.py &
if [ "$WITHOUT_APP_SERVER" = true ]; then
wait -n
fi
fi
if [ "$WITHOUT_APP_SERVER" = false ]; then
python manage.py collectstatic --noinput
celery -A admin_cohort worker $WITH_CELERY_BEAT --loglevel=INFO --logfile=log/celery.log &
sleep 5
# For websockets
daphne -p 8005 admin_cohort.asgi:application &
gunicorn admin_cohort.wsgi --config .conf/gunicorn.conf.py
tail -f log/django.error.log &
# Wait for any process to exit
wait -n
fi
# Exit with status of process that exited first
exit $?