blob: fdab3a26a8b1aace220452fdca816f7644924b18 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Malini Kamalambal9504bb32014-08-01 17:41:08 -04003# lib/zaqar
4# Install and start **Zaqar** service
5
6# To enable a minimal set of Zaqar services, add the following to localrc:
7#
8# enable_service zaqar-server
9#
10# Dependencies:
11# - functions
12# - OS_AUTH_URL for auth in api
13# - DEST set to the destination directory
14# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
15# - STACK_USER service user
16
17# stack.sh
18# ---------
19# install_zaqar
20# configure_zaqar
21# init_zaqar
22# start_zaqar
23# stop_zaqar
24# cleanup_zaqar
Flavio Percocodec13c32014-09-08 09:48:27 +020025# cleanup_zaqar_mongodb
Malini Kamalambal9504bb32014-08-01 17:41:08 -040026
27# Save trace setting
28XTRACE=$(set +o | grep xtrace)
29set +o xtrace
30
31
32# Defaults
33# --------
34
35# Set up default directories
36ZAQAR_DIR=$DEST/zaqar
37ZAQARCLIENT_DIR=$DEST/python-zaqarclient
38ZAQAR_CONF_DIR=/etc/zaqar
39ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf
Malini Kamalambal9504bb32014-08-01 17:41:08 -040040ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar}
41
42# Support potential entry-points console scripts
43ZAQAR_BIN_DIR=$(get_python_exec_prefix)
44
45# Set up database backend
46ZAQAR_BACKEND=${ZAQAR_BACKEND:-mongodb}
47
48
49# Set Zaqar repository
50ZAQAR_REPO=${ZAQAR_REPO:-${GIT_BASE}/openstack/zaqar.git}
51ZAQAR_BRANCH=${ZAQAR_BRANCH:-master}
52
53# Set client library repository
54ZAQARCLIENT_REPO=${ZAQARCLIENT_REPO:-${GIT_BASE}/openstack/python-zaqarclient.git}
55ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master}
56
57# Set Zaqar Connection Info
58ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST}
59ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888}
60ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
61
62# Tell Tempest this project is present
63TEMPEST_SERVICES+=,zaqar
64
65
66# Functions
67# ---------
68
69# Test if any Zaqar services are enabled
70# is_zaqar_enabled
71function is_zaqar_enabled {
72 [[ ,${ENABLED_SERVICES} =~ ,"zaqar-" ]] && return 0
73 return 1
74}
75
Flavio Percocodec13c32014-09-08 09:48:27 +020076# cleanup_zaqar() - Cleans up general things from previous
77# runs and storage specific left overs.
Malini Kamalambal9504bb32014-08-01 17:41:08 -040078function cleanup_zaqar {
Flavio Percocodec13c32014-09-08 09:48:27 +020079 if [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
80 cleanup_zaqar_mongodb
81 fi
82}
83
84# cleanup_zaqar_mongodb() - Remove residual data files, anything left over from previous
85# runs that a clean run would need to clean up
86function cleanup_zaqar_mongodb {
Malini Kamalambal9504bb32014-08-01 17:41:08 -040087 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo zaqar --eval 'db.dropDatabase();'; do sleep 1; done"; then
88 die $LINENO "Mongo DB did not start"
89 else
90 full_version=$(mongo zaqar --eval 'db.dropDatabase();')
91 mongo_version=`echo $full_version | cut -d' ' -f4`
92 required_mongo_version='2.2'
93 if [[ $mongo_version < $required_mongo_version ]]; then
94 die $LINENO "Zaqar needs Mongo DB version >= 2.2 to run."
95 fi
96 fi
97}
98
99# configure_zaqarclient() - Set config files, create data dirs, etc
100function configure_zaqarclient {
101 setup_develop $ZAQARCLIENT_DIR
102}
103
104# configure_zaqar() - Set config files, create data dirs, etc
105function configure_zaqar {
106 setup_develop $ZAQAR_DIR
107
Dean Troyer8421c2b2015-03-16 13:52:19 -0500108 sudo install -d -o $STACK_USER -m 755 $ZAQAR_CONF_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400109
Victoria Martinez de la Cruz5bef3e12014-12-04 10:24:37 -0300110 iniset $ZAQAR_CONF DEFAULT debug True
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400111 iniset $ZAQAR_CONF DEFAULT verbose True
Flavio Percocob64738f2014-11-24 16:44:50 +0100112 iniset $ZAQAR_CONF DEFAULT admin_mode True
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400113 iniset $ZAQAR_CONF DEFAULT use_syslog $SYSLOG
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400114 iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST
115
Brant Knudson05952372014-09-19 17:22:22 -0500116 configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400117
118 if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then
119 iniset $ZAQAR_CONF drivers storage sqlalchemy
120 iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar`
121 elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
122 iniset $ZAQAR_CONF drivers storage mongodb
123 iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar
124 configure_mongodb
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200125 elif [ "$ZAQAR_BACKEND" = 'redis' ] ; then
126 iniset $ZAQAR_CONF drivers storage redis
127 iniset $ZAQAR_CONF 'drivers:storage:redis' uri redis://localhost:6379
128 configure_redis
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400129 fi
Flavio Percocodec13c32014-09-08 09:48:27 +0200130
Sean Dague37eca482015-06-16 07:19:22 -0400131 iniset $ZAQAR_CONF DEFAULT notification_driver messaging
132 iniset $ZAQAR_CONF DEFAULT control_exchange zaqar
133
Brant Knudson2dd110c2015-03-14 12:39:14 -0500134 iniset_rpc_backend zaqar $ZAQAR_CONF
Zhi Yan Liu0f52d932014-12-30 14:37:02 +0800135
Flavio Percocodec13c32014-09-08 09:48:27 +0200136 cleanup_zaqar
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400137}
138
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200139function configure_redis {
140 if is_ubuntu; then
141 install_package redis-server
Sean Dague60996b12015-04-08 09:06:49 -0400142 pip_install_gr redis
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200143 elif is_fedora; then
144 install_package redis
Sean Dague60996b12015-04-08 09:06:49 -0400145 pip_install_gr redis
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200146 else
147 exit_distro_not_supported "redis installation"
148 fi
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200149}
150
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400151function configure_mongodb {
152 # Set nssize to 2GB. This increases the number of namespaces supported
153 # # per database.
154 if is_ubuntu; then
155 sudo sed -i -e "
156 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
157 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
158 " /etc/mongodb.conf
159 restart_service mongodb
160 elif is_fedora; then
161 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
162 restart_service mongod
163 fi
164}
165
166# init_zaqar() - Initialize etc.
167function init_zaqar {
168 # Create cache dir
Dean Troyer8421c2b2015-03-16 13:52:19 -0500169 sudo install -d -o $STACK_USER $ZAQAR_AUTH_CACHE_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400170 rm -f $ZAQAR_AUTH_CACHE_DIR/*
171}
172
173# install_zaqar() - Collect source and prepare
174function install_zaqar {
175 git_clone $ZAQAR_REPO $ZAQAR_DIR $ZAQAR_BRANCH
176 setup_develop $ZAQAR_DIR
177}
178
179# install_zaqarclient() - Collect source and prepare
180function install_zaqarclient {
181 git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH
182 setup_develop $ZAQARCLIENT_DIR
183}
184
185# start_zaqar() - Start running processes, including screen
186function start_zaqar {
187 if [[ "$USE_SCREEN" = "False" ]]; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100188 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400189 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100190 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400191 fi
192
193 echo "Waiting for Zaqar to start..."
194 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT/v1/health; do sleep 1; done"; then
195 die $LINENO "Zaqar did not start"
196 fi
197}
198
199# stop_zaqar() - Stop running processes
200function stop_zaqar {
Dean Troyer64309192014-08-19 22:17:50 -0500201 local serv
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400202 # Kill the zaqar screen windows
203 for serv in zaqar-server; do
204 screen -S $SCREEN_NAME -p $serv -X kill
205 done
206}
207
208function create_zaqar_accounts {
Jamie Lennoxe8bc2b82015-02-10 20:38:56 +1100209 create_service_user "zaqar"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400210
211 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
212
Jamie Lennoxb17ad752015-05-29 06:04:47 +0000213 get_or_create_service "zaqar" "messaging" "Zaqar Service"
214 get_or_create_endpoint "messaging" \
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400215 "$REGION_NAME" \
216 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
217 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
218 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT"
219 fi
220
221}
222
223
224# Restore xtrace
225$XTRACE
226
227# Local variables:
228# mode: shell-script
229# End: