From 6e0d33219baadaee004359eeab8dc5464fe82002 Mon Sep 17 00:00:00 2001 From: chenying Date: Tue, 11 Apr 2017 22:38:16 +0800 Subject: [PATCH] Add karbor-api WSGI support in devstack Update devstack related script in karbor to support deploying karbor-api in Apache2. Change-Id: Iaee79f4189dcc596765eb416df4bad4431158849 Closes-Bug: #1681500 --- devstack/files/apache-karbor-api.template | 26 +++++++++ devstack/plugin.sh | 71 ++++++++++++++++++++++- devstack/settings | 6 ++ 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 devstack/files/apache-karbor-api.template diff --git a/devstack/files/apache-karbor-api.template b/devstack/files/apache-karbor-api.template new file mode 100644 index 00000000..42f898c9 --- /dev/null +++ b/devstack/files/apache-karbor-api.template @@ -0,0 +1,26 @@ +Listen %PUBLICPORT% + + + WSGIDaemonProcess osapi_karbor processes=%APIWORKERS% threads=1 user=%USER% display-name=%{GROUP} + WSGIProcessGroup osapi_karbor + WSGIScriptAlias / %KARBOR_BIN_DIR%/karbor-wsgi + WSGIApplicationGroup %{GLOBAL} + WSGIPassAuthorization On + = 2.4> + ErrorLogFormat "%{cu}t %M" + + ErrorLog /var/log/%APACHE_NAME%/karbor-api.log + %SSLENGINE% + %SSLCERTFILE% + %SSLKEYFILE% + + + = 2.4> + Require all granted + + + Order allow,deny + Allow from all + + + \ No newline at end of file diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 48ce3da8..1a18b29b 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -34,6 +34,59 @@ function create_karbor_accounts { fi } + +# karbor_config_apache_wsgi() - Set WSGI config files +function karbor_config_apache_wsgi { + local karbor_apache_conf + karbor_apache_conf=$(apache_site_config_for osapi_karbor) + local karbor_ssl="" + local karbor_certfile="" + local karbor_keyfile="" + local karbor_api_port=$KARBOR_API_PORT + + if is_ssl_enabled_service karbor-api; then + karbor_ssl="SSLEngine On" + karbor_certfile="SSLCertificateFile $KARBOR_SSL_CERT" + karbor_keyfile="SSLCertificateKeyFile $KARBOR_SSL_KEY" + fi + + # copy proxy vhost file + sudo cp $KARBOR_API_APACHE_TEMPLATE $karbor_apache_conf + sudo sed -e " + s|%PUBLICPORT%|$karbor_api_port|g; + s|%APACHE_NAME%|$APACHE_NAME|g; + s|%APIWORKERS%|$API_WORKERS|g + s|%KARBOR_BIN_DIR%|$KARBOR_BIN_DIR|g; + s|%SSLENGINE%|$karbor_ssl|g; + s|%SSLCERTFILE%|$karbor_certfile|g; + s|%SSLKEYFILE%|$karbor_keyfile|g; + s|%USER%|$STACK_USER|g; + " -i $karbor_apache_conf +} + +# clean_karbor_api_wsgi() - Remove wsgi files, disable and remove apache vhost file +function clean_karbor_api_wsgi { + sudo rm -f $(apache_site_config_for osapi_karbor) +} + +# start_karbor_api_wsgi() - Start the API processes ahead of other things +function start_karbor_api_wsgi { + enable_apache_site osapi_karbor + restart_apache_server + tail_log karbor-api /var/log/$APACHE_NAME/karbor-api.log + + echo "Waiting for Karbor API to start..." + if ! wait_for_service $SERVICE_TIMEOUT $KARBOR_API_PROTOCOL://$KARBOR_API_HOST:$KARBOR_API_PORT; then + die $LINENO "karbor-api wsgi did not start" + fi +} + +# stop_karbor_api_wsgi() - Disable the api service and stop it. +function stop_karbor_api_wsgi { + disable_apache_site osapi_karbor + restart_apache_server +} + function configure_karbor_api { if is_service_enabled karbor-api ; then echo "Configuring Karbor API" @@ -106,6 +159,10 @@ if [[ "$Q_ENABLE_KARBOR" == "True" ]]; then configure_karbor_api + if [ "$KARBOR_USE_MOD_WSGI" == "True" ]; then + karbor_config_apache_wsgi + fi + echo export PYTHONPATH=\$PYTHONPATH:$KARBOR_DIR >> $RC_DIR/.localrc.auto elif [[ "$1" == "stack" && "$2" == "extra" ]]; then @@ -114,7 +171,6 @@ if [[ "$Q_ENABLE_KARBOR" == "True" ]]; then create_karbor_accounts echo_summary "Initializing Karbor Service" - KARBOR_BIN_DIR=$(get_python_exec_prefix) if is_service_enabled $DATABASE_BACKENDS; then # (re)create karbor database @@ -124,7 +180,11 @@ if [[ "$Q_ENABLE_KARBOR" == "True" ]]; then $KARBOR_BIN_DIR/karbor-manage db sync fi if is_service_enabled karbor-api; then - run_process karbor-api "$KARBOR_BIN_DIR/karbor-api --config-file $KARBOR_API_CONF" + if [[ "$KARBOR_USE_MOD_WSGI" == "True" ]]; then + start_karbor_api_wsgi + else + run_process karbor-api "$KARBOR_BIN_DIR/karbor-api --config-file $KARBOR_API_CONF" + fi fi if is_service_enabled karbor-operationengine; then run_process karbor-operationengine "$KARBOR_BIN_DIR/karbor-operationengine --config-file $KARBOR_API_CONF" @@ -137,7 +197,12 @@ if [[ "$Q_ENABLE_KARBOR" == "True" ]]; then if [[ "$1" == "unstack" ]]; then if is_service_enabled karbor-api; then - stop_process karbor-api + if [[ "$KARBOR_USE_MOD_WSGI" == "True" ]]; then + stop_karbor_api_wsgi + clean_karbor_api_wsgi + else + stop_process karbor-api + fi fi if is_service_enabled karbor-operationengine; then stop_process karbor-operationengine diff --git a/devstack/settings b/devstack/settings index 4daa9c13..0247dbb5 100644 --- a/devstack/settings +++ b/devstack/settings @@ -3,12 +3,18 @@ KARBOR_REPO=${KARBOR_REPO:-https://git.openstack.org/cgit/openstack/karbor/} KARBOR_DIR=$DEST/karbor KARBOR_BRANCH=${KARBOR_BRANCH:-master} +# Toggle for deploying Karbor under apache2 in mod_wsgi +KARBOR_USE_MOD_WSGI=${KARBOR_USE_MOD_WSGI:-True} + +KARBOR_BIN_DIR=$(get_python_exec_prefix) + # common variables KARBOR_CONF_DIR=${KARBOR_CONF_DIR:-/etc/karbor} # karbor rest api KARBOR_API=$KARBOR_DIR/karbor/cmd/api.py KARBOR_API_CONF=$KARBOR_CONF_DIR/karbor.conf +KARBOR_API_APACHE_TEMPLATE=$KARBOR_DIR/devstack/files/apache-karbor-api.template KARBOR_API_LISTEN_ADDRESS=${KARBOR_API_LISTEN_ADDRESS:-0.0.0.0} KARBOR_API_HOST=${KARBOR_API_HOST:-$SERVICE_HOST}