-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·80 lines (73 loc) · 2.35 KB
/
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
#!/bin/bash
export GUNICORN_APP=${GUNICORN_APP:-"nexus.asgi"}
export GUNICORN_CONF=${GUNICORN_CONF:-"${APP_PATH}/gunicorn.conf.py"}
export GUNICORN_LOG_CONF=${GUNICORN_LOG_CONF:-"${APP_PATH}/gunicorn-logging.conf"}
export LOG_LEVEL=${LOG_LEVEL:-"INFO"}
export CELERY_APP=${CELERY_APP:-"nexus.celery"}
export CELERY_MAX_WORKERS=${CELERY_MAX_WORKERS:-'6'}
export HEALTHCHECK_TIMEOUT=${HEALTHCHECK_TIMEOUT:-"10"}
#export GUNICORN_CONF=${GUNICORN_CONF:-"python:app.gunicorn"
do_gosu(){
user="$1"
shift 1
is_exec="false"
if [ "$1" = "exec" ]; then
is_exec="true"
shift 1
fi
if [ "$(id -u)" = "0" ]; then
if [ "${is_exec}" = "true" ]; then
exec gosu "${user}" "$@"
else
gosu "${user}" "$@"
return "$?"
fi
else
if [ "${is_exec}" = "true" ]; then
exec "$@"
else
eval '"$@"'
return "$?"
fi
fi
}
if [[ "start-wsgi" == "$1" ]]; then
echo "starting server"
do_gosu "${APP_USER}:${APP_GROUP}" python manage.py collectstatic --noinput
echo "collectstatic runned start gunicorn"
do_gosu "${APP_USER}:${APP_GROUP}" exec gunicorn "${GUNICORN_APP}" \
--name="${APP_NAME}" \
--chdir="${APP_PATH}" \
--bind=0.0.0.0:8000 \
--log-config="${GUNICORN_LOG_CONF}" \
-c "${GUNICORN_CONF}"
elif [[ "start" == "$1" ]]; then
do_gosu "${APP_USER}:${APP_GROUP}" exec daphne -b 0.0.0.0 -p 8000 nexus.asgi:application
elif [[ "celery-worker" == "$1" ]]; then
celery_queue="celery"
echo "celery worker"
if [ "${2}" ] ; then
celery_queue="${2}"
fi
do_gosu "${APP_USER}:${APP_GROUP}" exec celery \
-A "${CELERY_APP}" --workdir="${PROJECT_PATH}" worker \
-Q "${celery_queue}" \
-O fair \
-l "${LOG_LEVEL}" \
--autoscale=${CELERY_MAX_WORKERS},1
elif [[ "healthcheck-celery-worker" == "$1" ]]; then
celery_queue="celery"
if [ "${2}" ] ; then
celery_queue="${2}"
fi
HEALTHCHECK_OUT=$(
do_gosu "${APP_USER}:${APP_GROUP}" celery -A "${CELERY_APP}" \
inspect ping \
-d "${celery_queue}@${HOSTNAME}" \
--timeout "${HEALTHCHECK_TIMEOUT}" 2>&1
)
echo "${HEALTHCHECK_OUT}"
grep -F -qs "${celery_queue}@${HOSTNAME}: OK" <<< "${HEALTHCHECK_OUT}" || exit 1
exit 0
fi
exec "$@"