-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-worker.sh
executable file
·84 lines (75 loc) · 2.59 KB
/
start-worker.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
#!/usr/bin/env bash
if [[ "$OSTYPE" == *darwin* ]]; then
if command -v greadlink >/dev/null 2>&1; then
scriptPath=$(dirname "$(greadlink -f "$0")")
else
echo "greadlink command not found"
exit 1
fi
else
scriptPath=$(dirname "$(readlink -f "$0")")
fi
cd "${scriptPath}/" || exit 1
function display_help() {
echo "Start worker for ove-asset-manager"
echo
echo "usage: start-worker.sh [option]..."
echo " --port Worker service port"
echo " --class The worker class, e.g. workers.dzi.DeepZoomImageWorker"
echo " --name The worker name, autogenerated if missing"
}
while [[ $# -gt 0 ]]; do
key="$1"
case ${key} in
-h | --help)
display_help
exit 0
;;
--port)
GUNICORN_PORT="$2"
shift
;;
--class)
WORKER_CLASS="$2"
shift
;;
--name)
WORKER_NAME="$2"
shift
;;
*)
echo "Unrecognised option: $key"
echo
display_help
exit 1
;;
esac
shift
done
[[ ! -z "${GUNICORN_PORT}" ]] || GUNICORN_PORT="6090"
[[ ! -z "${GUNICORN_HOST}" ]] || GUNICORN_HOST="0.0.0.0"
[[ ! -z "${GUNICORN_WORKERS}" ]] || GUNICORN_WORKERS="1"
[[ ! -z "${GUNICORN_THREADS}" ]] || GUNICORN_THREADS="4"
[[ ! -z "${GUNICORN_TIMEOUT}" ]] || GUNICORN_TIMEOUT="240" # this needs to be tuned based on the network bandwidth
[[ ! -z "${SERVICE_LOG_LEVEL}" ]] || SERVICE_LOG_LEVEL="debug"
[[ ! -z "${WORKER_NAME}" ]] || WORKER_NAME=$(strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 21 | tr -d '\n')
# for MacOs and BSD-like systems
[[ ! -z "${WORKER_NAME}" ]] || WORKER_NAME=$(echo $(cat /dev/urandom | base64 | tr -dc "[:alnum:]" | head -c10))
[[ ! -z "${WORKER_CONFIG}" ]] || WORKER_CONFIG="config/worker.json"
# For testing purpose this can be used, otherwise the next line should be commented
# [[ ! -z "${WORKER_CLASS}" ]] || WORKER_CLASS="workers.dzi.DeepZoomImageWorker"
echo "Environment variables:"
echo " GUNICORN_PORT=${GUNICORN_PORT}"
echo " GUNICORN_HOST=${GUNICORN_HOST}"
echo " GUNICORN_WORKERS=${GUNICORN_WORKERS}"
echo " GUNICORN_THREADS=${GUNICORN_THREADS}"
echo ""
echo " SERVICE_LOG_LEVEL=${SERVICE_LOG_LEVEL}"
echo " WORKER_NAME=${WORKER_NAME}"
echo " WORKER_CLASS=${WORKER_CLASS}"
echo ""
echo " WORKER_CONFIG=${WORKER_CONFIG}"
echo ""
## did you activate the virtual environment and install the requirements?
exec gunicorn --bind "${GUNICORN_HOST}:${GUNICORN_PORT}" --workers ${GUNICORN_WORKERS} --threads ${GUNICORN_THREADS} --timeout ${GUNICORN_TIMEOUT} \
"workers.base:setup_worker(logging_level='${SERVICE_LOG_LEVEL}', worker_name='${WORKER_NAME}', worker_class='${WORKER_CLASS}', config_file='${WORKER_CONFIG}')"