blob: fe72fcdb11f4ed6b8e25adec86039fe6e53a0346 [file] [log] [blame]
John H. Tran93361642012-07-26 11:22:05 -07001# lib/ceilometer
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Ceilometer** service
3
Eoghan Glynn8d137032013-07-30 14:14:55 +00004# To enable a minimal set of Ceilometer services, add the following to localrc:
Adam Spierscb961592013-10-05 12:11:07 +01005#
Gordon Chung1c402282013-11-26 13:30:11 -05006# enable_service ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api
Eoghan Glynn8d137032013-07-30 14:14:55 +00007#
8# To ensure Ceilometer alarming services are enabled also, further add to the localrc:
Adam Spierscb961592013-10-05 12:11:07 +01009#
Eoghan Glynn19eed742013-09-20 21:11:25 +000010# enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator
Surya Prabhakar31d31852012-09-17 20:25:41 +053011
John H. Tran93361642012-07-26 11:22:05 -070012# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013#
John H. Tran93361642012-07-26 11:22:05 -070014# - functions
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040015# - OS_AUTH_URL for auth in api
Eoghan Glynnad80ead2012-09-27 09:36:33 +010016# - DEST set to the destination directory
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040017# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
Attila Fazekas91b8d132013-01-06 22:40:09 +010018# - STACK_USER service user
John H. Tran93361642012-07-26 11:22:05 -070019
20# stack.sh
21# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010022# - install_ceilometer
23# - configure_ceilometer
24# - init_ceilometer
25# - start_ceilometer
26# - stop_ceilometer
27# - cleanup_ceilometer
John H. Tran93361642012-07-26 11:22:05 -070028
Dean Troyer7903b792012-09-13 17:16:12 -050029# Save trace setting
30XTRACE=$(set +o | grep xtrace)
31set +o xtrace
John H. Tran93361642012-07-26 11:22:05 -070032
33
34# Defaults
35# --------
36
Dean Troyer6d04fd72012-12-21 11:03:37 -060037# Set up default directories
John H. Tran93361642012-07-26 11:22:05 -070038CEILOMETER_DIR=$DEST/ceilometer
Yunhong, Jiange583d9b2013-01-09 09:33:07 +080039CEILOMETERCLIENT_DIR=$DEST/python-ceilometerclient
Dean Troyer6d04fd72012-12-21 11:03:37 -060040CEILOMETER_CONF_DIR=/etc/ceilometer
41CEILOMETER_CONF=$CEILOMETER_CONF_DIR/ceilometer.conf
42CEILOMETER_API_LOG_DIR=/var/log/ceilometer-api
Lianhao Lu8c548492013-01-09 10:41:54 +080043CEILOMETER_AUTH_CACHE_DIR=${CEILOMETER_AUTH_CACHE_DIR:-/var/cache/ceilometer}
Dean Troyer6d04fd72012-12-21 11:03:37 -060044
Monty Taylor9fbeedd2012-08-17 12:52:27 -040045# Support potential entry-points console scripts
Guangyu Suo9778b3c2013-07-17 15:22:21 +080046CEILOMETER_BIN_DIR=$(get_python_exec_prefix)
John H. Tran93361642012-07-26 11:22:05 -070047
Guangyu Suo9778b3c2013-07-17 15:22:21 +080048# Set up database backend
Julien Danjou69f74572013-08-27 11:43:53 +020049CEILOMETER_BACKEND=${CEILOMETER_BACKEND:-mysql}
Dean Troyercc6b4432013-04-08 15:38:03 -050050
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010051# Ceilometer connection info.
52CEILOMETER_SERVICE_PROTOCOL=http
53CEILOMETER_SERVICE_HOST=$SERVICE_HOST
54CEILOMETER_SERVICE_PORT=${CEILOMETER_SERVICE_PORT:-8777}
55#
56
Dean Troyercc6b4432013-04-08 15:38:03 -050057# Functions
58# ---------
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010059#
60# create_ceilometer_accounts() - Set up common required ceilometer accounts
61
62create_ceilometer_accounts() {
63
64 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
65 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
66
67 # Ceilometer
68 if [[ "$ENABLED_SERVICES" =~ "ceilometer-api" ]]; then
69 CEILOMETER_USER=$(keystone user-create \
70 --name=ceilometer \
71 --pass="$SERVICE_PASSWORD" \
72 --tenant_id $SERVICE_TENANT \
73 --email=ceilometer@example.com \
74 | grep " id " | get_field 2)
75 keystone user-role-add \
76 --tenant-id $SERVICE_TENANT \
77 --user-id $CEILOMETER_USER \
78 --role-id $ADMIN_ROLE
79 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
80 CEILOMETER_SERVICE=$(keystone service-create \
81 --name=ceilometer \
82 --type=metering \
83 --description="OpenStack Telemetry Service" \
84 | grep " id " | get_field 2)
85 keystone endpoint-create \
86 --region RegionOne \
87 --service_id $CEILOMETER_SERVICE \
88 --publicurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
89 --adminurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
90 --internalurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
91 fi
92 fi
93}
94
Dean Troyercc6b4432013-04-08 15:38:03 -050095
John H. Tran93361642012-07-26 11:22:05 -070096# cleanup_ceilometer() - Remove residual data files, anything left over from previous
97# runs that a clean run would need to clean up
98function cleanup_ceilometer() {
David Kranz867cf422012-10-26 13:25:19 -040099 mongo ceilometer --eval "db.dropDatabase();"
John H. Tran93361642012-07-26 11:22:05 -0700100}
101
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800102# configure_ceilometerclient() - Set config files, create data dirs, etc
103function configure_ceilometerclient() {
104 setup_develop $CEILOMETERCLIENT_DIR
105}
106
John H. Tran93361642012-07-26 11:22:05 -0700107# configure_ceilometer() - Set config files, create data dirs, etc
108function configure_ceilometer() {
109 setup_develop $CEILOMETER_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +0530110
Doug Hellmannc5259b42012-09-22 10:52:31 -0400111 [ ! -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +0100112 sudo chown $STACK_USER $CEILOMETER_CONF_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +0530113
Doug Hellmannc5259b42012-09-22 10:52:31 -0400114 [ ! -d $CEILOMETER_API_LOG_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +0100115 sudo chown $STACK_USER $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -0700116
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000117 iniset_rpc_backend ceilometer $CEILOMETER_CONF DEFAULT
Eoghan Glynnd36268a2013-02-22 21:59:52 +0000118
Gordon Chung701eb612013-05-10 10:45:50 -0400119 iniset $CEILOMETER_CONF DEFAULT notification_topics 'notifications'
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200120 iniset $CEILOMETER_CONF DEFAULT verbose True
Doug Hellmann53a5f422012-10-02 17:29:23 -0400121
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400122 # Install the policy file for the API server
123 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
Yunhong, Jiang8407b2d2013-02-07 13:48:33 +0800124 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400125 iniset $CEILOMETER_CONF DEFAULT policy_file $CEILOMETER_CONF_DIR/policy.json
126
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +0200127 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
128 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
129 fi
130
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000131 # the compute and central agents need these credentials in order to
132 # call out to the public nova and glance APIs
133 iniset $CEILOMETER_CONF DEFAULT os_username ceilometer
134 iniset $CEILOMETER_CONF DEFAULT os_password $SERVICE_PASSWORD
135 iniset $CEILOMETER_CONF DEFAULT os_tenant_name $SERVICE_TENANT_NAME
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000136
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200137 iniset $CEILOMETER_CONF keystone_authtoken auth_protocol http
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400138 iniset $CEILOMETER_CONF keystone_authtoken admin_user ceilometer
139 iniset $CEILOMETER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
140 iniset $CEILOMETER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
Lianhao Lu8c548492013-01-09 10:41:54 +0800141 iniset $CEILOMETER_CONF keystone_authtoken signing_dir $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400142
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000143 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800144 iniset $CEILOMETER_CONF database connection `database_connection_url ceilometer`
145 else
146 iniset $CEILOMETER_CONF database connection mongodb://localhost:27017/ceilometer
147 configure_mongodb
148 cleanup_ceilometer
149 fi
John H. Tran93361642012-07-26 11:22:05 -0700150}
151
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500152function configure_mongodb() {
Dean Troyercc6b4432013-04-08 15:38:03 -0500153 if is_fedora; then
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500154 # ensure smallfiles selected to minimize freespace requirements
155 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
156
157 restart_service mongod
158 fi
159}
160
Lianhao Lu8c548492013-01-09 10:41:54 +0800161# init_ceilometer() - Initialize etc.
162function init_ceilometer() {
163 # Create cache dir
164 sudo mkdir -p $CEILOMETER_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100165 sudo chown $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800166 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800167
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000168 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800169 recreate_database ceilometer utf8
170 $CEILOMETER_BIN_DIR/ceilometer-dbsync
171 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800172}
173
John H. Tran93361642012-07-26 11:22:05 -0700174# install_ceilometer() - Collect source and prepare
175function install_ceilometer() {
176 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
177}
178
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800179# install_ceilometerclient() - Collect source and prepare
180function install_ceilometerclient() {
181 git_clone $CEILOMETERCLIENT_REPO $CEILOMETERCLIENT_DIR $CEILOMETERCLIENT_BRANCH
182}
183
John H. Tran93361642012-07-26 11:22:05 -0700184# start_ceilometer() - Start running processes, including screen
185function start_ceilometer() {
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000186 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
187 screen_it ceilometer-acompute "cd ; sg $LIBVIRT_GROUP \"ceilometer-agent-compute --config-file $CEILOMETER_CONF\""
188 fi
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200189 screen_it ceilometer-acentral "cd ; ceilometer-agent-central --config-file $CEILOMETER_CONF"
Gordon Chung1c402282013-11-26 13:30:11 -0500190 screen_it ceilometer-anotification "cd ; ceilometer-agent-notification --config-file $CEILOMETER_CONF"
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200191 screen_it ceilometer-collector "cd ; ceilometer-collector --config-file $CEILOMETER_CONF"
192 screen_it ceilometer-api "cd ; ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR --config-file $CEILOMETER_CONF"
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200193
194 echo "Waiting for ceilometer-api to start..."
195 if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl --noproxy '*' -s http://localhost:8777/v2/ >/dev/null; do sleep 1; done"; then
196 die $LINENO "ceilometer-api did not start"
197 fi
198
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200199 screen_it ceilometer-alarm-notifier "cd ; ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
200 screen_it ceilometer-alarm-evaluator "cd ; ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700201}
Dean Troyer7903b792012-09-13 17:16:12 -0500202
Dean Troyer699a29f2012-09-10 14:10:27 -0500203# stop_ceilometer() - Stop running processes
204function stop_ceilometer() {
205 # Kill the ceilometer screen windows
Gordon Chung1c402282013-11-26 13:30:11 -0500206 for serv in ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api ceilometer-alarm-notifier ceilometer-alarm-evaluator; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500207 screen -S $SCREEN_NAME -p $serv -X kill
208 done
209}
210
Dean Troyercc6b4432013-04-08 15:38:03 -0500211
Dean Troyer7903b792012-09-13 17:16:12 -0500212# Restore xtrace
213$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400214
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100215# Tell emacs to use shell-script-mode
216## Local variables:
217## mode: shell-script
218## End: