327 lines
11 KiB
Bash
327 lines
11 KiB
Bash
#!/bin/bash
|
|
#
|
|
# lib/senlin
|
|
# Install and start **Senlin** service
|
|
|
|
# To enable, add the following to local.conf
|
|
#
|
|
# [[local|localrc]]
|
|
# enable_plugin senlin https://git.openstack.org/openstack/senlin
|
|
|
|
# Dependencies:
|
|
#
|
|
# - functions
|
|
# - HORIZON_DIR
|
|
|
|
# stack.sh
|
|
# ---------
|
|
# - config_senlin_dashboard
|
|
# - configure_senlin
|
|
# - cleanup_senlin
|
|
# - cleanup_senlin_dashboard
|
|
# - create_senlin_cache_dir
|
|
# - create_senlin_accounts
|
|
# - init_senlin
|
|
# - install_senlinclient
|
|
# - install_senlin
|
|
# - install_senlin_dashboard
|
|
# - is_senlin_enabled
|
|
# - start_senlin
|
|
# - stop_senlin
|
|
|
|
# Save trace setting
|
|
XTRACE=$(set +o | grep xtrace)
|
|
set +o xtrace
|
|
|
|
|
|
# Defaults
|
|
# --------
|
|
|
|
# set up default
|
|
SENLIN_AUTH_CACHE_DIR=${SENLIN_AUTH_CACHE_DIR:-/var/cache/senlin}
|
|
SENLIN_CONF_DIR=/etc/senlin
|
|
SENLIN_CONF=$SENLIN_CONF_DIR/senlin.conf
|
|
SENLIN_API_HOST=${SENLIN_API_HOST:-$SERVICE_HOST}
|
|
SENLIN_WSGI_MODE=${SENLIN_WSGI_MODE:-"uwsgi"}
|
|
|
|
SENLIN_DIR=$DEST/senlin
|
|
if [[ ${USE_VENV} = True ]]; then
|
|
PROJECT_VENV["senlin"]=${SENLIN_DIR}.venv
|
|
SENLIN_BIN_DIR=${PROJECT_VENV["senlin"]}/bin
|
|
else
|
|
SENLIN_BIN_DIR=$(get_python_exec_prefix)
|
|
fi
|
|
SENLIN_REPO=${SENLIN_REPO:-${GIT_BASE}/openstack/senlin.git}
|
|
SENLIN_BRANCH=${SENLIN_BRANCH:-master}
|
|
|
|
SENLINCLIENT_DIR=$DEST/python-senlinclient
|
|
SENLINCLIENT_REPO=${SENLINCLIENT_REPO:-${GIT_BASE}/openstack/python-senlinclient.git}
|
|
SENLINCLIENT_BRANCH=${SENLINCLIENT_BRANCH:-master}
|
|
|
|
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}
|
|
|
|
SENLIN_UWSGI=$SENLIN_BIN_DIR/senlin-wsgi-api
|
|
SENLIN_UWSGI_CONF=$SENLIN_CONF_DIR/senlin-api-uwsgi.ini
|
|
|
|
if is_service_enabled tls-proxy; then
|
|
SENLIN_SERVICE_PROTOCOL="https"
|
|
fi
|
|
|
|
SENLIN_SERVICE_PROTOCOL=${SENLIN_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
|
|
|
|
# Functions
|
|
# ---------
|
|
|
|
# Test if any Senlin services are enabled
|
|
function is_senlin_enabled {
|
|
[[ ,${ENABLED_SERVICES} =~ ,"sl-" ]] && return 0
|
|
return 1
|
|
}
|
|
|
|
# cleanup_senlin() - Remove residual data files, anything left over from previous
|
|
# runs that a clean run would need to clean up
|
|
function cleanup_senlin {
|
|
sudo rm -f $(apache_site_config_for senlin-api)
|
|
remove_uwsgi_config "$SENLIN_UWSGI_CONF" "$SENLIN_UWSGI"
|
|
sudo rm -rf $SENLIN_AUTH_CACHE_DIR
|
|
sudo rm -rf $SENLIN_CONF_DIR
|
|
}
|
|
|
|
# configure_senlin() - Set config files, create data dirs, etc
|
|
function configure_senlin {
|
|
if [[ ! -d $SENLIN_CONF_DIR ]]; then
|
|
sudo mkdir -p $SENLIN_CONF_DIR
|
|
fi
|
|
|
|
sudo chown $STACK_USER $SENLIN_CONF_DIR
|
|
|
|
sudo install -d -o $STACK_USER $SENLIN_CONF_DIR
|
|
|
|
SENLIN_API_PASTE_FILE=$SENLIN_CONF_DIR/api-paste.ini
|
|
|
|
cp $SENLIN_DIR/etc/senlin/api-paste.ini $SENLIN_API_PASTE_FILE
|
|
|
|
# common options
|
|
iniset $SENLIN_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
|
|
iniset $SENLIN_CONF DEFAULT auth_encryption_key $(generate_hex_string 16)
|
|
iniset $SENLIN_CONF DEFAULT default_region_name "$REGION_NAME"
|
|
|
|
|
|
if [ "$USE_SYSTEMD" != "False" ]; then
|
|
setup_systemd_logging $SENLIN_CONF
|
|
fi
|
|
|
|
if [ "$LOG_COLOR" == "True" ] && [ "$USE_SYSTEMD" == "False" ]; then
|
|
# Add color to logging output
|
|
setup_colorized_logging $SENLIN_CONF DEFAULT
|
|
fi
|
|
|
|
# rpc
|
|
iniset_rpc_backend senlin $SENLIN_CONF
|
|
|
|
# Database connection
|
|
iniset $SENLIN_CONF database connection `database_connection_url senlin`
|
|
|
|
# Keystone authtoken middleware
|
|
#configure_auth_token_middleware $SENLIN_CONF senlin $SENLIN_AUTH_CACHE_DIR
|
|
iniset $SENLIN_CONF keystone_authtoken cafile $SSL_BUNDLE_FILE
|
|
iniset $SENLIN_CONF keystone_authtoken auth_url $KEYSTONE_AUTH_URI
|
|
iniset $SENLIN_CONF keystone_authtoken www_authenticate_uri $KEYSTONE_SERVICE_URI_V3
|
|
iniset $SENLIN_CONF keystone_authtoken username senlin
|
|
iniset $SENLIN_CONF keystone_authtoken password $SERVICE_PASSWORD
|
|
iniset $SENLIN_CONF keystone_authtoken project_name $SERVICE_TENANT_NAME
|
|
iniset $SENLIN_CONF keystone_authtoken project_domain_name Default
|
|
iniset $SENLIN_CONF keystone_authtoken user_domain_name Default
|
|
iniset $SENLIN_CONF keystone_authtoken auth_type password
|
|
iniset $SENLIN_CONF keystone_authtoken service_token_roles_required True
|
|
|
|
# Senlin service credentials
|
|
iniset $SENLIN_CONF authentication auth_url $KEYSTONE_AUTH_URI/v3
|
|
iniset $SENLIN_CONF authentication service_username senlin
|
|
iniset $SENLIN_CONF authentication service_password $SERVICE_PASSWORD
|
|
iniset $SENLIN_CONF authentication service_project_name $SERVICE_TENANT_NAME
|
|
|
|
# Senlin Conductor options
|
|
iniset $SENLIN_CONF conductor workers $API_WORKERS
|
|
|
|
# Senlin Conductor options
|
|
iniset $SENLIN_CONF engine workers $API_WORKERS
|
|
|
|
# Senlin Health-Manager options
|
|
iniset $SENLIN_CONF health_manager workers $API_WORKERS
|
|
|
|
# Zaqar options for message receiver
|
|
iniset $SENLIN_CONF zaqar auth_type password
|
|
iniset $SENLIN_CONF zaqar username zaqar
|
|
iniset $SENLIN_CONF zaqar password $SERVICE_PASSWORD
|
|
iniset $SENLIN_CONF zaqar project_name $SERVICE_TENANT_NAME
|
|
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_WSGI_MODE" == "uwsgi" ]]; then
|
|
write_uwsgi_config "$SENLIN_UWSGI_CONF" "$SENLIN_UWSGI" "/cluster"
|
|
else
|
|
_config_senlin_apache_wsgi
|
|
fi
|
|
}
|
|
|
|
# _config_senlin_apache_wsgi() - Configure mod_wsgi
|
|
function _config_senlin_apache_wsgi {
|
|
local senlin_api_apache_conf
|
|
local venv_path=""
|
|
local senlin_bin_dir=""
|
|
senlin_bin_dir=$(get_python_exec_prefix)
|
|
senlin_api_apache_conf=$(apache_site_config_for senlin-api)
|
|
|
|
if [[ ${USE_VENV} = True ]]; then
|
|
venv_path="python-path=${PROJECT_VENV["senlin"]}/lib/$(python_version)/site-packages"
|
|
senlin_bin_dir=${PROJECT_VENV["senlin"]}/bin
|
|
fi
|
|
|
|
sudo cp $SENLIN_DIR/devstack/files/apache-senlin-api.template $senlin_api_apache_conf
|
|
sudo sed -e "
|
|
s|%APACHE_NAME%|$APACHE_NAME|g;
|
|
s|%SENLIN_BIN_DIR%|$SENLIN_BIN_DIR|g;
|
|
s|%SSLENGINE%|$senlin_ssl|g;
|
|
s|%SSLCERTFILE%|$senlin_certfile|g;
|
|
s|%SSLKEYFILE%|$senlin_keyfile|g;
|
|
s|%USER%|$STACK_USER|g;
|
|
s|%VIRTUALENV%|$venv_path|g;
|
|
s|%APIWORKERS%|$API_WORKERS|g;
|
|
" -i $senlin_api_apache_conf
|
|
}
|
|
|
|
# init_senlin() - Initialize database
|
|
function init_senlin {
|
|
|
|
# (re)create senlin database
|
|
recreate_database senlin utf8
|
|
|
|
$SENLIN_BIN_DIR/senlin-manage db_sync
|
|
create_senlin_cache_dir
|
|
}
|
|
|
|
# create_senlin_cache_dir() - Part of the init_senlin() process
|
|
function create_senlin_cache_dir {
|
|
# Create cache dirs
|
|
sudo mkdir -p $SENLIN_AUTH_CACHE_DIR
|
|
sudo install -d -o $STACK_USER $SENLIN_AUTH_CACHE_DIR
|
|
}
|
|
|
|
# install_senlinclient() - Collect source and prepare
|
|
function install_senlinclient {
|
|
if use_library_from_git "python-senlinclient"; then
|
|
git_clone $SENLINCLIENT_REPO $SENLINCLIENT_DIR $SENLINCLIENT_BRANCH
|
|
setup_develop $SENLINCLIENT_DIR
|
|
else
|
|
pip_install --upgrade python-senlinclient
|
|
fi
|
|
}
|
|
|
|
# install_senlin_dashboard() - Collect source and prepare
|
|
function install_senlin_dashboard {
|
|
# NOTE(Liuqing): workaround for devstack bug: 1540328
|
|
# https://bugs.launchpad.net/devstack/+bug/1540328
|
|
# where devstack install 'test-requirements' but should not do it
|
|
# for senlin-dashboard project as it installs Horizon from url.
|
|
# Remove following two 'mv' commands when mentioned bug is fixed.
|
|
if use_library_from_git "senlin-dashboard"; then
|
|
git_clone $SENLIN_DASHBOARD_REPO $SENLIN_DASHBOARD_DIR $SENLIN_DASHBOARD_BRANCH
|
|
mv $SENLIN_DASHBOARD_DIR/test-requirements.txt $SENLIN_DASHBOARD_DIR/_test-requirements.txt
|
|
setup_develop $SENLIN_DASHBOARD_DIR
|
|
mv $SENLIN_DASHBOARD_DIR/_test-requirements.txt $SENLIN_DASHBOARD_DIR/test-requirements.txt
|
|
else
|
|
pip_install --upgrade senlin-dashboard
|
|
fi
|
|
}
|
|
|
|
# configure_senlin_dashboard() - Set config files
|
|
function config_senlin_dashboard {
|
|
# Install Senlin Dashboard as plugin for Horizon
|
|
ln -sf $SENLIN_DASHBOARD_DIR/senlin_dashboard/enabled/_50_senlin.py $HORIZON_DIR/openstack_dashboard/local/enabled/_50_senlin.py
|
|
# Enable senlin policy
|
|
ln -sf $SENLIN_DASHBOARD_DIR/senlin_dashboard/conf/senlin_policy.json $HORIZON_DIR/openstack_dashboard/conf/senlin_policy.json
|
|
}
|
|
|
|
# cleanup_senlin_dashboard() - Remove residual data files, anything left over from previous
|
|
# runs that a clean run would need to clean up
|
|
function cleanup_senlin_dashboard {
|
|
sudo rm -rf $HORIZON_DIR/openstack_dashboard/local/enabled/_50_senlin.py
|
|
sudo rm -rf $HORIZON_DIR/openstack_dashboard/conf/senlin_policy.json
|
|
}
|
|
|
|
# install_senlin() - Collect source and prepare
|
|
function install_senlin {
|
|
if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
|
|
install_apache_uwsgi
|
|
else
|
|
install_apache_wsgi
|
|
fi
|
|
|
|
git_clone $SENLIN_REPO $SENLIN_DIR $SENLIN_BRANCH
|
|
setup_develop $SENLIN_DIR
|
|
}
|
|
|
|
# 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-conductor "$SENLIN_BIN_DIR/senlin-conductor --config-file=$SENLIN_CONF"
|
|
run_process sl-health-manager "$SENLIN_BIN_DIR/senlin-health-manager --config-file=$SENLIN_CONF"
|
|
|
|
if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
|
|
run_process sl-api "$SENLIN_BIN_DIR/uwsgi --procname-prefix senlin-api --ini $SENLIN_UWSGI_CONF"
|
|
else
|
|
enable_apache_site senlin-api
|
|
restart_apache_server
|
|
tail_log senlin-api /var/log/$APACHE_NAME/senlin-api.log
|
|
fi
|
|
|
|
echo "Waiting for senlin-api to start..."
|
|
if ! wait_for_service $SERVICE_TIMEOUT $SENLIN_SERVICE_PROTOCOL://$SENLIN_API_HOST/cluster; then
|
|
die $LINENO "senlin-api did not start"
|
|
fi
|
|
}
|
|
|
|
# stop_senlin() - Stop running processes
|
|
function stop_senlin {
|
|
# Kill the screen windows
|
|
stop_process sl-eng
|
|
stop_process sl-conductor
|
|
stop_process sl-health-manager
|
|
|
|
if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
|
|
stop_process sl-api
|
|
else
|
|
disable_apache_site senlin-api
|
|
restart_apache_server
|
|
fi
|
|
}
|
|
|
|
# create_senlin_accounts() - Set up common required senlin accounts
|
|
function create_senlin_accounts {
|
|
create_service_user "senlin"
|
|
|
|
local senlin_api_url="$SENLIN_SERVICE_PROTOCOL://$SENLIN_API_HOST/cluster"
|
|
|
|
get_or_create_service "senlin" "clustering" "Senlin Clustering Service"
|
|
get_or_create_endpoint "clustering" \
|
|
"$REGION_NAME" \
|
|
"$senlin_api_url" \
|
|
"$senlin_api_url" \
|
|
"$senlin_api_url"
|
|
|
|
# get or add 'service' role to 'senlin' on 'demo' project
|
|
get_or_add_user_project_role "service" "senlin" "demo"
|
|
}
|
|
|
|
# Restore xtrace
|
|
$XTRACE
|
|
|
|
# Tell emacs to use shell-script-mode
|
|
## Local variables:
|
|
## mode: shell-script
|
|
## End:
|