blob: 0d1f6f4aaf0a8051845c5c9d928703398edc7634 [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
40ZAQAR_API_LOG_DIR=/var/log/zaqar
41ZAQAR_API_LOG_FILE=$ZAQAR_API_LOG_DIR/queues.log
42ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar}
43
44# Support potential entry-points console scripts
45ZAQAR_BIN_DIR=$(get_python_exec_prefix)
46
47# Set up database backend
48ZAQAR_BACKEND=${ZAQAR_BACKEND:-mongodb}
49
50
51# Set Zaqar repository
52ZAQAR_REPO=${ZAQAR_REPO:-${GIT_BASE}/openstack/zaqar.git}
53ZAQAR_BRANCH=${ZAQAR_BRANCH:-master}
54
55# Set client library repository
56ZAQARCLIENT_REPO=${ZAQARCLIENT_REPO:-${GIT_BASE}/openstack/python-zaqarclient.git}
57ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master}
58
59# Set Zaqar Connection Info
60ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST}
61ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888}
62ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
63
64# Tell Tempest this project is present
65TEMPEST_SERVICES+=,zaqar
66
67
68# Functions
69# ---------
70
71# Test if any Zaqar services are enabled
72# is_zaqar_enabled
73function is_zaqar_enabled {
74 [[ ,${ENABLED_SERVICES} =~ ,"zaqar-" ]] && return 0
75 return 1
76}
77
Flavio Percocodec13c32014-09-08 09:48:27 +020078# cleanup_zaqar() - Cleans up general things from previous
79# runs and storage specific left overs.
Malini Kamalambal9504bb32014-08-01 17:41:08 -040080function cleanup_zaqar {
Flavio Percocodec13c32014-09-08 09:48:27 +020081 if [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
82 cleanup_zaqar_mongodb
83 fi
84}
85
86# cleanup_zaqar_mongodb() - Remove residual data files, anything left over from previous
87# runs that a clean run would need to clean up
88function cleanup_zaqar_mongodb {
Malini Kamalambal9504bb32014-08-01 17:41:08 -040089 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo zaqar --eval 'db.dropDatabase();'; do sleep 1; done"; then
90 die $LINENO "Mongo DB did not start"
91 else
92 full_version=$(mongo zaqar --eval 'db.dropDatabase();')
93 mongo_version=`echo $full_version | cut -d' ' -f4`
94 required_mongo_version='2.2'
95 if [[ $mongo_version < $required_mongo_version ]]; then
96 die $LINENO "Zaqar needs Mongo DB version >= 2.2 to run."
97 fi
98 fi
99}
100
101# configure_zaqarclient() - Set config files, create data dirs, etc
102function configure_zaqarclient {
103 setup_develop $ZAQARCLIENT_DIR
104}
105
106# configure_zaqar() - Set config files, create data dirs, etc
107function configure_zaqar {
108 setup_develop $ZAQAR_DIR
109
110 [ ! -d $ZAQAR_CONF_DIR ] && sudo mkdir -m 755 -p $ZAQAR_CONF_DIR
111 sudo chown $USER $ZAQAR_CONF_DIR
112
113 [ ! -d $ZAQAR_API_LOG_DIR ] && sudo mkdir -m 755 -p $ZAQAR_API_LOG_DIR
114 sudo chown $USER $ZAQAR_API_LOG_DIR
115
Victoria Martinez de la Cruz5bef3e12014-12-04 10:24:37 -0300116 iniset $ZAQAR_CONF DEFAULT debug True
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400117 iniset $ZAQAR_CONF DEFAULT verbose True
Flavio Percocob64738f2014-11-24 16:44:50 +0100118 iniset $ZAQAR_CONF DEFAULT admin_mode True
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400119 iniset $ZAQAR_CONF DEFAULT use_syslog $SYSLOG
120 iniset $ZAQAR_CONF DEFAULT log_file $ZAQAR_API_LOG_FILE
121 iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST
122
Brant Knudson05952372014-09-19 17:22:22 -0500123 configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400124
125 if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then
126 iniset $ZAQAR_CONF drivers storage sqlalchemy
127 iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar`
128 elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
129 iniset $ZAQAR_CONF drivers storage mongodb
130 iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar
131 configure_mongodb
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200132 elif [ "$ZAQAR_BACKEND" = 'redis' ] ; then
133 iniset $ZAQAR_CONF drivers storage redis
134 iniset $ZAQAR_CONF 'drivers:storage:redis' uri redis://localhost:6379
135 configure_redis
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400136 fi
Flavio Percocodec13c32014-09-08 09:48:27 +0200137
138 cleanup_zaqar
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400139}
140
Flavio Percocoe29a55a2014-09-05 16:03:01 +0200141function configure_redis {
142 if is_ubuntu; then
143 install_package redis-server
144 elif is_fedora; then
145 install_package redis
146 else
147 exit_distro_not_supported "redis installation"
148 fi
149
150 install_package python-redis
151}
152
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400153function configure_mongodb {
154 # Set nssize to 2GB. This increases the number of namespaces supported
155 # # per database.
156 if is_ubuntu; then
157 sudo sed -i -e "
158 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
159 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
160 " /etc/mongodb.conf
161 restart_service mongodb
162 elif is_fedora; then
163 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
164 restart_service mongod
165 fi
166}
167
168# init_zaqar() - Initialize etc.
169function init_zaqar {
170 # Create cache dir
171 sudo mkdir -p $ZAQAR_AUTH_CACHE_DIR
172 sudo chown $STACK_USER $ZAQAR_AUTH_CACHE_DIR
173 rm -f $ZAQAR_AUTH_CACHE_DIR/*
174}
175
176# install_zaqar() - Collect source and prepare
177function install_zaqar {
178 git_clone $ZAQAR_REPO $ZAQAR_DIR $ZAQAR_BRANCH
179 setup_develop $ZAQAR_DIR
180}
181
182# install_zaqarclient() - Collect source and prepare
183function install_zaqarclient {
184 git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH
185 setup_develop $ZAQARCLIENT_DIR
186}
187
188# start_zaqar() - Start running processes, including screen
189function start_zaqar {
190 if [[ "$USE_SCREEN" = "False" ]]; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100191 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400192 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100193 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400194 fi
195
196 echo "Waiting for Zaqar to start..."
197 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
198 die $LINENO "Zaqar did not start"
199 fi
200}
201
202# stop_zaqar() - Stop running processes
203function stop_zaqar {
Dean Troyer64309192014-08-19 22:17:50 -0500204 local serv
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400205 # Kill the zaqar screen windows
206 for serv in zaqar-server; do
207 screen -S $SCREEN_NAME -p $serv -X kill
208 done
209}
210
211function create_zaqar_accounts {
Dean Troyer64309192014-08-19 22:17:50 -0500212 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400213 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
214
Dean Troyer64309192014-08-19 22:17:50 -0500215 local zaqar_user=$(get_or_create_user "zaqar" \
216 "$SERVICE_PASSWORD" $service_tenant)
217 get_or_add_user_role $ADMIN_ROLE $zaqar_user $service_tenant
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400218
219 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
220
Dean Troyer64309192014-08-19 22:17:50 -0500221 local zaqar_service=$(get_or_create_service "zaqar" \
Victoria Martínez de la Cruzf080e892014-09-19 19:07:10 -0300222 "messaging" "Zaqar Service")
Dean Troyer64309192014-08-19 22:17:50 -0500223 get_or_create_endpoint $zaqar_service \
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400224 "$REGION_NAME" \
225 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
226 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
227 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT"
228 fi
229
230}
231
232
233# Restore xtrace
234$XTRACE
235
236# Local variables:
237# mode: shell-script
238# End: