-
Notifications
You must be signed in to change notification settings - Fork 26
/
celery-entrypoint.sh
executable file
·58 lines (49 loc) · 1.79 KB
/
celery-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
#!/usr/bin/env sh
set -e
_is_celery_command () {
local cmd="$1"; shift
python - <<EOF
import sys
from celery.bin.celery import celery
from click import Context
sys.exit(0 if '$cmd' in celery.list_commands(Context(celery)) else 1)
EOF
}
if [ "$1" != 'celery' ]; then
# If first argument looks like an option or a Celery command, add the 'celery'
if [ "${1#-}" != "$1" ] || _is_celery_command "$1"; then
set -- celery "$@"
fi
fi
if [ "$1" = 'celery' ]; then
# Set some common options if the env vars are set
if [ -n "$CELERY_BROKER" ]; then
echo 'DEPRECATED: The CELERY_BROKER environment variable is deprecated.
Please set the Celery broker in your Django settings file rather.' 1>&2
set -- "$@" --broker "$CELERY_BROKER"
fi
if [ -n "$CELERY_LOGLEVEL" ]; then
echo 'DEPRECATED: The CELERY_LOGLEVEL environment variable is deprecated.
Please set the Celery log level in your Django settings file rather.' 1>&2
set -- "$@" --loglevel "$CELERY_LOGLEVEL"
fi
# Set the concurrency if this is a worker
if [ "$2" = 'worker' ]; then
if [ -n "$CELERY_CONCURRENCY" ]; then
echo 'DEPRECATED: The CELERY_CONCURRENCY environment variable is deprecated.
Please set the Celery worker concurrency in your Django settings file rather.' 1>&2
fi
set -- "$@" --concurrency "${CELERY_CONCURRENCY:-1}"
fi
# Run under the celery user
set -- su-exec django "$@"
# Create the Celery runtime directory at runtime in case /run is a tmpfs
if mkdir /run/celery 2> /dev/null; then
chown django:django /run/celery
fi
# Celery by default writes files like pidfiles and the beat schedule file to
# the current working directory. Change to the Celery working directory so
# that these files end up there.
cd /run/celery
fi
exec "$@"