From 3a6ec7c213eecee5089827e6495880c05fffbc19 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Mon, 5 Jun 2017 19:12:53 +0100 Subject: [PATCH] Configure dsvm gate job to use uwsgi instead of apache2 Change-Id: I31c8f5e724367e863fd613fbad170e52f99f1a42 --- devstack/files/apache2-freezer-api.conf | 1 + devstack/lib/freezer-api | 75 ++++++++++++++++++++++++- devstack/settings | 7 ++- etc/freezer/apache2-freezer-api.conf | 1 + etc/freezer/uwsgi.conf | 17 ++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 devstack/files/apache2-freezer-api.conf create mode 100644 etc/freezer/apache2-freezer-api.conf create mode 100644 etc/freezer/uwsgi.conf diff --git a/devstack/files/apache2-freezer-api.conf b/devstack/files/apache2-freezer-api.conf new file mode 100644 index 00000000..418b595c --- /dev/null +++ b/devstack/files/apache2-freezer-api.conf @@ -0,0 +1 @@ +ProxyPass "/backup" "unix:/var/run/uwsgi/freezer-api-wsgi.socket|uwsgi://uwsgi-uds-freezer-api-wsgi/" retry=0 \ No newline at end of file diff --git a/devstack/lib/freezer-api b/devstack/lib/freezer-api index 8fdbb499..1fdc5a56 100644 --- a/devstack/lib/freezer-api +++ b/devstack/lib/freezer-api @@ -103,6 +103,7 @@ function configure_freezer_api { # enable debuging iniset $FREEZER_API_CONF 'DEFAULT' debug True + iniset $FREEZER_API_CONF 'DEFAULT' log_file $FREEZER_API_LOG_DIR/freezer-api.log # set paste configuration iniset $FREEZER_API_CONF 'paste_deploy' config_file $FREEZER_API_CONF_DIR/freezer-paste.ini @@ -130,6 +131,9 @@ function configure_freezer_api { if [[ "${FREEZER_API_SERVER_TYPE}" == "apache2" ]]; then echo_summary "Configuring Freezer API wsgi app in Apache" configure_apache_freezer_app + elif [[ "${FREEZER_API_SERVER_TYPE}" == "uwsgi" ]]; then + echo_summary "Configuring Freezer API wsgi app in Uwsgi" + configure_uwsgi_freezer_api_app fi # TODO certs and more recent options such as elasticsearch connection parameters @@ -149,10 +153,18 @@ function init_freezer_api { # executed during: stack extra function start_freezer_api { + if [[ "${FREEZER_API_SERVER_TYPE}" == "uwsgi" ]]; then - run_process freezer-api "uwsgi --http :$FREEZER_API_PORT --need-app --master --module freezer_api.cmd.wsgi:application" + # @todo (szaher) use apache2 proxy template to run api with uwsgi + run_process freezer-api "$FREEZER_API_BIN_DIR/uwsgi --ini $FREEZER_API_UWSGI_CONF --pidfile2 $FREEZER_API_UWSGI_MASTER_PIDFILE" sleep 1 + enable_apache_site freezer-api + restart_apache_server + + tail_log freezer-api /var/log/$APACHE_NAME/freezer-api.log + elif [[ "${FREEZER_API_SERVER_TYPE}" == "apache2" ]]; then + enable_apache_site freezer-api restart_apache_server tail_log freezer-api /var/log/$APACHE_NAME/freezer-api.log @@ -164,9 +176,13 @@ function start_freezer_api { # executed during: stop function stop_freezer_api { ${TOP_DIR}/pkg/elasticsearch.sh stop + if [[ "${FREEZER_API_SERVER_TYPE}" == "uwsgi" ]]; then + uwsgi --stop $FREEZER_API_UWSGI_MASTER_PIDFILE killall -9 uwsgi fi + + disable_apache_site freezer-api stop_process freezer-api } @@ -202,11 +218,23 @@ function create_freezer_api_accounts { # # freezer backup endpoint registration # - get_or_create_endpoint "$freezer_service" \ + + if [[ "${FREEZER_API_SERVER_TYPE}" == "uwsgi" ]]; then + get_or_create_endpoint "$freezer_service" \ + "$REGION_NAME" \ + "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST/backup" \ + "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST/backup" \ + "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST/backup" + + elif [[ "${FREEZER_API_SERVER_TYPE}" == "apache2" ]]; then + get_or_create_endpoint "$freezer_service" \ "$REGION_NAME" \ "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST:$FREEZER_API_PORT" \ "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST:$FREEZER_API_PORT" \ "$FREEZER_API_SERVICE_PROTOCOL://$SERVICE_HOST:$FREEZER_API_PORT" + fi + + } @@ -232,5 +260,48 @@ function configure_apache_freezer_app { " -i $freezer_api_apache_conf } + +function configure_uwsgi_freezer_api_app { + + local freezer_api_apache_conf=$(apache_site_config_for freezer-api) + + # copy the uwsgi.conf to /etc/freezer/ + sudo cp $FREEZER_API_DIR/etc/freezer/uwsgi.conf $FREEZER_API_UWSGI_CONF + + local local_http="${SERVICE_HOST}:$FREEZER_API_PORT" + if [[ "${SERVICE_HOST}" == "127.0.0.1" ]] || [[ "${SERVICE_HOST}" == "localhost" ]]; then + local_http=":$FREEZER_API_PORT" + fi + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' http $local_http + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' processes 2 + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' threads 2 + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' wsgi-file $FREEZER_API_DIR/freezer_api/cmd/wsgi.py + + # Make sure the client doesn't try to re-use the connection. + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' add-header "Connection: close" + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' master true + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' socket /var/run/uwsgi/freezer-api-wsgi.socket + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' chmod-socket 666 + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' lazy-apps true + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' plugins python + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' enable-threads true + + # Set die-on-term & exit-on-reload so that uwsgi shuts down + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' exit-on-reload true + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' die-on-term true + + # uwsgi recommends this to prevent thundering herd on accept. + iniset $FREEZER_API_UWSGI_CONF 'uwsgi' thunder-lock true + + # print the content of the uwsgi.conf after replacing values + cat $FREEZER_API_UWSGI_CONF + + echo_summary "Configuring freezer-api uwsgi site" + + sudo cp $FREEZER_API_FILES/apache2-freezer-api.conf $freezer_api_apache_conf + + +} + # Restore xtrace $XTRACE diff --git a/devstack/settings b/devstack/settings index e9bcc125..ddb0b87d 100644 --- a/devstack/settings +++ b/devstack/settings @@ -20,6 +20,9 @@ FREEZER_API_DIR=$DEST/freezer-api FREEZER_API_FILES=${FREEZER_API_DIR}/devstack/files FREEZER_API_CONF_DIR=${FREEZER_API_CONF_DIR:-/etc/freezer} FREEZER_API_CONF=$FREEZER_API_CONF_DIR/freezer-api.conf +FREEZER_API_UWSGI_CONF=$FREEZER_API_CONF_DIR/uwsgi.conf +FREEZER_API_UWSGI_MASTER_PIDFILE=/tmp/uwsgifreezermasterprocess.pid + FREEZER_API_LOG_DIR=$DEST/logs FREEZER_API_AUTH_CACHE_DIR=${FREEZER_API_AUTH_CACHE_DIR:-/var/cache/freezer-api} @@ -28,7 +31,7 @@ FREEZER_API_REPO=${FREEZER_API_REPO:-${GIT_BASE}/openstack/freezer-api.git} FREEZER_API_BRANCH=${FREEZER_API_BRANCH:-master} # supported servers: "apache2", "uwsgi" -FREEZER_API_SERVER_TYPE=${FREEZER_API_SERVER_TYPE:-apache2} +FREEZER_API_SERVER_TYPE=${FREEZER_API_SERVER_TYPE:-uwsgi} FREEZER_API_SERVICE_PROTOCOL=http FREEZER_API_PORT=9090 @@ -38,6 +41,8 @@ FREEZERCLIENT_DIR=$DEST/python-freezerclient FREEZERCLIENT_REPO=${FREEZERCLIENT_REPO:-${GIT_BASE}/openstack/python-freezerclient.git} FREEZERCLIENT_BRANCH=${FREEZERCLIENT_BRANCH:-master} +FREEZER_API_BIN_DIR=$(get_python_exec_prefix) + enable_service freezer-api # Tell Tempest this project is present diff --git a/etc/freezer/apache2-freezer-api.conf b/etc/freezer/apache2-freezer-api.conf new file mode 100644 index 00000000..418b595c --- /dev/null +++ b/etc/freezer/apache2-freezer-api.conf @@ -0,0 +1 @@ +ProxyPass "/backup" "unix:/var/run/uwsgi/freezer-api-wsgi.socket|uwsgi://uwsgi-uds-freezer-api-wsgi/" retry=0 \ No newline at end of file diff --git a/etc/freezer/uwsgi.conf b/etc/freezer/uwsgi.conf new file mode 100644 index 00000000..e805d8ca --- /dev/null +++ b/etc/freezer/uwsgi.conf @@ -0,0 +1,17 @@ +[uwsgi] +chmod-socket = 666 +lazy-apps = true +strict = true +http = :9090 +processes = 2 +threads = 2 +wsgi-file = /opt/stack/freezer-api/freezer_api/cmd/wsgi.py +callable = app +master = true +add-header = Connection: close +plugins = python +enable-threads = true +exit-on-reload = true +die-on-term = true +socket = /var/run/uwsgi/freezer-api-wsgi.socket +thunder-lock = true \ No newline at end of file