diff --git a/README.rst b/README.rst index 63fd7208..76e87c38 100644 --- a/README.rst +++ b/README.rst @@ -275,7 +275,9 @@ If SSL needs to be enabled follow this step or skip to next step:: For locally generating and testing, please refer to below link: http://tech.paulcz.net/2016/01/secure-docker-with-tls/ -Run Kuryr Server from command below:: +Run Kuryr Server with the command below. If you have uwsgi installed this +command would run Kuryr under it. You can override this behaviour by +setting `KURYR_USE_UWSGI=False`:: $ sudo ./scripts/run_kuryr.sh diff --git a/releasenotes/notes/use-uwsgi-to-run-server-4f43e615fd277c73.yaml b/releasenotes/notes/use-uwsgi-to-run-server-4f43e615fd277c73.yaml new file mode 100644 index 00000000..7758077e --- /dev/null +++ b/releasenotes/notes/use-uwsgi-to-run-server-4f43e615fd277c73.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + scripts/run_kuryr.sh now defaults to running api server under uwsgi. This behaviour + can be controlled by KURYR_USE_UWSGI env variable (default True). + In case it is set to False or uwsgi is abscent api would be run as usual. diff --git a/scripts/run_kuryr.sh b/scripts/run_kuryr.sh index e1845f90..0ab2cb1b 100755 --- a/scripts/run_kuryr.sh +++ b/scripts/run_kuryr.sh @@ -76,4 +76,34 @@ if [[ ! -f "${KURYR_CONFIG}" ]]; then echo "Done" fi -PYTHONPATH=${KURYR_HOME} python ${KURYR_HOME}/scripts/run_server.py --config-file /etc/kuryr/kuryr.conf $@ +KURYR_USE_UWSGI=${KURYR_USE_UWSGI:-True} +KURYR_UWSGI_PROCESSES=${KURYR_UWSGI_PROCESSES:-1} +KURYR_UWSGI_THREADS=${KURYR_UWSGI_THREADS:-1} + +UWSGI_BIN=$(which uwsgi) +if [[ -z "UWSGI_BIN" && $KURYR_USE_UWSGI == "True" ]]; then + echo "Requested uwsgi usage, but no uwsgi executable is available. Falling back to run_server.py" + echo "To suppress this message set KURYR_USE_UWSGI to False" + KURYR_USE_UWSGI="False" +fi + +UWSGI_ADDITIONAL_ARGS=() +if [[ $KURYR_USE_UWSGI == "True" ]]; then + if [[ "$VIRTUAL_ENV" ]]; then + UWSGI_ADDITIONAL_ARGS=( --virtualenv $VIRTUAL_ENV ) + fi + echo "Starting uwsgi with ${KURYR_UWSGI_PROCESSES} processes and ${KURYR_UWSGI_THREADS} threads" + $UWSGI_BIN \ + --plugins python \ + --http-socket :23750 \ + --wsgi kuryr_libnetwork.server:app \ + --python-path "${KURYR_HOME}" \ + --pyargv "--config-file ${KURYR_CONFIG}" \ + --master \ + --need-app \ + --processes "$KURYR_UWSGI_PROCESSES" \ + --threads "$KURYR_UWSGI_THREADS" \ + "${UWSGI_ADDITIONAL_ARGS[@]}" +else + PYTHONPATH="${KURYR_HOME}" python "${KURYR_HOME}/scripts/run_server.py" --config-file "${KURYR_CONFIG}" "$@" +fi