2012-07-26 11:22:05 -07:00
# lib/ceilometer
2012-12-21 11:03:37 -06:00
# Install and start **Ceilometer** service
2013-07-30 14:14:55 +00:00
# To enable a minimal set of Ceilometer services, add the following to localrc:
2013-10-05 12:11:07 +01:00
#
2013-11-26 13:30:11 -05:00
# enable_service ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api
2013-07-30 14:14:55 +00:00
#
# To ensure Ceilometer alarming services are enabled also, further add to the localrc:
2013-10-05 12:11:07 +01:00
#
2013-09-20 21:11:25 +00:00
# enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator
2012-09-17 20:25:41 +05:30
2012-07-26 11:22:05 -07:00
# Dependencies:
2013-10-24 11:27:02 +01:00
#
2012-07-26 11:22:05 -07:00
# - functions
2012-11-01 16:23:52 -04:00
# - OS_AUTH_URL for auth in api
2012-09-27 09:36:33 +01:00
# - DEST set to the destination directory
2012-11-01 16:23:52 -04:00
# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
2013-01-06 22:40:09 +01:00
# - STACK_USER service user
2012-07-26 11:22:05 -07:00
# stack.sh
# ---------
2013-10-24 11:27:02 +01:00
# - install_ceilometer
# - configure_ceilometer
# - init_ceilometer
# - start_ceilometer
# - stop_ceilometer
# - cleanup_ceilometer
2012-07-26 11:22:05 -07:00
2012-09-13 17:16:12 -05:00
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
2012-07-26 11:22:05 -07:00
# Defaults
# --------
2012-12-21 11:03:37 -06:00
# Set up default directories
2012-07-26 11:22:05 -07:00
CEILOMETER_DIR=$DEST/ceilometer
2013-01-09 09:33:07 +08:00
CEILOMETERCLIENT_DIR=$DEST/python-ceilometerclient
2012-12-21 11:03:37 -06:00
CEILOMETER_CONF_DIR=/etc/ceilometer
CEILOMETER_CONF=$CEILOMETER_CONF_DIR/ceilometer.conf
CEILOMETER_API_LOG_DIR=/var/log/ceilometer-api
2013-01-09 10:41:54 +08:00
CEILOMETER_AUTH_CACHE_DIR=${CEILOMETER_AUTH_CACHE_DIR:-/var/cache/ceilometer}
2012-12-21 11:03:37 -06:00
2012-08-17 12:52:27 -04:00
# Support potential entry-points console scripts
2013-07-17 15:22:21 +08:00
CEILOMETER_BIN_DIR=$(get_python_exec_prefix)
2012-07-26 11:22:05 -07:00
2013-07-17 15:22:21 +08:00
# Set up database backend
2013-08-27 11:43:53 +02:00
CEILOMETER_BACKEND=${CEILOMETER_BACKEND:-mysql}
2013-04-08 15:38:03 -05:00
2014-01-09 13:27:35 +01:00
# Ceilometer connection info.
CEILOMETER_SERVICE_PROTOCOL=http
CEILOMETER_SERVICE_HOST=$SERVICE_HOST
CEILOMETER_SERVICE_PORT=${CEILOMETER_SERVICE_PORT:-8777}
2014-01-29 16:22:11 -06:00
2014-07-01 14:15:52 +04:00
# To enable OSprofiler change value of this variable to "notifications,profiler"
CEILOMETER_NOTIFICATION_TOPICS=${CEILOMETER_NOTIFICATION_TOPICS:-notifications}
2014-01-29 16:22:11 -06:00
# Tell Tempest this project is present
TEMPEST_SERVICES+=,ceilometer
2014-01-09 13:27:35 +01:00
2013-04-08 15:38:03 -05:00
# Functions
# ---------
2014-01-15 15:04:49 -06:00
# Test if any Ceilometer services are enabled
# is_ceilometer_enabled
function is_ceilometer_enabled {
[[ ,${ENABLED_SERVICES} =~ ,"ceilometer-" ]] && return 0
return 1
}
2014-01-09 13:27:35 +01:00
# create_ceilometer_accounts() - Set up common required ceilometer accounts
2014-03-03 14:31:29 -06:00
# Project User Roles
# ------------------------------------------------------------------
# SERVICE_TENANT_NAME ceilometer admin
# SERVICE_TENANT_NAME ceilometer ResellerAdmin (if Swift is enabled)
2014-01-09 13:27:35 +01:00
create_ceilometer_accounts() {
2014-08-19 19:31:34 -05:00
local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
local admin_role=$(openstack role list | awk "/ admin / { print \$2 }")
2014-01-09 13:27:35 +01:00
# Ceilometer
if [[ "$ENABLED_SERVICES" =~ "ceilometer-api" ]]; then
2014-08-19 19:31:34 -05:00
local ceilometer_user=$(get_or_create_user "ceilometer" \
"$SERVICE_PASSWORD" $service_tenant)
get_or_add_user_role $admin_role $ceilometer_user $service_tenant
2014-02-28 14:15:19 +01:00
2014-01-09 13:27:35 +01:00
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
2014-08-19 19:31:34 -05:00
local ceilometer_service=$(get_or_create_service "ceilometer" \
2014-02-28 14:15:19 +01:00
"metering" "OpenStack Telemetry Service")
2014-08-19 19:31:34 -05:00
get_or_create_endpoint $ceilometer_service \
2014-02-28 14:15:19 +01:00
"$REGION_NAME" \
"$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
"$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
"$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
2014-01-09 13:27:35 +01:00
fi
2014-03-03 14:31:29 -06:00
if is_service_enabled swift; then
# Ceilometer needs ResellerAdmin role to access swift account stats.
2014-02-28 14:15:19 +01:00
get_or_add_user_role "ResellerAdmin" "ceilometer" $SERVICE_TENANT_NAME
2014-03-03 14:31:29 -06:00
fi
2014-01-09 13:27:35 +01:00
fi
}
2013-04-08 15:38:03 -05:00
2012-07-26 11:22:05 -07:00
# cleanup_ceilometer() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
2014-02-21 15:35:08 +11:00
function cleanup_ceilometer {
2014-03-11 09:35:55 +11:00
if [ "$CEILOMETER_BACKEND" != 'mysql' ] && [ "$CEILOMETER_BACKEND" != 'postgresql' ] ; then
mongo ceilometer --eval "db.dropDatabase();"
fi
2012-07-26 11:22:05 -07:00
}
# configure_ceilometer() - Set config files, create data dirs, etc
2014-02-21 15:35:08 +11:00
function configure_ceilometer {
2012-09-22 10:52:31 -04:00
[ ! -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
2013-11-19 13:31:04 +01:00
sudo chown $STACK_USER $CEILOMETER_CONF_DIR
2012-09-17 20:25:41 +05:30
2012-09-22 10:52:31 -04:00
[ ! -d $CEILOMETER_API_LOG_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR
2013-11-19 13:31:04 +01:00
sudo chown $STACK_USER $CEILOMETER_API_LOG_DIR
2012-07-26 11:22:05 -07:00
2013-03-01 12:09:01 +00:00
iniset_rpc_backend ceilometer $CEILOMETER_CONF DEFAULT
2013-02-22 21:59:52 +00:00
2014-07-01 14:15:52 +04:00
iniset $CEILOMETER_CONF DEFAULT notification_topics "$CEILOMETER_NOTIFICATION_TOPICS"
2012-10-24 16:32:01 +02:00
iniset $CEILOMETER_CONF DEFAULT verbose True
2014-03-06 15:14:59 +04:00
iniset $CEILOMETER_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
2012-10-02 17:29:23 -04:00
2012-11-01 16:23:52 -04:00
# Install the policy file for the API server
cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
iniset $CEILOMETER_CONF DEFAULT policy_file $CEILOMETER_CONF_DIR/policy.json
2014-05-16 16:27:41 +08:00
cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
cp $CEILOMETER_DIR/etc/ceilometer/api_paste.ini $CEILOMETER_CONF_DIR
cp $CEILOMETER_DIR/etc/ceilometer/event_definitions.yaml $CEILOMETER_CONF_DIR
2013-10-23 09:26:25 +02:00
if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
fi
2012-11-14 16:23:04 +00:00
# the compute and central agents need these credentials in order to
2014-04-16 14:52:12 +08:00
# call out to other services' public APIs
# the alarm evaluator needs these options to call ceilometer APIs
iniset $CEILOMETER_CONF service_credentials os_username ceilometer
iniset $CEILOMETER_CONF service_credentials os_password $SERVICE_PASSWORD
iniset $CEILOMETER_CONF service_credentials os_tenant_name $SERVICE_TENANT_NAME
2012-11-14 16:23:04 +00:00
2014-09-19 17:22:22 -05:00
configure_auth_token_middleware $CEILOMETER_CONF ceilometer $CEILOMETER_AUTH_CACHE_DIR
2012-11-01 16:23:52 -04:00
2013-10-24 18:57:40 +00:00
if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
2013-07-17 15:22:21 +08:00
iniset $CEILOMETER_CONF database connection `database_connection_url ceilometer`
2014-09-16 17:25:33 -05:00
iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
2013-07-17 15:22:21 +08:00
else
iniset $CEILOMETER_CONF database connection mongodb://localhost:27017/ceilometer
configure_mongodb
cleanup_ceilometer
fi
2014-03-14 19:21:48 +05:30
if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
iniset $CEILOMETER_CONF DEFAULT hypervisor_inspector vsphere
iniset $CEILOMETER_CONF vmware host_ip "$VMWAREAPI_IP"
iniset $CEILOMETER_CONF vmware host_username "$VMWAREAPI_USER"
iniset $CEILOMETER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
fi
2012-07-26 11:22:05 -07:00
}
2014-02-21 15:35:08 +11:00
function configure_mongodb {
2014-03-11 09:35:55 +11:00
# server package is the same on all
local packages=mongodb-server
if is_fedora; then
# mongodb client + python bindings
packages="${packages} mongodb pymongo"
else
packages="${packages} python-pymongo"
fi
install_package ${packages}
2013-04-08 15:38:03 -05:00
if is_fedora; then
2013-03-04 13:13:03 -05:00
# ensure smallfiles selected to minimize freespace requirements
sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
restart_service mongod
fi
2014-03-11 09:35:55 +11:00
# give mongodb time to start-up
sleep 5
2013-03-04 13:13:03 -05:00
}
2013-01-09 10:41:54 +08:00
# init_ceilometer() - Initialize etc.
2014-02-21 15:35:08 +11:00
function init_ceilometer {
2013-01-09 10:41:54 +08:00
# Create cache dir
sudo mkdir -p $CEILOMETER_AUTH_CACHE_DIR
2013-01-06 22:40:09 +01:00
sudo chown $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
2013-01-09 10:41:54 +08:00
rm -f $CEILOMETER_AUTH_CACHE_DIR/*
2013-07-17 15:22:21 +08:00
2014-02-28 21:09:33 -05:00
if is_service_enabled mysql postgresql; then
if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
recreate_database ceilometer utf8
$CEILOMETER_BIN_DIR/ceilometer-dbsync
fi
2013-07-17 15:22:21 +08:00
fi
2013-01-09 10:41:54 +08:00
}
2012-07-26 11:22:05 -07:00
# install_ceilometer() - Collect source and prepare
2014-02-21 15:35:08 +11:00
function install_ceilometer {
2012-07-26 11:22:05 -07:00
git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
2014-07-22 14:26:05 -07:00
setup_develop $CEILOMETER_DIR
2012-07-26 11:22:05 -07:00
}
2013-01-09 09:33:07 +08:00
# install_ceilometerclient() - Collect source and prepare
2014-02-21 15:35:08 +11:00
function install_ceilometerclient {
2013-01-09 09:33:07 +08:00
git_clone $CEILOMETERCLIENT_REPO $CEILOMETERCLIENT_DIR $CEILOMETERCLIENT_BRANCH
2014-07-22 14:26:05 -07:00
setup_develop $CEILOMETERCLIENT_DIR
sudo install -D -m 0644 -o $STACK_USER {$CEILOMETERCLIENT_DIR/tools/,/etc/bash_completion.d/}ceilometer.bash_completion
2013-01-09 09:33:07 +08:00
}
2012-07-26 11:22:05 -07:00
# start_ceilometer() - Start running processes, including screen
2014-02-21 15:35:08 +11:00
function start_ceilometer {
2014-09-09 13:46:02 +01:00
run_process ceilometer-acentral "ceilometer-agent-central --config-file $CEILOMETER_CONF"
run_process ceilometer-anotification "ceilometer-agent-notification --config-file $CEILOMETER_CONF"
run_process ceilometer-collector "ceilometer-collector --config-file $CEILOMETER_CONF"
run_process ceilometer-api "ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR --config-file $CEILOMETER_CONF"
2014-08-12 14:27:58 +01:00
# Start the compute agent last to allow time for the collector to
# fully wake up and connect to the message bus. See bug #1355809
2013-10-23 06:46:43 +00:00
if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
2014-09-17 14:54:21 -04:00
run_process ceilometer-acompute "ceilometer-agent-compute --config-file $CEILOMETER_CONF" $LIBVIRT_GROUP
2013-10-23 06:46:43 +00:00
fi
2014-03-14 19:21:48 +05:30
if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
2014-09-09 13:46:02 +01:00
run_process ceilometer-acompute "ceilometer-agent-compute --config-file $CEILOMETER_CONF"
2014-03-14 19:21:48 +05:30
fi
2013-10-23 10:37:05 +02:00
2014-02-28 20:16:20 -05:00
# only die on API if it was actually intended to be turned on
2014-03-04 15:02:04 -05:00
if is_service_enabled ceilometer-api; then
2014-02-28 20:16:20 -05:00
echo "Waiting for ceilometer-api to start..."
if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl --noproxy '*' -s http://localhost:8777/v2/ >/dev/null; do sleep 1; done"; then
die $LINENO "ceilometer-api did not start"
fi
2013-10-23 10:37:05 +02:00
fi
2014-09-09 13:46:02 +01:00
run_process ceilometer-alarm-notifier "ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
run_process ceilometer-alarm-evaluator "ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
2012-07-26 11:22:05 -07:00
}
2012-09-13 17:16:12 -05:00
2012-09-10 14:10:27 -05:00
# stop_ceilometer() - Stop running processes
2014-02-21 15:35:08 +11:00
function stop_ceilometer {
2012-09-10 14:10:27 -05:00
# Kill the ceilometer screen windows
2013-11-26 13:30:11 -05:00
for serv in ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api ceilometer-alarm-notifier ceilometer-alarm-evaluator; do
2014-09-09 13:46:02 +01:00
stop_process $serv
2012-09-10 14:10:27 -05:00
done
}
2013-04-08 15:38:03 -05:00
2012-09-13 17:16:12 -05:00
# Restore xtrace
$XTRACE
2013-03-29 14:34:53 -04:00
2013-10-24 11:27:02 +01:00
# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: