blob: c6c4c87fbca488e8b55d4ad4c1abce43fcbd412e [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
John H. Tran93361642012-07-26 11:22:05 -07003# lib/ceilometer
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Install and start **Ceilometer** service
5
Chris Denta9c25942014-12-08 14:26:28 +00006# To enable a minimal set of Ceilometer services, add the following to the
Dean Troyerdc97cb72015-03-28 08:20:50 -05007# ``localrc`` section of ``local.conf``:
Adam Spierscb961592013-10-05 12:11:07 +01008#
Gordon Chung1c402282013-11-26 13:30:11 -05009# enable_service ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api
Eoghan Glynn8d137032013-07-30 14:14:55 +000010#
Chris Denta9c25942014-12-08 14:26:28 +000011# To ensure Ceilometer alarming services are enabled also, further add to the
12# localrc section of local.conf:
Adam Spierscb961592013-10-05 12:11:07 +010013#
Eoghan Glynn19eed742013-09-20 21:11:25 +000014# enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator
Chris Denta9c25942014-12-08 14:26:28 +000015#
Lianhao Luc39f6402015-03-24 12:36:00 +080016# To enable Ceilometer to collect the IPMI based meters, further add to the
17# localrc section of local.conf:
18#
19# enable_service ceilometer-aipmi
20#
21# NOTE: Currently, there are two ways to get the IPMI based meters in
22# OpenStack. One way is to configure Ironic conductor to report those meters
23# for the nodes managed by Ironic and to have Ceilometer notification
24# agent to collect them. Ironic by default does NOT enable that reporting
25# functionality. So in order to do so, users need to set the option of
26# conductor.send_sensor_data to true in the ironic.conf configuration file
27# for the Ironic conductor service, and also enable the
28# ceilometer-anotification service.
29#
30# The other way is to use Ceilometer ipmi agent only to get the IPMI based
31# meters. To avoid duplicated meters, users need to make sure to set the
32# option of conductor.send_sensor_data to false in the ironic.conf
33# configuration file if the node on which Ceilometer ipmi agent is running
34# is also managed by Ironic.
35#
Chris Denta9c25942014-12-08 14:26:28 +000036# Several variables set in the localrc section adjust common behaviors
37# of Ceilometer (see within for additional settings):
38#
39# CEILOMETER_USE_MOD_WSGI: When True, run the api under mod_wsgi.
Dean Troyerdc97cb72015-03-28 08:20:50 -050040# CEILOMETER_PIPELINE_INTERVAL: Seconds between pipeline processing runs. Default 600.
41# CEILOMETER_BACKEND: Database backend (e.g. 'mysql', 'mongodb', 'es')
42# CEILOMETER_COORDINATION_URL: URL for group membership service provided by tooz.
gordon chung76e724b2015-02-11 18:28:37 -050043# CEILOMETER_EVENTS: Enable event collection
Chris Denta9c25942014-12-08 14:26:28 +000044
John H. Tran93361642012-07-26 11:22:05 -070045# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010046#
John H. Tran93361642012-07-26 11:22:05 -070047# - functions
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040048# - OS_AUTH_URL for auth in api
Eoghan Glynnad80ead2012-09-27 09:36:33 +010049# - DEST set to the destination directory
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040050# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
Attila Fazekas91b8d132013-01-06 22:40:09 +010051# - STACK_USER service user
John H. Tran93361642012-07-26 11:22:05 -070052
53# stack.sh
54# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010055# - install_ceilometer
56# - configure_ceilometer
57# - init_ceilometer
58# - start_ceilometer
59# - stop_ceilometer
60# - cleanup_ceilometer
John H. Tran93361642012-07-26 11:22:05 -070061
Dean Troyer7903b792012-09-13 17:16:12 -050062# Save trace setting
63XTRACE=$(set +o | grep xtrace)
64set +o xtrace
John H. Tran93361642012-07-26 11:22:05 -070065
66
67# Defaults
68# --------
69
Dean Troyer6d04fd72012-12-21 11:03:37 -060070# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050071GITDIR["python-ceilometerclient"]=$DEST/python-ceilometerclient
gordon chungad61e7f2015-02-12 15:17:25 -050072GITDIR["ceilometermiddleware"]=$DEST/ceilometermiddleware
Sean Dague5cb19062014-11-01 01:37:45 +010073
John H. Tran93361642012-07-26 11:22:05 -070074CEILOMETER_DIR=$DEST/ceilometer
Dean Troyer6d04fd72012-12-21 11:03:37 -060075CEILOMETER_CONF_DIR=/etc/ceilometer
76CEILOMETER_CONF=$CEILOMETER_CONF_DIR/ceilometer.conf
77CEILOMETER_API_LOG_DIR=/var/log/ceilometer-api
Lianhao Lu8c548492013-01-09 10:41:54 +080078CEILOMETER_AUTH_CACHE_DIR=${CEILOMETER_AUTH_CACHE_DIR:-/var/cache/ceilometer}
Chris Dentae6fb182014-09-16 15:17:13 +010079CEILOMETER_WSGI_DIR=${CEILOMETER_WSGI_DIR:-/var/www/ceilometer}
Dean Troyer6d04fd72012-12-21 11:03:37 -060080
Chris Dent027e2ea2015-06-05 18:43:50 +000081# Support potential entry-points console scripts in VENV or not
82if [[ ${USE_VENV} = True ]]; then
83 PROJECT_VENV["ceilometer"]=${CEILOMETER_DIR}.venv
84 CEILOMETER_BIN_DIR=${PROJECT_VENV["ceilometer"]}/bin
85else
86 CEILOMETER_BIN_DIR=$(get_python_exec_prefix)
87fi
John H. Tran93361642012-07-26 11:22:05 -070088
Guangyu Suo9778b3c2013-07-17 15:22:21 +080089# Set up database backend
Julien Danjou69f74572013-08-27 11:43:53 +020090CEILOMETER_BACKEND=${CEILOMETER_BACKEND:-mysql}
Dean Troyercc6b4432013-04-08 15:38:03 -050091
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010092# Ceilometer connection info.
93CEILOMETER_SERVICE_PROTOCOL=http
94CEILOMETER_SERVICE_HOST=$SERVICE_HOST
95CEILOMETER_SERVICE_PORT=${CEILOMETER_SERVICE_PORT:-8777}
Sean Dague53753292014-12-04 19:38:15 -050096CEILOMETER_USE_MOD_WSGI=$(trueorfalse False CEILOMETER_USE_MOD_WSGI)
Dean Troyer4237f592014-01-29 16:22:11 -060097
Boris Pavlovic46e1aba2014-07-01 14:15:52 +040098# To enable OSprofiler change value of this variable to "notifications,profiler"
99CEILOMETER_NOTIFICATION_TOPICS=${CEILOMETER_NOTIFICATION_TOPICS:-notifications}
gordon chung76e724b2015-02-11 18:28:37 -0500100CEILOMETER_EVENTS=${CEILOMETER_EVENTS:-True}
Boris Pavlovic46e1aba2014-07-01 14:15:52 +0400101
Sean Dague53753292014-12-04 19:38:15 -0500102CEILOMETER_COORDINATION_URL=${CEILOMETER_COORDINATION_URL:-}
103CEILOMETER_PIPELINE_INTERVAL=${CEILOMETER_PIPELINE_INTERVAL:-}
104
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100105
Dean Troyercc6b4432013-04-08 15:38:03 -0500106# Functions
107# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600108
109# Test if any Ceilometer services are enabled
110# is_ceilometer_enabled
111function is_ceilometer_enabled {
112 [[ ,${ENABLED_SERVICES} =~ ,"ceilometer-" ]] && return 0
113 return 1
114}
115
Dean Troyerdc97cb72015-03-28 08:20:50 -0500116# create_ceilometer_accounts() - Set up common required Ceilometer accounts
Chris Dent67bc8e82014-10-08 12:07:46 +0100117#
Dean Troyer42a59c22014-03-03 14:31:29 -0600118# Project User Roles
119# ------------------------------------------------------------------
120# SERVICE_TENANT_NAME ceilometer admin
121# SERVICE_TENANT_NAME ceilometer ResellerAdmin (if Swift is enabled)
Chris Dent67bc8e82014-10-08 12:07:46 +0100122function create_ceilometer_accounts {
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100123
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100124 # Ceilometer
125 if [[ "$ENABLED_SERVICES" =~ "ceilometer-api" ]]; then
Jamie Lennox85ff5322015-01-28 14:28:01 +1000126
Chris Dent230e03a2015-02-16 22:07:00 +0000127 create_service_user "ceilometer" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100128
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100129 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000130 get_or_create_service "ceilometer" "metering" "OpenStack Telemetry Service"
131 get_or_create_endpoint "metering" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100132 "$REGION_NAME" \
133 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
134 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
135 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100136 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600137 if is_service_enabled swift; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500138 # Ceilometer needs ResellerAdmin role to access Swift account stats.
Jamie Lennox9b215db2015-02-10 18:19:57 +1100139 get_or_add_user_project_role "ResellerAdmin" "ceilometer" $SERVICE_TENANT_NAME
Dean Troyer42a59c22014-03-03 14:31:29 -0600140 fi
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100141 fi
142}
143
Dean Troyercc6b4432013-04-08 15:38:03 -0500144
Dean Troyerdc97cb72015-03-28 08:20:50 -0500145# _cleanup_keystone_apache_wsgi() - Remove WSGI files, disable and remove Apache vhost file
Chris Dentae6fb182014-09-16 15:17:13 +0100146function _cleanup_ceilometer_apache_wsgi {
147 sudo rm -f $CEILOMETER_WSGI_DIR/*
148 sudo rm -f $(apache_site_config_for ceilometer)
149}
150
John H. Tran93361642012-07-26 11:22:05 -0700151# cleanup_ceilometer() - Remove residual data files, anything left over from previous
152# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100153function cleanup_ceilometer {
gordon chung76e724b2015-02-11 18:28:37 -0500154 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
Ian Wienand936284b2014-03-11 09:35:55 +1100155 mongo ceilometer --eval "db.dropDatabase();"
gordon chung76e724b2015-02-11 18:28:37 -0500156 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
157 curl -XDELETE "localhost:9200/events_*"
Ian Wienand936284b2014-03-11 09:35:55 +1100158 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100159 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
160 _cleanup_ceilometer_apache_wsgi
161 fi
162}
163
164function _config_ceilometer_apache_wsgi {
165 sudo mkdir -p $CEILOMETER_WSGI_DIR
166
167 local ceilometer_apache_conf=$(apache_site_config_for ceilometer)
168 local apache_version=$(get_apache_version)
Chris Dent027e2ea2015-06-05 18:43:50 +0000169 local venv_path=""
Chris Dentae6fb182014-09-16 15:17:13 +0100170
Dean Troyerdc97cb72015-03-28 08:20:50 -0500171 # Copy proxy vhost and wsgi file
Chris Dentae6fb182014-09-16 15:17:13 +0100172 sudo cp $CEILOMETER_DIR/ceilometer/api/app.wsgi $CEILOMETER_WSGI_DIR/app
173
Chris Dent027e2ea2015-06-05 18:43:50 +0000174 if [[ ${USE_VENV} = True ]]; then
175 venv_path="python-path=${PROJECT_VENV["ceilometer"]}/lib/$(python_version)/site-packages"
176 fi
177
Chris Dentae6fb182014-09-16 15:17:13 +0100178 sudo cp $FILES/apache-ceilometer.template $ceilometer_apache_conf
179 sudo sed -e "
180 s|%PORT%|$CEILOMETER_SERVICE_PORT|g;
181 s|%APACHE_NAME%|$APACHE_NAME|g;
182 s|%WSGIAPP%|$CEILOMETER_WSGI_DIR/app|g;
Chris Dent027e2ea2015-06-05 18:43:50 +0000183 s|%USER%|$STACK_USER|g;
184 s|%VIRTUALENV%|$venv_path|g
Chris Dentae6fb182014-09-16 15:17:13 +0100185 " -i $ceilometer_apache_conf
John H. Tran93361642012-07-26 11:22:05 -0700186}
187
188# configure_ceilometer() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100189function configure_ceilometer {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500190 sudo install -d -o $STACK_USER -m 755 $CEILOMETER_CONF_DIR $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -0700191
Brant Knudson2dd110c2015-03-14 12:39:14 -0500192 iniset_rpc_backend ceilometer $CEILOMETER_CONF
Eoghan Glynnd36268a2013-02-22 21:59:52 +0000193
Boris Pavlovic46e1aba2014-07-01 14:15:52 +0400194 iniset $CEILOMETER_CONF DEFAULT notification_topics "$CEILOMETER_NOTIFICATION_TOPICS"
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200195 iniset $CEILOMETER_CONF DEFAULT verbose True
Nadya Privalova423d7902014-03-06 15:14:59 +0400196 iniset $CEILOMETER_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Doug Hellmann53a5f422012-10-02 17:29:23 -0400197
Chris Dent8abd8592014-10-08 15:24:25 +0100198 if [[ -n "$CEILOMETER_COORDINATION_URL" ]]; then
199 iniset $CEILOMETER_CONF coordination backend_url $CEILOMETER_COORDINATION_URL
200 iniset $CEILOMETER_CONF compute workload_partitioning True
201 fi
202
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400203 # Install the policy file for the API server
204 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
Chris Dent74a85b02015-04-22 18:02:39 +0000205 iniset $CEILOMETER_CONF oslo_policy policy_file $CEILOMETER_CONF_DIR/policy.json
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400206
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800207 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
gordon chung99f5bcc2015-02-03 09:23:39 -0500208 cp $CEILOMETER_DIR/etc/ceilometer/event_pipeline.yaml $CEILOMETER_CONF_DIR
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800209 cp $CEILOMETER_DIR/etc/ceilometer/api_paste.ini $CEILOMETER_CONF_DIR
210 cp $CEILOMETER_DIR/etc/ceilometer/event_definitions.yaml $CEILOMETER_CONF_DIR
Mehdi Abaakoukeef5d852015-07-24 10:55:42 +0200211 cp $CEILOMETER_DIR/etc/ceilometer/gnocchi_archive_policy_map.yaml $CEILOMETER_CONF_DIR
212 cp $CEILOMETER_DIR/etc/ceilometer/gnocchi_resources.yaml $CEILOMETER_CONF_DIR
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800213
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +0200214 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
215 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
216 fi
217
Dean Troyerdc97cb72015-03-28 08:20:50 -0500218 # The compute and central agents need these credentials in order to
219 # call out to other services' public APIs.
220 # The alarm evaluator needs these options to call ceilometer APIs
ZhiQiang Fan1af4afb2014-04-16 14:52:12 +0800221 iniset $CEILOMETER_CONF service_credentials os_username ceilometer
222 iniset $CEILOMETER_CONF service_credentials os_password $SERVICE_PASSWORD
223 iniset $CEILOMETER_CONF service_credentials os_tenant_name $SERVICE_TENANT_NAME
Ethan Lynna134f652015-01-12 12:59:30 +0800224 iniset $CEILOMETER_CONF service_credentials os_region_name $REGION_NAME
225 iniset $CEILOMETER_CONF service_credentials os_auth_url $KEYSTONE_SERVICE_URI/v2.0
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000226
Brant Knudson05952372014-09-19 17:22:22 -0500227 configure_auth_token_middleware $CEILOMETER_CONF ceilometer $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400228
gordon chung76e724b2015-02-11 18:28:37 -0500229 iniset $CEILOMETER_CONF notification store_events $CEILOMETER_EVENTS
230
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000231 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500232 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
233 iniset $CEILOMETER_CONF database event_connection $(database_connection_url ceilometer)
234 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
Dean Troyer05bd7b82014-09-16 17:25:33 -0500235 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
gordon chung76e724b2015-02-11 18:28:37 -0500236 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
237 # es is only supported for events. we will use sql for alarming/metering.
238 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
239 iniset $CEILOMETER_CONF database event_connection es://localhost:9200
240 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
241 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
242 ${TOP_DIR}/pkg/elasticsearch.sh start
243 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000244 elif [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500245 iniset $CEILOMETER_CONF database alarm_connection mongodb://localhost:27017/ceilometer
246 iniset $CEILOMETER_CONF database event_connection mongodb://localhost:27017/ceilometer
247 iniset $CEILOMETER_CONF database metering_connection mongodb://localhost:27017/ceilometer
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800248 configure_mongodb
249 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000250 else
251 die $LINENO "Unable to configure unknown CEILOMETER_BACKEND $CEILOMETER_BACKEND"
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800252 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530253
254 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
255 iniset $CEILOMETER_CONF DEFAULT hypervisor_inspector vsphere
256 iniset $CEILOMETER_CONF vmware host_ip "$VMWAREAPI_IP"
257 iniset $CEILOMETER_CONF vmware host_username "$VMWAREAPI_USER"
258 iniset $CEILOMETER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
259 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100260
261 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
262 iniset $CEILOMETER_CONF api pecan_debug "False"
263 _config_ceilometer_apache_wsgi
264 fi
Lianhao Luc39f6402015-03-24 12:36:00 +0800265
266 if is_service_enabled ceilometer-aipmi; then
267 # Configure rootwrap for the ipmi agent
Ian Wienandc6782412015-05-14 10:01:53 +1000268 configure_rootwrap ceilometer
Lianhao Luc39f6402015-03-24 12:36:00 +0800269 fi
John H. Tran93361642012-07-26 11:22:05 -0700270}
271
Ian Wienandaee18c72014-02-21 15:35:08 +1100272function configure_mongodb {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500273 # Server package is the same on all
Ian Wienand936284b2014-03-11 09:35:55 +1100274 local packages=mongodb-server
275
Dean Troyercc6b4432013-04-08 15:38:03 -0500276 if is_fedora; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000277 # mongodb client
278 packages="${packages} mongodb"
Ian Wienand936284b2014-03-11 09:35:55 +1100279 fi
280
281 install_package ${packages}
282
283 if is_fedora; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500284 # Ensure smallfiles is selected to minimize freespace requirements
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500285 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
286
287 restart_service mongod
288 fi
Ian Wienand936284b2014-03-11 09:35:55 +1100289
Dean Troyerdc97cb72015-03-28 08:20:50 -0500290 # Give mongodb time to start-up
Ian Wienand936284b2014-03-11 09:35:55 +1100291 sleep 5
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500292}
293
Lianhao Lu8c548492013-01-09 10:41:54 +0800294# init_ceilometer() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100295function init_ceilometer {
Lianhao Lu8c548492013-01-09 10:41:54 +0800296 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500297 sudo install -d -o $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800298 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800299
Sean Daguec921a952014-02-28 21:09:33 -0500300 if is_service_enabled mysql postgresql; then
gordon chung76e724b2015-02-11 18:28:37 -0500301 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] || [ "$CEILOMETER_BACKEND" = 'es' ] ; then
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200302 recreate_database ceilometer
Sean Daguec921a952014-02-28 21:09:33 -0500303 $CEILOMETER_BIN_DIR/ceilometer-dbsync
304 fi
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800305 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800306}
307
Chris Dent21127432014-10-21 20:19:23 +0100308# install_redis() - Install the redis server.
309function install_redis {
310 if is_ubuntu; then
311 install_package redis-server
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400312 restart_service redis-server
Chris Dent21127432014-10-21 20:19:23 +0100313 else
314 # This will fail (correctly) where a redis package is unavailable
315 install_package redis
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400316 restart_service redis
Chris Dent21127432014-10-21 20:19:23 +0100317 fi
Chris Dent21127432014-10-21 20:19:23 +0100318}
319
John H. Tran93361642012-07-26 11:22:05 -0700320# install_ceilometer() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100321function install_ceilometer {
John H. Tran93361642012-07-26 11:22:05 -0700322 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
Joe Gordon13344bd2014-07-22 14:26:05 -0700323 setup_develop $CEILOMETER_DIR
324
Chris Dent8abd8592014-10-08 15:24:25 +0100325 if echo $CEILOMETER_COORDINATION_URL | grep -q '^memcached:'; then
326 install_package memcached
Chris Dent21127432014-10-21 20:19:23 +0100327 elif echo $CEILOMETER_COORDINATION_URL | grep -q '^redis:'; then
328 install_redis
Chris Dent8abd8592014-10-08 15:24:25 +0100329 fi
gordon chung76e724b2015-02-11 18:28:37 -0500330
Chris Dent027e2ea2015-06-05 18:43:50 +0000331 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
332 pip_install_gr pymongo
333 fi
334
Chris Dentccd4c2e2015-06-17 16:42:43 +0000335 # Only install virt drivers if we're running nova compute
336 if is_service_enabled n-cpu ; then
337 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
338 pip_install_gr libvirt-python
339 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000340
Chris Dentccd4c2e2015-06-17 16:42:43 +0000341 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent53a8f7c2015-06-27 15:07:20 +0100342 pip_install_gr oslo.vmware
Chris Dentccd4c2e2015-06-17 16:42:43 +0000343 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000344 fi
345
gordon chung76e724b2015-02-11 18:28:37 -0500346 if [ "$CEILOMETER_BACKEND" = 'es' ] ; then
347 ${TOP_DIR}/pkg/elasticsearch.sh download
348 ${TOP_DIR}/pkg/elasticsearch.sh install
349 fi
John H. Tran93361642012-07-26 11:22:05 -0700350}
351
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800352# install_ceilometerclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100353function install_ceilometerclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500354 if use_library_from_git "python-ceilometerclient"; then
355 git_clone_by_name "python-ceilometerclient"
356 setup_dev_lib "python-ceilometerclient"
357 sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-ceilometerclient"]}/tools/,/etc/bash_completion.d/}ceilometer.bash_completion
Sean Dague5cb19062014-11-01 01:37:45 +0100358 fi
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800359}
360
John H. Tran93361642012-07-26 11:22:05 -0700361# start_ceilometer() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100362function start_ceilometer {
Chris Dent23f65cb2015-09-09 08:33:15 +0000363 run_process ceilometer-acentral "$CEILOMETER_BIN_DIR/ceilometer-polling --polling-namespaces central --config-file $CEILOMETER_CONF"
Chris Dent027e2ea2015-06-05 18:43:50 +0000364 run_process ceilometer-anotification "$CEILOMETER_BIN_DIR/ceilometer-agent-notification --config-file $CEILOMETER_CONF"
365 run_process ceilometer-collector "$CEILOMETER_BIN_DIR/ceilometer-collector --config-file $CEILOMETER_CONF"
Chris Dent23f65cb2015-09-09 08:33:15 +0000366 run_process ceilometer-aipmi "$CEILOMETER_BIN_DIR/ceilometer-polling --polling-namespaces ipmi --config-file $CEILOMETER_CONF"
Chris Dentae6fb182014-09-16 15:17:13 +0100367
368 if [[ "$CEILOMETER_USE_MOD_WSGI" == "False" ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000369 run_process ceilometer-api "$CEILOMETER_BIN_DIR/ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR --config-file $CEILOMETER_CONF"
Chris Dentae6fb182014-09-16 15:17:13 +0100370 else
371 enable_apache_site ceilometer
372 restart_apache_server
373 tail_log ceilometer /var/log/$APACHE_NAME/ceilometer.log
374 tail_log ceilometer-api /var/log/$APACHE_NAME/ceilometer_access.log
375 fi
376
Chris Dent4922bfa2014-08-12 14:27:58 +0100377
378 # Start the compute agent last to allow time for the collector to
379 # fully wake up and connect to the message bus. See bug #1355809
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000380 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Chris Dent23f65cb2015-09-09 08:33:15 +0000381 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-polling --polling-namespaces compute --config-file $CEILOMETER_CONF" $LIBVIRT_GROUP
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000382 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530383 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent23f65cb2015-09-09 08:33:15 +0000384 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-polling --polling-namespaces compute --config-file $CEILOMETER_CONF"
Piyush Masrani846609b2014-03-14 19:21:48 +0530385 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200386
Dean Troyerdc97cb72015-03-28 08:20:50 -0500387 # Only die on API if it was actually intended to be turned on
Sean Dagueb9a70352014-03-04 15:02:04 -0500388 if is_service_enabled ceilometer-api; then
Sean Dague7083b822014-02-28 20:16:20 -0500389 echo "Waiting for ceilometer-api to start..."
sridhargaddamb5ab6462015-02-24 07:23:24 +0000390 if ! wait_for_service $SERVICE_TIMEOUT $CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/v2/; then
Sean Dague7083b822014-02-28 20:16:20 -0500391 die $LINENO "ceilometer-api did not start"
392 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200393 fi
394
Chris Dent027e2ea2015-06-05 18:43:50 +0000395 run_process ceilometer-alarm-notifier "$CEILOMETER_BIN_DIR/ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
396 run_process ceilometer-alarm-evaluator "$CEILOMETER_BIN_DIR/ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700397}
Dean Troyer7903b792012-09-13 17:16:12 -0500398
Dean Troyer699a29f2012-09-10 14:10:27 -0500399# stop_ceilometer() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100400function stop_ceilometer {
Chris Dentae6fb182014-09-16 15:17:13 +0100401 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
402 disable_apache_site ceilometer
403 restart_apache_server
404 fi
Dean Troyer699a29f2012-09-10 14:10:27 -0500405 # Kill the ceilometer screen windows
Lianhao Luc39f6402015-03-24 12:36:00 +0800406 for serv in ceilometer-acompute ceilometer-acentral ceilometer-aipmi ceilometer-anotification ceilometer-collector ceilometer-api ceilometer-alarm-notifier ceilometer-alarm-evaluator; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100407 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500408 done
409}
410
Dean Troyercc6b4432013-04-08 15:38:03 -0500411
Dean Troyer7903b792012-09-13 17:16:12 -0500412# Restore xtrace
413$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400414
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100415# Tell emacs to use shell-script-mode
416## Local variables:
417## mode: shell-script
418## End: