-
Notifications
You must be signed in to change notification settings - Fork 0
/
vumi-entrypoint.sh
executable file
·62 lines (51 loc) · 1.72 KB
/
vumi-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
#!/usr/bin/env sh
set -e
# If `python` isn't available, we should use `pypy`
python=$(command -v python > /dev/null && echo python || echo pypy)
# Generate Twisted's plugin cache just before running -- all plugins should be
# installed at this point. Twisted is installed site-wide, so the root user is
# needed to perform this operation. See:
# http://twistedmatrix.com/documents/current/core/howto/plugin.html#plugin-caching
"$python" -c 'from twisted.plugin import IPlugin, getPlugins; list(getPlugins(IPlugin))'
is_twistd_command() {
local cmd="$1"; shift
"$python" - <<EOF
import sys
from twisted.plugin import getPlugins
from twisted.application.service import IServiceMaker
sys.exit(0 if '$cmd' in [p.tapname for p in getPlugins(IServiceMaker)] else 1)
EOF
}
env_vumi_opts() {
env \
| grep ^VUMI_OPT_ \
| sed -e 's/^VUMI_OPT_//' -e 's/=/ /' \
| awk '{printf("%s=%s:%s ", "--set-option", tolower($1), $2);}'
}
# If no args, first arg looks like an option, or first arg is a twistd command
if [ $# -eq 0 ] || [ "${1#-}" != "$1" ]; then
set -- twistd --nodaemon --pidfile='' "${TWISTD_COMMAND:-vumi_worker}" "$@"
elif is_twistd_command "$1"; then
set -- twistd --nodaemon --pidfile='' "$@"
fi
if [ "$1" = 'twistd' ]; then
if [ -n "$WORKER_CLASS" ]; then
set -- "$@" --worker-class "$WORKER_CLASS"
fi
if [ -n "$CONFIG_FILE" ]; then
set -- "$@" --config "$CONFIG_FILE"
fi
if [ -n "$AMQP_HOST" ]; then
set -- "$@" \
--hostname "$AMQP_HOST" \
--port "${AMQP_PORT:-5672}" \
--vhost "${AMQP_VHOST:-/}" \
--username "${AMQP_USERNAME:-guest}" \
--password "${AMQP_PASSWORD:-guest}"
fi
if [ -n "$SENTRY_DSN" ]; then
set -- "$@" --sentry "$SENTRY_DSN"
fi
set -- su-exec vumi "$@" $(env_vumi_opts)
fi
exec "$@"