lib/apache: Use module paths instead of WSGI scripts
pbr's 'wsgi_scripts' entrypoint functionality is not long for this world
so we need to start working towards an alternative. We could start
packaging our own WSGI scripts in DevStack but using module paths seems
like a better option, particularly when it's supported by other WSGI
servers like gunicorn.
Currently only nova is migrated. We should switch additional projects as
they migrate and eventually remove the support for WSGI scripts
entirely.
Change-Id: I057dc635c01e54740ee04dfe7b39ef83db5dc180
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Depends-on: https://review.opendev.org/c/openstack/nova/+/902687/
diff --git a/lib/apache b/lib/apache
index 9017e0a..a314b76 100644
--- a/lib/apache
+++ b/lib/apache
@@ -237,13 +237,17 @@
restart_service $APACHE_NAME
}
+# write_uwsgi_config() - Create a new uWSGI config file
function write_uwsgi_config {
local conf=$1
local wsgi=$2
local url=$3
local http=$4
- local name=""
- name=$(basename $wsgi)
+ local name=$5
+
+ if [ -z "$name" ]; then
+ name=$(basename $wsgi)
+ fi
# create a home for the sockets; note don't use /tmp -- apache has
# a private view of it on some platforms.
@@ -259,7 +263,15 @@
# always cleanup given that we are using iniset here
rm -rf $conf
- iniset "$conf" uwsgi wsgi-file "$wsgi"
+ # Set either the module path or wsgi script path depending on what we've
+ # been given. Note that the regex isn't exhaustive - neither Python modules
+ # nor Python variables can start with a number - but it's "good enough"
+ if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
+ iniset "$conf" uwsgi module "$wsgi"
+ else
+ deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
+ iniset "$conf" uwsgi wsgi-file "$wsgi"
+ fi
iniset "$conf" uwsgi processes $API_WORKERS
# This is running standalone
iniset "$conf" uwsgi master true
@@ -306,14 +318,25 @@
local conf=$1
local wsgi=$2
local url=$3
- name=$(basename $wsgi)
+ local name=$4
+
+ if [ -z "$name" ]; then
+ name=$(basename $wsgi)
+ fi
# create a home for the sockets; note don't use /tmp -- apache has
# a private view of it on some platforms.
# always cleanup given that we are using iniset here
rm -rf $conf
- iniset "$conf" uwsgi wsgi-file "$wsgi"
+ # Set either the module path or wsgi script path depending on what we've
+ # been given
+ if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
+ iniset "$conf" uwsgi module "$wsgi"
+ else
+ deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
+ iniset "$conf" uwsgi wsgi-file "$wsgi"
+ fi
port=$(get_random_port)
iniset "$conf" uwsgi http-socket "$APACHE_LOCAL_HOST:$port"
iniset "$conf" uwsgi processes $API_WORKERS