Add toggle in devstack plugin to run senlin-api under Apache2

Add senlin-api apache mod_wsgi template file and related functions
to devstack plugin.

Change-Id: I24558509b2e310c665272f1831c69144ccd30dd7
This commit is contained in:
lvdongbing 2016-11-11 02:27:47 -05:00
parent 62dc971fa6
commit 1bc046717e
4 changed files with 104 additions and 9 deletions

View File

@ -15,4 +15,7 @@ Enabling senlin in DevStack
#Enable senlin-dashboard
enable_plugin senlin-dashboard https://git.openstack.org/openstack/senlin-dashboard
Optionally, you can add a line ``SENLIN_USE_MOD_WSGI=True`` to the same ``local.conf``
file if you prefer running the Senlin API service under Apache.
3. Run ``./stack.sh``.

View File

@ -0,0 +1,34 @@
Listen %PORT%
<VirtualHost *:%PORT%>
WSGIDaemonProcess senlin-api processes=2 threads=1 user=%USER% display-name=%{GROUP} %VIRTUALENV%
WSGIProcessGroup senlin-api
WSGIScriptAlias / %SENLIN_BIN_DIR%/senlin-wsgi-api
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
AllowEncodedSlashes On
<IfVersion >= 2.4>
ErrorLogFormat "%{cu}t %M"
</IfVersion>
ErrorLog /var/log/%APACHE_NAME%/senlin-api.log
<Directory %SENLIN_BIN_DIR%>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
</VirtualHost>
Alias /cluster %SENLIN_BIN_DIR%/senlin-wsgi-api
<Location /cluster>
SetHandler wsgi-script
Options +ExecCGI
WSGIProcessGroup senlin-api
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
AllowEncodedSlashes On
</Location>

View File

@ -57,6 +57,9 @@ SENLIN_DASHBOARD_DIR=$DEST/senlin-dashboard
SENLIN_DASHBOARD_REPO=${SENLIN_DASHBOARD_REPO:-${GIT_BASE}/openstack/senlin-dashboard.git}
SENLIN_DASHBOARD_BRANCH=${SENLIN_DASHBOARD_BRANCH:-master}
# Toggle for deploying senlin-api under Apache(mod_wsgi)
SENLIN_USE_MOD_WSGI=${SENLIN_USE_MOD_WSGI:-False}
# Functions
# ---------
@ -70,6 +73,7 @@ function is_senlin_enabled {
# cleanup_senlin() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
function cleanup_senlin {
_cleanup_senlin_apache_wsgi
sudo rm -rf $SENLIN_AUTH_CACHE_DIR
sudo rm -rf $SENLIN_CONF_DIR
}
@ -96,7 +100,7 @@ function configure_senlin {
iniset $SENLIN_CONF DEFAULT default_region_name "$REGION_NAME"
iniset $SENLIN_CONF DEFAULT use_syslog $SYSLOG
if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ] && [ "$SENLIN_USE_MOD_WSGI" == "False" ]; then
# Add color to logging output
setup_colorized_logging $SENLIN_CONF DEFAULT
fi
@ -134,6 +138,35 @@ function configure_senlin {
iniset $SENLIN_CONF zaqar auth_url $KEYSTONE_AUTH_URI/v3
iniset $SENLIN_CONF zaqar user_domain_name Default
iniset $SENLIN_CONF zaqar project_domain_name Default
if [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
_config_senlin_apache_wsgi
fi
}
# _cleanup_senlin_apache_wsgi() - Remove WSGI files, disable and remove Apache vhost file
function _cleanup_senlin_apache_wsgi {
if [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
sudo rm -f $(apache_site_config_for senlin-api)
fi
}
# _config_senlin_apache_wsgi() - Configure mod_wsgi
function _config_senlin_apache_wsgi {
local senlin_apache_conf
senlin_apache_conf=$(apache_site_config_for senlin-api)
local senlin_api_port=$SENLIN_API_PORT
local venv_path=""
sudo cp $SENLIN_DIR/devstack/apache-senlin.template $senlin_apache_conf
sudo sed -e "
s|%PORT%|$senlin_api_port|g;
s|%APACHE_NAME%|$APACHE_NAME|g;
s|%SENLIN_BIN_DIR%|$SENLIN_BIN_DIR|g;
s|%USER%|$STACK_USER|g;
s|%VIRTUALENV%|$venv_path|g
" -i $senlin_apache_conf
}
# init_senlin() - Initialize database
@ -199,21 +232,37 @@ function cleanup_senlin_dashboard {
function install_senlin {
git_clone $SENLIN_REPO $SENLIN_DIR $SENLIN_BRANCH
setup_develop $SENLIN_DIR
if [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
install_apache_wsgi
fi
}
# start_senlin() - Start running processes, including screen
function start_senlin {
run_process sl-eng "$SENLIN_BIN_DIR/senlin-engine --config-file=$SENLIN_CONF"
run_process sl-api "$SENLIN_BIN_DIR/senlin-api --config-file=$SENLIN_CONF"
local enabled_site_file
enabled_site_file=$(apache_site_config_for senlin-api)
if [ -f ${enabled_site_file} ] && [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
enable_apache_site senlin-api
restart_apache_server
tail_log senlin-api /var/log/$APACHE_NAME/senlin-api.log
else
run_process sl-api "$SENLIN_BIN_DIR/senlin-api --config-file=$SENLIN_CONF"
fi
}
# stop_senlin() - Stop running processes
function stop_senlin {
# Kill the screen windows
local serv
for serv in sl-eng sl-api; do
stop_process $serv
done
stop_process sl-eng
if [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
disable_apache_site senlin-api
restart_apache_server
else
stop_process sl-api
fi
}
# create_senlin_accounts() - Set up common required senlin accounts
@ -225,11 +274,17 @@ function create_senlin_accounts {
local senlin_service=$(get_or_create_service "senlin" \
"clustering" "Senlin Clustering Service")
if [ "$SENLIN_USE_MOD_WSGI" == "True" ]; then
senlin_api_url="$SERVICE_PROTOCOL://$SENLIN_API_HOST/cluster"
else
senlin_api_url="$SERVICE_PROTOCOL://$SENLIN_API_HOST:$SENLIN_API_PORT"
fi
get_or_create_endpoint $senlin_service \
"$REGION_NAME" \
"$SERVICE_PROTOCOL://$SENLIN_API_HOST:$SENLIN_API_PORT" \
"$SERVICE_PROTOCOL://$SENLIN_API_HOST:$SENLIN_API_PORT" \
"$SERVICE_PROTOCOL://$SENLIN_API_HOST:$SENLIN_API_PORT"
"$senlin_api_url" \
"$senlin_api_url" \
"$senlin_api_url"
fi
# get or adds 'service' role to 'senlin' on 'demo' project

View File

@ -41,6 +41,9 @@ following detailed instructions.
#Enable senlin-dashboard
enable_plugin senlin-dashboard https://git.openstack.org/openstack/senlin-dashboard
Optionally, you can add a line ``SENLIN_USE_MOD_WSGI=True`` to the same ``local.conf``
file if you prefer running the Senlin API service under Apache.
3. Run ``./stack.sh``::
$ ./stack.sh