-
Notifications
You must be signed in to change notification settings - Fork 50
/
django-entrypoint.sh
executable file
·81 lines (71 loc) · 1.5 KB
/
django-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
#!/bin/sh
pid=0
_exit=0
shutdown() {
echo "Got signal ${*}" >&2
_exit=1
if [ 0 -ne ${pid} ]
then
kill "-${1:-INT}" ${pid}
case "${1:-INT}" in
"HUP"|"FPE"|"SEGV"|"USR1"|"USR2")
echo "Non terminal signal received." >&2
_exit=0
;;
*)
echo "Waiting for child process ${pid} to exit." >&2
wait ${pid}
echo "Child exited. Bye." >&2
exit 0
;;
esac
else
echo "No specific child PID known. Terminating all." >&2
killall -INT
echo "Waiting for all children to exit." >&2
wait
exit 1
fi
}
for sig in HUP INT QUIT FPE SEGV TERM USR1 USR2
do
trap "shutdown ${sig}" "${sig}"
done
# determine about-to-run proccess
case "${1}x" in
/*)
echo "Absolute command given. Replacing Entrypoint with ${*}" >&2
exec ${@}
# if we reach here, something wicked happened, therefore we exit
exit 1
;;
*)
if [ -z "${1}" ]
then
set -- /usr/sbin/uwsgi --ini uwsgi.ini
else
set -- python3 manage.py "${@}"
fi
;;
esac
if [ -z "${NO_CHECK}" ]
then
echo "Checking django database connection." >&2
python3 manage.py check_db_connection --sleep 5 --count 5
retval=$?
if [ 0 -ne ${retval} ]
then
exit ${retval}
fi
fi
echo "Starting main command ${*}" >&2
"${@}" &
pid=$!
echo "Waiting for children to finish." >&2
while [ 0 -eq ${_exit} ]
do
wait
_exit=1
done
echo "End of entrypoint. Bye." >&2
exit 0