blob: fac3be14a96c21c01f1c58c913e48353ad25ee54 [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
51# Functions
52# ---------
53
John H. Tran93361642012-07-26 11:22:05 -070054# cleanup_ceilometer() - Remove residual data files, anything left over from previous
55# runs that a clean run would need to clean up
56function cleanup_ceilometer() {
David Kranz867cf422012-10-26 13:25:19 -040057 mongo ceilometer --eval "db.dropDatabase();"
John H. Tran93361642012-07-26 11:22:05 -070058}
59
Yunhong, Jiange583d9b2013-01-09 09:33:07 +080060# configure_ceilometerclient() - Set config files, create data dirs, etc
61function configure_ceilometerclient() {
62 setup_develop $CEILOMETERCLIENT_DIR
63}
64
John H. Tran93361642012-07-26 11:22:05 -070065# configure_ceilometer() - Set config files, create data dirs, etc
66function configure_ceilometer() {
67 setup_develop $CEILOMETER_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +053068
Doug Hellmannc5259b42012-09-22 10:52:31 -040069 [ ! -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +010070 sudo chown $STACK_USER $CEILOMETER_CONF_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +053071
Doug Hellmannc5259b42012-09-22 10:52:31 -040072 [ ! -d $CEILOMETER_API_LOG_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +010073 sudo chown $STACK_USER $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -070074
Eoghan Glynn8c11f562013-03-01 12:09:01 +000075 iniset_rpc_backend ceilometer $CEILOMETER_CONF DEFAULT
Eoghan Glynnd36268a2013-02-22 21:59:52 +000076
Gordon Chung701eb612013-05-10 10:45:50 -040077 iniset $CEILOMETER_CONF DEFAULT notification_topics 'notifications'
Julien Danjou4b3e4e52012-10-24 16:32:01 +020078 iniset $CEILOMETER_CONF DEFAULT verbose True
Doug Hellmann53a5f422012-10-02 17:29:23 -040079
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040080 # Install the policy file for the API server
81 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
Yunhong, Jiang8407b2d2013-02-07 13:48:33 +080082 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040083 iniset $CEILOMETER_CONF DEFAULT policy_file $CEILOMETER_CONF_DIR/policy.json
84
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +020085 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
86 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
87 fi
88
Eoghan Glynn14246ac2012-11-14 16:23:04 +000089 # the compute and central agents need these credentials in order to
90 # call out to the public nova and glance APIs
91 iniset $CEILOMETER_CONF DEFAULT os_username ceilometer
92 iniset $CEILOMETER_CONF DEFAULT os_password $SERVICE_PASSWORD
93 iniset $CEILOMETER_CONF DEFAULT os_tenant_name $SERVICE_TENANT_NAME
Eoghan Glynn14246ac2012-11-14 16:23:04 +000094
Julien Danjou4b3e4e52012-10-24 16:32:01 +020095 iniset $CEILOMETER_CONF keystone_authtoken auth_protocol http
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040096 iniset $CEILOMETER_CONF keystone_authtoken admin_user ceilometer
97 iniset $CEILOMETER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
98 iniset $CEILOMETER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
Lianhao Lu8c548492013-01-09 10:41:54 +080099 iniset $CEILOMETER_CONF keystone_authtoken signing_dir $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400100
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000101 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800102 iniset $CEILOMETER_CONF database connection `database_connection_url ceilometer`
103 else
104 iniset $CEILOMETER_CONF database connection mongodb://localhost:27017/ceilometer
105 configure_mongodb
106 cleanup_ceilometer
107 fi
John H. Tran93361642012-07-26 11:22:05 -0700108}
109
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500110function configure_mongodb() {
Dean Troyercc6b4432013-04-08 15:38:03 -0500111 if is_fedora; then
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500112 # ensure smallfiles selected to minimize freespace requirements
113 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
114
115 restart_service mongod
116 fi
117}
118
Lianhao Lu8c548492013-01-09 10:41:54 +0800119# init_ceilometer() - Initialize etc.
120function init_ceilometer() {
121 # Create cache dir
122 sudo mkdir -p $CEILOMETER_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100123 sudo chown $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800124 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800125
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000126 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800127 recreate_database ceilometer utf8
128 $CEILOMETER_BIN_DIR/ceilometer-dbsync
129 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800130}
131
John H. Tran93361642012-07-26 11:22:05 -0700132# install_ceilometer() - Collect source and prepare
133function install_ceilometer() {
134 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
135}
136
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800137# install_ceilometerclient() - Collect source and prepare
138function install_ceilometerclient() {
139 git_clone $CEILOMETERCLIENT_REPO $CEILOMETERCLIENT_DIR $CEILOMETERCLIENT_BRANCH
140}
141
John H. Tran93361642012-07-26 11:22:05 -0700142# start_ceilometer() - Start running processes, including screen
143function start_ceilometer() {
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000144 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
145 screen_it ceilometer-acompute "cd ; sg $LIBVIRT_GROUP \"ceilometer-agent-compute --config-file $CEILOMETER_CONF\""
146 fi
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200147 screen_it ceilometer-acentral "cd ; ceilometer-agent-central --config-file $CEILOMETER_CONF"
Gordon Chung1c402282013-11-26 13:30:11 -0500148 screen_it ceilometer-anotification "cd ; ceilometer-agent-notification --config-file $CEILOMETER_CONF"
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200149 screen_it ceilometer-collector "cd ; ceilometer-collector --config-file $CEILOMETER_CONF"
150 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 +0200151
152 echo "Waiting for ceilometer-api to start..."
153 if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl --noproxy '*' -s http://localhost:8777/v2/ >/dev/null; do sleep 1; done"; then
154 die $LINENO "ceilometer-api did not start"
155 fi
156
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200157 screen_it ceilometer-alarm-notifier "cd ; ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
158 screen_it ceilometer-alarm-evaluator "cd ; ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700159}
Dean Troyer7903b792012-09-13 17:16:12 -0500160
Dean Troyer699a29f2012-09-10 14:10:27 -0500161# stop_ceilometer() - Stop running processes
162function stop_ceilometer() {
163 # Kill the ceilometer screen windows
Gordon Chung1c402282013-11-26 13:30:11 -0500164 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 -0500165 screen -S $SCREEN_NAME -p $serv -X kill
166 done
167}
168
Dean Troyercc6b4432013-04-08 15:38:03 -0500169
Dean Troyer7903b792012-09-13 17:16:12 -0500170# Restore xtrace
171$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400172
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100173# Tell emacs to use shell-script-mode
174## Local variables:
175## mode: shell-script
176## End: