blob: ed9b93377e278aec0fa387f8bd3e6bc6f11eae5b [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
Dean Troyer4237f592014-01-29 16:22:11 -0600105# Tell Tempest this project is present
106TEMPEST_SERVICES+=,ceilometer
107
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100108
Dean Troyercc6b4432013-04-08 15:38:03 -0500109# Functions
110# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -0600111
112# Test if any Ceilometer services are enabled
113# is_ceilometer_enabled
114function is_ceilometer_enabled {
115 [[ ,${ENABLED_SERVICES} =~ ,"ceilometer-" ]] && return 0
116 return 1
117}
118
Dean Troyerdc97cb72015-03-28 08:20:50 -0500119# create_ceilometer_accounts() - Set up common required Ceilometer accounts
Chris Dent67bc8e82014-10-08 12:07:46 +0100120#
Dean Troyer42a59c22014-03-03 14:31:29 -0600121# Project User Roles
122# ------------------------------------------------------------------
123# SERVICE_TENANT_NAME ceilometer admin
124# SERVICE_TENANT_NAME ceilometer ResellerAdmin (if Swift is enabled)
Chris Dent67bc8e82014-10-08 12:07:46 +0100125function create_ceilometer_accounts {
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100126
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100127 # Ceilometer
128 if [[ "$ENABLED_SERVICES" =~ "ceilometer-api" ]]; then
Jamie Lennox85ff5322015-01-28 14:28:01 +1000129
Chris Dent230e03a2015-02-16 22:07:00 +0000130 create_service_user "ceilometer" "admin"
Bartosz Górski0abde392014-02-28 14:15:19 +0100131
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100132 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Dean Troyer16ef9762014-08-19 19:31:34 -0500133 local ceilometer_service=$(get_or_create_service "ceilometer" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100134 "metering" "OpenStack Telemetry Service")
Dean Troyer16ef9762014-08-19 19:31:34 -0500135 get_or_create_endpoint $ceilometer_service \
Bartosz Górski0abde392014-02-28 14:15:19 +0100136 "$REGION_NAME" \
137 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
138 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
139 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100140 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600141 if is_service_enabled swift; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500142 # Ceilometer needs ResellerAdmin role to access Swift account stats.
Jamie Lennox9b215db2015-02-10 18:19:57 +1100143 get_or_add_user_project_role "ResellerAdmin" "ceilometer" $SERVICE_TENANT_NAME
Dean Troyer42a59c22014-03-03 14:31:29 -0600144 fi
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100145 fi
146}
147
Dean Troyercc6b4432013-04-08 15:38:03 -0500148
Dean Troyerdc97cb72015-03-28 08:20:50 -0500149# _cleanup_keystone_apache_wsgi() - Remove WSGI files, disable and remove Apache vhost file
Chris Dentae6fb182014-09-16 15:17:13 +0100150function _cleanup_ceilometer_apache_wsgi {
151 sudo rm -f $CEILOMETER_WSGI_DIR/*
152 sudo rm -f $(apache_site_config_for ceilometer)
153}
154
John H. Tran93361642012-07-26 11:22:05 -0700155# cleanup_ceilometer() - Remove residual data files, anything left over from previous
156# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100157function cleanup_ceilometer {
gordon chung76e724b2015-02-11 18:28:37 -0500158 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
Ian Wienand936284b2014-03-11 09:35:55 +1100159 mongo ceilometer --eval "db.dropDatabase();"
gordon chung76e724b2015-02-11 18:28:37 -0500160 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
161 curl -XDELETE "localhost:9200/events_*"
Ian Wienand936284b2014-03-11 09:35:55 +1100162 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100163 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
164 _cleanup_ceilometer_apache_wsgi
165 fi
166}
167
168function _config_ceilometer_apache_wsgi {
169 sudo mkdir -p $CEILOMETER_WSGI_DIR
170
171 local ceilometer_apache_conf=$(apache_site_config_for ceilometer)
172 local apache_version=$(get_apache_version)
Chris Dent027e2ea2015-06-05 18:43:50 +0000173 local venv_path=""
Chris Dentae6fb182014-09-16 15:17:13 +0100174
Dean Troyerdc97cb72015-03-28 08:20:50 -0500175 # Copy proxy vhost and wsgi file
Chris Dentae6fb182014-09-16 15:17:13 +0100176 sudo cp $CEILOMETER_DIR/ceilometer/api/app.wsgi $CEILOMETER_WSGI_DIR/app
177
Chris Dent027e2ea2015-06-05 18:43:50 +0000178 if [[ ${USE_VENV} = True ]]; then
179 venv_path="python-path=${PROJECT_VENV["ceilometer"]}/lib/$(python_version)/site-packages"
180 fi
181
Chris Dentae6fb182014-09-16 15:17:13 +0100182 sudo cp $FILES/apache-ceilometer.template $ceilometer_apache_conf
183 sudo sed -e "
184 s|%PORT%|$CEILOMETER_SERVICE_PORT|g;
185 s|%APACHE_NAME%|$APACHE_NAME|g;
186 s|%WSGIAPP%|$CEILOMETER_WSGI_DIR/app|g;
Chris Dent027e2ea2015-06-05 18:43:50 +0000187 s|%USER%|$STACK_USER|g;
188 s|%VIRTUALENV%|$venv_path|g
Chris Dentae6fb182014-09-16 15:17:13 +0100189 " -i $ceilometer_apache_conf
John H. Tran93361642012-07-26 11:22:05 -0700190}
191
192# configure_ceilometer() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100193function configure_ceilometer {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500194 sudo install -d -o $STACK_USER -m 755 $CEILOMETER_CONF_DIR $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -0700195
Brant Knudson2dd110c2015-03-14 12:39:14 -0500196 iniset_rpc_backend ceilometer $CEILOMETER_CONF
Eoghan Glynnd36268a2013-02-22 21:59:52 +0000197
Boris Pavlovic46e1aba2014-07-01 14:15:52 +0400198 iniset $CEILOMETER_CONF DEFAULT notification_topics "$CEILOMETER_NOTIFICATION_TOPICS"
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200199 iniset $CEILOMETER_CONF DEFAULT verbose True
Nadya Privalova423d7902014-03-06 15:14:59 +0400200 iniset $CEILOMETER_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Doug Hellmann53a5f422012-10-02 17:29:23 -0400201
Chris Dent8abd8592014-10-08 15:24:25 +0100202 if [[ -n "$CEILOMETER_COORDINATION_URL" ]]; then
203 iniset $CEILOMETER_CONF coordination backend_url $CEILOMETER_COORDINATION_URL
204 iniset $CEILOMETER_CONF compute workload_partitioning True
205 fi
206
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400207 # Install the policy file for the API server
208 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
Chris Dent74a85b02015-04-22 18:02:39 +0000209 iniset $CEILOMETER_CONF oslo_policy policy_file $CEILOMETER_CONF_DIR/policy.json
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400210
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800211 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
gordon chung99f5bcc2015-02-03 09:23:39 -0500212 cp $CEILOMETER_DIR/etc/ceilometer/event_pipeline.yaml $CEILOMETER_CONF_DIR
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800213 cp $CEILOMETER_DIR/etc/ceilometer/api_paste.ini $CEILOMETER_CONF_DIR
214 cp $CEILOMETER_DIR/etc/ceilometer/event_definitions.yaml $CEILOMETER_CONF_DIR
215
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +0200216 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
217 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
218 fi
219
Dean Troyerdc97cb72015-03-28 08:20:50 -0500220 # The compute and central agents need these credentials in order to
221 # call out to other services' public APIs.
222 # The alarm evaluator needs these options to call ceilometer APIs
ZhiQiang Fan1af4afb2014-04-16 14:52:12 +0800223 iniset $CEILOMETER_CONF service_credentials os_username ceilometer
224 iniset $CEILOMETER_CONF service_credentials os_password $SERVICE_PASSWORD
225 iniset $CEILOMETER_CONF service_credentials os_tenant_name $SERVICE_TENANT_NAME
Ethan Lynna134f652015-01-12 12:59:30 +0800226 iniset $CEILOMETER_CONF service_credentials os_region_name $REGION_NAME
227 iniset $CEILOMETER_CONF service_credentials os_auth_url $KEYSTONE_SERVICE_URI/v2.0
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000228
Brant Knudson05952372014-09-19 17:22:22 -0500229 configure_auth_token_middleware $CEILOMETER_CONF ceilometer $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400230
gordon chung76e724b2015-02-11 18:28:37 -0500231 iniset $CEILOMETER_CONF notification store_events $CEILOMETER_EVENTS
232
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000233 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500234 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
235 iniset $CEILOMETER_CONF database event_connection $(database_connection_url ceilometer)
236 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
Dean Troyer05bd7b82014-09-16 17:25:33 -0500237 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
gordon chung76e724b2015-02-11 18:28:37 -0500238 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
239 # es is only supported for events. we will use sql for alarming/metering.
240 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
241 iniset $CEILOMETER_CONF database event_connection es://localhost:9200
242 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
243 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
244 ${TOP_DIR}/pkg/elasticsearch.sh start
245 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000246 elif [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500247 iniset $CEILOMETER_CONF database alarm_connection mongodb://localhost:27017/ceilometer
248 iniset $CEILOMETER_CONF database event_connection mongodb://localhost:27017/ceilometer
249 iniset $CEILOMETER_CONF database metering_connection mongodb://localhost:27017/ceilometer
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800250 configure_mongodb
251 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000252 else
253 die $LINENO "Unable to configure unknown CEILOMETER_BACKEND $CEILOMETER_BACKEND"
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800254 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530255
256 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
257 iniset $CEILOMETER_CONF DEFAULT hypervisor_inspector vsphere
258 iniset $CEILOMETER_CONF vmware host_ip "$VMWAREAPI_IP"
259 iniset $CEILOMETER_CONF vmware host_username "$VMWAREAPI_USER"
260 iniset $CEILOMETER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
261 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100262
263 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
264 iniset $CEILOMETER_CONF api pecan_debug "False"
265 _config_ceilometer_apache_wsgi
266 fi
Lianhao Luc39f6402015-03-24 12:36:00 +0800267
268 if is_service_enabled ceilometer-aipmi; then
269 # Configure rootwrap for the ipmi agent
Ian Wienandc6782412015-05-14 10:01:53 +1000270 configure_rootwrap ceilometer
Lianhao Luc39f6402015-03-24 12:36:00 +0800271 fi
John H. Tran93361642012-07-26 11:22:05 -0700272}
273
Ian Wienandaee18c72014-02-21 15:35:08 +1100274function configure_mongodb {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500275 # Server package is the same on all
Ian Wienand936284b2014-03-11 09:35:55 +1100276 local packages=mongodb-server
277
Dean Troyercc6b4432013-04-08 15:38:03 -0500278 if is_fedora; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000279 # mongodb client
280 packages="${packages} mongodb"
Ian Wienand936284b2014-03-11 09:35:55 +1100281 fi
282
283 install_package ${packages}
284
285 if is_fedora; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500286 # Ensure smallfiles is selected to minimize freespace requirements
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500287 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
288
289 restart_service mongod
290 fi
Ian Wienand936284b2014-03-11 09:35:55 +1100291
Dean Troyerdc97cb72015-03-28 08:20:50 -0500292 # Give mongodb time to start-up
Ian Wienand936284b2014-03-11 09:35:55 +1100293 sleep 5
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500294}
295
Lianhao Lu8c548492013-01-09 10:41:54 +0800296# init_ceilometer() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100297function init_ceilometer {
Lianhao Lu8c548492013-01-09 10:41:54 +0800298 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500299 sudo install -d -o $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800300 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800301
Sean Daguec921a952014-02-28 21:09:33 -0500302 if is_service_enabled mysql postgresql; then
gordon chung76e724b2015-02-11 18:28:37 -0500303 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] || [ "$CEILOMETER_BACKEND" = 'es' ] ; then
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200304 recreate_database ceilometer
Sean Daguec921a952014-02-28 21:09:33 -0500305 $CEILOMETER_BIN_DIR/ceilometer-dbsync
306 fi
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800307 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800308}
309
Chris Dent21127432014-10-21 20:19:23 +0100310# install_redis() - Install the redis server.
311function install_redis {
312 if is_ubuntu; then
313 install_package redis-server
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400314 restart_service redis-server
Chris Dent21127432014-10-21 20:19:23 +0100315 else
316 # This will fail (correctly) where a redis package is unavailable
317 install_package redis
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400318 restart_service redis
Chris Dent21127432014-10-21 20:19:23 +0100319 fi
Chris Dent21127432014-10-21 20:19:23 +0100320}
321
John H. Tran93361642012-07-26 11:22:05 -0700322# install_ceilometer() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100323function install_ceilometer {
John H. Tran93361642012-07-26 11:22:05 -0700324 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
Joe Gordon13344bd2014-07-22 14:26:05 -0700325 setup_develop $CEILOMETER_DIR
326
Chris Dent8abd8592014-10-08 15:24:25 +0100327 if echo $CEILOMETER_COORDINATION_URL | grep -q '^memcached:'; then
328 install_package memcached
Chris Dent21127432014-10-21 20:19:23 +0100329 elif echo $CEILOMETER_COORDINATION_URL | grep -q '^redis:'; then
330 install_redis
Chris Dent8abd8592014-10-08 15:24:25 +0100331 fi
gordon chung76e724b2015-02-11 18:28:37 -0500332
Chris Dent027e2ea2015-06-05 18:43:50 +0000333 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
334 pip_install_gr pymongo
335 fi
336
Chris Dentccd4c2e2015-06-17 16:42:43 +0000337 # Only install virt drivers if we're running nova compute
338 if is_service_enabled n-cpu ; then
339 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
340 pip_install_gr libvirt-python
341 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000342
Chris Dentccd4c2e2015-06-17 16:42:43 +0000343 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent53a8f7c2015-06-27 15:07:20 +0100344 pip_install_gr oslo.vmware
Chris Dentccd4c2e2015-06-17 16:42:43 +0000345 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000346 fi
347
gordon chung76e724b2015-02-11 18:28:37 -0500348 if [ "$CEILOMETER_BACKEND" = 'es' ] ; then
349 ${TOP_DIR}/pkg/elasticsearch.sh download
350 ${TOP_DIR}/pkg/elasticsearch.sh install
351 fi
John H. Tran93361642012-07-26 11:22:05 -0700352}
353
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800354# install_ceilometerclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100355function install_ceilometerclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500356 if use_library_from_git "python-ceilometerclient"; then
357 git_clone_by_name "python-ceilometerclient"
358 setup_dev_lib "python-ceilometerclient"
359 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 +0100360 fi
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800361}
362
gordon chungad61e7f2015-02-12 15:17:25 -0500363# install_ceilometermiddleware() - Collect source and prepare
364function install_ceilometermiddleware {
365 if use_library_from_git "ceilometermiddleware"; then
366 git_clone_by_name "ceilometermiddleware"
367 setup_dev_lib "ceilometermiddleware"
gordon chungb6197e62015-02-12 15:33:35 -0500368 else
Jerry Zhaod3d78cc2015-06-19 18:57:13 -0700369 pip_install_gr ceilometermiddleware
gordon chungad61e7f2015-02-12 15:17:25 -0500370 fi
371}
372
John H. Tran93361642012-07-26 11:22:05 -0700373# start_ceilometer() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100374function start_ceilometer {
Chris Dent027e2ea2015-06-05 18:43:50 +0000375 run_process ceilometer-acentral "$CEILOMETER_BIN_DIR/ceilometer-agent-central --config-file $CEILOMETER_CONF"
376 run_process ceilometer-anotification "$CEILOMETER_BIN_DIR/ceilometer-agent-notification --config-file $CEILOMETER_CONF"
377 run_process ceilometer-collector "$CEILOMETER_BIN_DIR/ceilometer-collector --config-file $CEILOMETER_CONF"
378 run_process ceilometer-aipmi "$CEILOMETER_BIN_DIR/ceilometer-agent-ipmi --config-file $CEILOMETER_CONF"
Chris Dentae6fb182014-09-16 15:17:13 +0100379
380 if [[ "$CEILOMETER_USE_MOD_WSGI" == "False" ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000381 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 +0100382 else
383 enable_apache_site ceilometer
384 restart_apache_server
385 tail_log ceilometer /var/log/$APACHE_NAME/ceilometer.log
386 tail_log ceilometer-api /var/log/$APACHE_NAME/ceilometer_access.log
387 fi
388
Chris Dent4922bfa2014-08-12 14:27:58 +0100389
390 # Start the compute agent last to allow time for the collector to
391 # fully wake up and connect to the message bus. See bug #1355809
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000392 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000393 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-agent-compute --config-file $CEILOMETER_CONF" $LIBVIRT_GROUP
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000394 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530395 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000396 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-agent-compute --config-file $CEILOMETER_CONF"
Piyush Masrani846609b2014-03-14 19:21:48 +0530397 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200398
Dean Troyerdc97cb72015-03-28 08:20:50 -0500399 # Only die on API if it was actually intended to be turned on
Sean Dagueb9a70352014-03-04 15:02:04 -0500400 if is_service_enabled ceilometer-api; then
Sean Dague7083b822014-02-28 20:16:20 -0500401 echo "Waiting for ceilometer-api to start..."
sridhargaddamb5ab6462015-02-24 07:23:24 +0000402 if ! wait_for_service $SERVICE_TIMEOUT $CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/v2/; then
Sean Dague7083b822014-02-28 20:16:20 -0500403 die $LINENO "ceilometer-api did not start"
404 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200405 fi
406
Chris Dent027e2ea2015-06-05 18:43:50 +0000407 run_process ceilometer-alarm-notifier "$CEILOMETER_BIN_DIR/ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
408 run_process ceilometer-alarm-evaluator "$CEILOMETER_BIN_DIR/ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700409}
Dean Troyer7903b792012-09-13 17:16:12 -0500410
Dean Troyer699a29f2012-09-10 14:10:27 -0500411# stop_ceilometer() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100412function stop_ceilometer {
Chris Dentae6fb182014-09-16 15:17:13 +0100413 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
414 disable_apache_site ceilometer
415 restart_apache_server
416 fi
Dean Troyer699a29f2012-09-10 14:10:27 -0500417 # Kill the ceilometer screen windows
Lianhao Luc39f6402015-03-24 12:36:00 +0800418 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 +0100419 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500420 done
421}
422
Dean Troyercc6b4432013-04-08 15:38:03 -0500423
Dean Troyer7903b792012-09-13 17:16:12 -0500424# Restore xtrace
425$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400426
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100427# Tell emacs to use shell-script-mode
428## Local variables:
429## mode: shell-script
430## End: