blob: ce93ebdc4fb588bd3c988437a5cc8e69a1aa6180 [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
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000133 get_or_create_service "ceilometer" "metering" "OpenStack Telemetry Service"
134 get_or_create_endpoint "metering" \
Bartosz Górski0abde392014-02-28 14:15:19 +0100135 "$REGION_NAME" \
136 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
137 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
138 "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100139 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600140 if is_service_enabled swift; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500141 # Ceilometer needs ResellerAdmin role to access Swift account stats.
Jamie Lennox9b215db2015-02-10 18:19:57 +1100142 get_or_add_user_project_role "ResellerAdmin" "ceilometer" $SERVICE_TENANT_NAME
Dean Troyer42a59c22014-03-03 14:31:29 -0600143 fi
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100144 fi
145}
146
Dean Troyercc6b4432013-04-08 15:38:03 -0500147
Dean Troyerdc97cb72015-03-28 08:20:50 -0500148# _cleanup_keystone_apache_wsgi() - Remove WSGI files, disable and remove Apache vhost file
Chris Dentae6fb182014-09-16 15:17:13 +0100149function _cleanup_ceilometer_apache_wsgi {
150 sudo rm -f $CEILOMETER_WSGI_DIR/*
151 sudo rm -f $(apache_site_config_for ceilometer)
152}
153
John H. Tran93361642012-07-26 11:22:05 -0700154# cleanup_ceilometer() - Remove residual data files, anything left over from previous
155# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100156function cleanup_ceilometer {
gordon chung76e724b2015-02-11 18:28:37 -0500157 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
Ian Wienand936284b2014-03-11 09:35:55 +1100158 mongo ceilometer --eval "db.dropDatabase();"
gordon chung76e724b2015-02-11 18:28:37 -0500159 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
160 curl -XDELETE "localhost:9200/events_*"
Ian Wienand936284b2014-03-11 09:35:55 +1100161 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100162 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
163 _cleanup_ceilometer_apache_wsgi
164 fi
165}
166
167function _config_ceilometer_apache_wsgi {
168 sudo mkdir -p $CEILOMETER_WSGI_DIR
169
170 local ceilometer_apache_conf=$(apache_site_config_for ceilometer)
171 local apache_version=$(get_apache_version)
Chris Dent027e2ea2015-06-05 18:43:50 +0000172 local venv_path=""
Chris Dentae6fb182014-09-16 15:17:13 +0100173
Dean Troyerdc97cb72015-03-28 08:20:50 -0500174 # Copy proxy vhost and wsgi file
Chris Dentae6fb182014-09-16 15:17:13 +0100175 sudo cp $CEILOMETER_DIR/ceilometer/api/app.wsgi $CEILOMETER_WSGI_DIR/app
176
Chris Dent027e2ea2015-06-05 18:43:50 +0000177 if [[ ${USE_VENV} = True ]]; then
178 venv_path="python-path=${PROJECT_VENV["ceilometer"]}/lib/$(python_version)/site-packages"
179 fi
180
Chris Dentae6fb182014-09-16 15:17:13 +0100181 sudo cp $FILES/apache-ceilometer.template $ceilometer_apache_conf
182 sudo sed -e "
183 s|%PORT%|$CEILOMETER_SERVICE_PORT|g;
184 s|%APACHE_NAME%|$APACHE_NAME|g;
185 s|%WSGIAPP%|$CEILOMETER_WSGI_DIR/app|g;
Chris Dent027e2ea2015-06-05 18:43:50 +0000186 s|%USER%|$STACK_USER|g;
187 s|%VIRTUALENV%|$venv_path|g
Chris Dentae6fb182014-09-16 15:17:13 +0100188 " -i $ceilometer_apache_conf
John H. Tran93361642012-07-26 11:22:05 -0700189}
190
191# configure_ceilometer() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100192function configure_ceilometer {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500193 sudo install -d -o $STACK_USER -m 755 $CEILOMETER_CONF_DIR $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -0700194
Brant Knudson2dd110c2015-03-14 12:39:14 -0500195 iniset_rpc_backend ceilometer $CEILOMETER_CONF
Eoghan Glynnd36268a2013-02-22 21:59:52 +0000196
Boris Pavlovic46e1aba2014-07-01 14:15:52 +0400197 iniset $CEILOMETER_CONF DEFAULT notification_topics "$CEILOMETER_NOTIFICATION_TOPICS"
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200198 iniset $CEILOMETER_CONF DEFAULT verbose True
Nadya Privalova423d7902014-03-06 15:14:59 +0400199 iniset $CEILOMETER_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Doug Hellmann53a5f422012-10-02 17:29:23 -0400200
Chris Dent8abd8592014-10-08 15:24:25 +0100201 if [[ -n "$CEILOMETER_COORDINATION_URL" ]]; then
202 iniset $CEILOMETER_CONF coordination backend_url $CEILOMETER_COORDINATION_URL
203 iniset $CEILOMETER_CONF compute workload_partitioning True
204 fi
205
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400206 # Install the policy file for the API server
207 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
Chris Dent74a85b02015-04-22 18:02:39 +0000208 iniset $CEILOMETER_CONF oslo_policy policy_file $CEILOMETER_CONF_DIR/policy.json
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400209
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800210 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
gordon chung99f5bcc2015-02-03 09:23:39 -0500211 cp $CEILOMETER_DIR/etc/ceilometer/event_pipeline.yaml $CEILOMETER_CONF_DIR
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800212 cp $CEILOMETER_DIR/etc/ceilometer/api_paste.ini $CEILOMETER_CONF_DIR
213 cp $CEILOMETER_DIR/etc/ceilometer/event_definitions.yaml $CEILOMETER_CONF_DIR
Pradeep Kilambi37566872015-07-20 16:16:31 -0400214 cp $CEILOMETER_DIR/etc/ceilometer/meters.yaml $CEILOMETER_CONF_DIR
Mehdi Abaakoukeef5d852015-07-24 10:55:42 +0200215 cp $CEILOMETER_DIR/etc/ceilometer/gnocchi_archive_policy_map.yaml $CEILOMETER_CONF_DIR
216 cp $CEILOMETER_DIR/etc/ceilometer/gnocchi_resources.yaml $CEILOMETER_CONF_DIR
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800217
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +0200218 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
219 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
220 fi
221
Dean Troyerdc97cb72015-03-28 08:20:50 -0500222 # The compute and central agents need these credentials in order to
223 # call out to other services' public APIs.
224 # The alarm evaluator needs these options to call ceilometer APIs
ZhiQiang Fan1af4afb2014-04-16 14:52:12 +0800225 iniset $CEILOMETER_CONF service_credentials os_username ceilometer
226 iniset $CEILOMETER_CONF service_credentials os_password $SERVICE_PASSWORD
227 iniset $CEILOMETER_CONF service_credentials os_tenant_name $SERVICE_TENANT_NAME
Ethan Lynna134f652015-01-12 12:59:30 +0800228 iniset $CEILOMETER_CONF service_credentials os_region_name $REGION_NAME
229 iniset $CEILOMETER_CONF service_credentials os_auth_url $KEYSTONE_SERVICE_URI/v2.0
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000230
Brant Knudson05952372014-09-19 17:22:22 -0500231 configure_auth_token_middleware $CEILOMETER_CONF ceilometer $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400232
gordon chung76e724b2015-02-11 18:28:37 -0500233 iniset $CEILOMETER_CONF notification store_events $CEILOMETER_EVENTS
234
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000235 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500236 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
237 iniset $CEILOMETER_CONF database event_connection $(database_connection_url ceilometer)
238 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
Dean Troyer05bd7b82014-09-16 17:25:33 -0500239 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
gordon chung76e724b2015-02-11 18:28:37 -0500240 elif [ "$CEILOMETER_BACKEND" = 'es' ] ; then
241 # es is only supported for events. we will use sql for alarming/metering.
242 iniset $CEILOMETER_CONF database alarm_connection $(database_connection_url ceilometer)
243 iniset $CEILOMETER_CONF database event_connection es://localhost:9200
244 iniset $CEILOMETER_CONF database metering_connection $(database_connection_url ceilometer)
245 iniset $CEILOMETER_CONF DEFAULT collector_workers $API_WORKERS
246 ${TOP_DIR}/pkg/elasticsearch.sh start
247 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000248 elif [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
gordon chung48bbfe92014-11-19 15:54:17 -0500249 iniset $CEILOMETER_CONF database alarm_connection mongodb://localhost:27017/ceilometer
250 iniset $CEILOMETER_CONF database event_connection mongodb://localhost:27017/ceilometer
251 iniset $CEILOMETER_CONF database metering_connection mongodb://localhost:27017/ceilometer
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800252 configure_mongodb
253 cleanup_ceilometer
Chris Dent027e2ea2015-06-05 18:43:50 +0000254 else
255 die $LINENO "Unable to configure unknown CEILOMETER_BACKEND $CEILOMETER_BACKEND"
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800256 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530257
258 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
259 iniset $CEILOMETER_CONF DEFAULT hypervisor_inspector vsphere
260 iniset $CEILOMETER_CONF vmware host_ip "$VMWAREAPI_IP"
261 iniset $CEILOMETER_CONF vmware host_username "$VMWAREAPI_USER"
262 iniset $CEILOMETER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
263 fi
Chris Dentae6fb182014-09-16 15:17:13 +0100264
265 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
266 iniset $CEILOMETER_CONF api pecan_debug "False"
267 _config_ceilometer_apache_wsgi
268 fi
Lianhao Luc39f6402015-03-24 12:36:00 +0800269
270 if is_service_enabled ceilometer-aipmi; then
271 # Configure rootwrap for the ipmi agent
Ian Wienandc6782412015-05-14 10:01:53 +1000272 configure_rootwrap ceilometer
Lianhao Luc39f6402015-03-24 12:36:00 +0800273 fi
John H. Tran93361642012-07-26 11:22:05 -0700274}
275
Ian Wienandaee18c72014-02-21 15:35:08 +1100276function configure_mongodb {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500277 # Server package is the same on all
Ian Wienand936284b2014-03-11 09:35:55 +1100278 local packages=mongodb-server
279
Dean Troyercc6b4432013-04-08 15:38:03 -0500280 if is_fedora; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000281 # mongodb client
282 packages="${packages} mongodb"
Ian Wienand936284b2014-03-11 09:35:55 +1100283 fi
284
285 install_package ${packages}
286
287 if is_fedora; then
Dean Troyerdc97cb72015-03-28 08:20:50 -0500288 # Ensure smallfiles is selected to minimize freespace requirements
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500289 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
290
291 restart_service mongod
292 fi
Ian Wienand936284b2014-03-11 09:35:55 +1100293
Dean Troyerdc97cb72015-03-28 08:20:50 -0500294 # Give mongodb time to start-up
Ian Wienand936284b2014-03-11 09:35:55 +1100295 sleep 5
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500296}
297
Lianhao Lu8c548492013-01-09 10:41:54 +0800298# init_ceilometer() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100299function init_ceilometer {
Lianhao Lu8c548492013-01-09 10:41:54 +0800300 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500301 sudo install -d -o $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800302 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800303
Sean Daguec921a952014-02-28 21:09:33 -0500304 if is_service_enabled mysql postgresql; then
gordon chung76e724b2015-02-11 18:28:37 -0500305 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] || [ "$CEILOMETER_BACKEND" = 'es' ] ; then
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200306 recreate_database ceilometer
Sean Daguec921a952014-02-28 21:09:33 -0500307 $CEILOMETER_BIN_DIR/ceilometer-dbsync
308 fi
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800309 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800310}
311
Chris Dent21127432014-10-21 20:19:23 +0100312# install_redis() - Install the redis server.
313function install_redis {
314 if is_ubuntu; then
315 install_package redis-server
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400316 restart_service redis-server
Chris Dent21127432014-10-21 20:19:23 +0100317 else
318 # This will fail (correctly) where a redis package is unavailable
319 install_package redis
Ilya Tyaptinfe5164a2014-12-23 14:53:43 +0400320 restart_service redis
Chris Dent21127432014-10-21 20:19:23 +0100321 fi
Chris Dent21127432014-10-21 20:19:23 +0100322}
323
John H. Tran93361642012-07-26 11:22:05 -0700324# install_ceilometer() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100325function install_ceilometer {
John H. Tran93361642012-07-26 11:22:05 -0700326 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
Joe Gordon13344bd2014-07-22 14:26:05 -0700327 setup_develop $CEILOMETER_DIR
328
Chris Dent8abd8592014-10-08 15:24:25 +0100329 if echo $CEILOMETER_COORDINATION_URL | grep -q '^memcached:'; then
330 install_package memcached
Chris Dent21127432014-10-21 20:19:23 +0100331 elif echo $CEILOMETER_COORDINATION_URL | grep -q '^redis:'; then
332 install_redis
Chris Dent8abd8592014-10-08 15:24:25 +0100333 fi
gordon chung76e724b2015-02-11 18:28:37 -0500334
Chris Dent027e2ea2015-06-05 18:43:50 +0000335 if [ "$CEILOMETER_BACKEND" = 'mongodb' ] ; then
336 pip_install_gr pymongo
337 fi
338
Chris Dentccd4c2e2015-06-17 16:42:43 +0000339 # Only install virt drivers if we're running nova compute
340 if is_service_enabled n-cpu ; then
341 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
342 pip_install_gr libvirt-python
343 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000344
Chris Dentccd4c2e2015-06-17 16:42:43 +0000345 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent53a8f7c2015-06-27 15:07:20 +0100346 pip_install_gr oslo.vmware
Chris Dentccd4c2e2015-06-17 16:42:43 +0000347 fi
Chris Dent027e2ea2015-06-05 18:43:50 +0000348 fi
349
gordon chung76e724b2015-02-11 18:28:37 -0500350 if [ "$CEILOMETER_BACKEND" = 'es' ] ; then
351 ${TOP_DIR}/pkg/elasticsearch.sh download
352 ${TOP_DIR}/pkg/elasticsearch.sh install
353 fi
John H. Tran93361642012-07-26 11:22:05 -0700354}
355
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800356# install_ceilometerclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100357function install_ceilometerclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500358 if use_library_from_git "python-ceilometerclient"; then
359 git_clone_by_name "python-ceilometerclient"
360 setup_dev_lib "python-ceilometerclient"
361 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 +0100362 fi
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800363}
364
John H. Tran93361642012-07-26 11:22:05 -0700365# start_ceilometer() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100366function start_ceilometer {
Chris Dent027e2ea2015-06-05 18:43:50 +0000367 run_process ceilometer-acentral "$CEILOMETER_BIN_DIR/ceilometer-agent-central --config-file $CEILOMETER_CONF"
368 run_process ceilometer-anotification "$CEILOMETER_BIN_DIR/ceilometer-agent-notification --config-file $CEILOMETER_CONF"
369 run_process ceilometer-collector "$CEILOMETER_BIN_DIR/ceilometer-collector --config-file $CEILOMETER_CONF"
370 run_process ceilometer-aipmi "$CEILOMETER_BIN_DIR/ceilometer-agent-ipmi --config-file $CEILOMETER_CONF"
Chris Dentae6fb182014-09-16 15:17:13 +0100371
372 if [[ "$CEILOMETER_USE_MOD_WSGI" == "False" ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000373 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 +0100374 else
375 enable_apache_site ceilometer
376 restart_apache_server
377 tail_log ceilometer /var/log/$APACHE_NAME/ceilometer.log
378 tail_log ceilometer-api /var/log/$APACHE_NAME/ceilometer_access.log
379 fi
380
Chris Dent4922bfa2014-08-12 14:27:58 +0100381
382 # Start the compute agent last to allow time for the collector to
383 # fully wake up and connect to the message bus. See bug #1355809
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000384 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000385 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-agent-compute --config-file $CEILOMETER_CONF" $LIBVIRT_GROUP
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000386 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530387 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
Chris Dent027e2ea2015-06-05 18:43:50 +0000388 run_process ceilometer-acompute "$CEILOMETER_BIN_DIR/ceilometer-agent-compute --config-file $CEILOMETER_CONF"
Piyush Masrani846609b2014-03-14 19:21:48 +0530389 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200390
Dean Troyerdc97cb72015-03-28 08:20:50 -0500391 # Only die on API if it was actually intended to be turned on
Sean Dagueb9a70352014-03-04 15:02:04 -0500392 if is_service_enabled ceilometer-api; then
Sean Dague7083b822014-02-28 20:16:20 -0500393 echo "Waiting for ceilometer-api to start..."
sridhargaddamb5ab6462015-02-24 07:23:24 +0000394 if ! wait_for_service $SERVICE_TIMEOUT $CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/v2/; then
Sean Dague7083b822014-02-28 20:16:20 -0500395 die $LINENO "ceilometer-api did not start"
396 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200397 fi
398
Chris Dent027e2ea2015-06-05 18:43:50 +0000399 run_process ceilometer-alarm-notifier "$CEILOMETER_BIN_DIR/ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
400 run_process ceilometer-alarm-evaluator "$CEILOMETER_BIN_DIR/ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700401}
Dean Troyer7903b792012-09-13 17:16:12 -0500402
Dean Troyer699a29f2012-09-10 14:10:27 -0500403# stop_ceilometer() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100404function stop_ceilometer {
Chris Dentae6fb182014-09-16 15:17:13 +0100405 if [ "$CEILOMETER_USE_MOD_WSGI" == "True" ]; then
406 disable_apache_site ceilometer
407 restart_apache_server
408 fi
Dean Troyer699a29f2012-09-10 14:10:27 -0500409 # Kill the ceilometer screen windows
Lianhao Luc39f6402015-03-24 12:36:00 +0800410 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 +0100411 stop_process $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500412 done
413}
414
Dean Troyercc6b4432013-04-08 15:38:03 -0500415
Dean Troyer7903b792012-09-13 17:16:12 -0500416# Restore xtrace
417$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400418
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100419# Tell emacs to use shell-script-mode
420## Local variables:
421## mode: shell-script
422## End: