blob: 93b727e63bdd5fa522998ddae0cc365e429aa8b5 [file] [log] [blame]
Malini Kamalambal9504bb32014-08-01 17:41:08 -04001# lib/zaqar
2# Install and start **Zaqar** service
3
4# To enable a minimal set of Zaqar services, add the following to localrc:
5#
6# enable_service zaqar-server
7#
8# Dependencies:
9# - functions
10# - OS_AUTH_URL for auth in api
11# - DEST set to the destination directory
12# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
13# - STACK_USER service user
14
15# stack.sh
16# ---------
17# install_zaqar
18# configure_zaqar
19# init_zaqar
20# start_zaqar
21# stop_zaqar
22# cleanup_zaqar
23
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
32# Set up default directories
33ZAQAR_DIR=$DEST/zaqar
34ZAQARCLIENT_DIR=$DEST/python-zaqarclient
35ZAQAR_CONF_DIR=/etc/zaqar
36ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf
37ZAQAR_API_LOG_DIR=/var/log/zaqar
38ZAQAR_API_LOG_FILE=$ZAQAR_API_LOG_DIR/queues.log
39ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar}
40
41# Support potential entry-points console scripts
42ZAQAR_BIN_DIR=$(get_python_exec_prefix)
43
44# Set up database backend
45ZAQAR_BACKEND=${ZAQAR_BACKEND:-mongodb}
46
47
48# Set Zaqar repository
49ZAQAR_REPO=${ZAQAR_REPO:-${GIT_BASE}/openstack/zaqar.git}
50ZAQAR_BRANCH=${ZAQAR_BRANCH:-master}
51
52# Set client library repository
53ZAQARCLIENT_REPO=${ZAQARCLIENT_REPO:-${GIT_BASE}/openstack/python-zaqarclient.git}
54ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master}
55
56# Set Zaqar Connection Info
57ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST}
58ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888}
59ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
60
61# Tell Tempest this project is present
62TEMPEST_SERVICES+=,zaqar
63
64
65# Functions
66# ---------
67
68# Test if any Zaqar services are enabled
69# is_zaqar_enabled
70function is_zaqar_enabled {
71 [[ ,${ENABLED_SERVICES} =~ ,"zaqar-" ]] && return 0
72 return 1
73}
74
75# cleanup_zaqar() - Remove residual data files, anything left over from previous
76# runs that a clean run would need to clean up
77function cleanup_zaqar {
78 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo zaqar --eval 'db.dropDatabase();'; do sleep 1; done"; then
79 die $LINENO "Mongo DB did not start"
80 else
81 full_version=$(mongo zaqar --eval 'db.dropDatabase();')
82 mongo_version=`echo $full_version | cut -d' ' -f4`
83 required_mongo_version='2.2'
84 if [[ $mongo_version < $required_mongo_version ]]; then
85 die $LINENO "Zaqar needs Mongo DB version >= 2.2 to run."
86 fi
87 fi
88}
89
90# configure_zaqarclient() - Set config files, create data dirs, etc
91function configure_zaqarclient {
92 setup_develop $ZAQARCLIENT_DIR
93}
94
95# configure_zaqar() - Set config files, create data dirs, etc
96function configure_zaqar {
97 setup_develop $ZAQAR_DIR
98
99 [ ! -d $ZAQAR_CONF_DIR ] && sudo mkdir -m 755 -p $ZAQAR_CONF_DIR
100 sudo chown $USER $ZAQAR_CONF_DIR
101
102 [ ! -d $ZAQAR_API_LOG_DIR ] && sudo mkdir -m 755 -p $ZAQAR_API_LOG_DIR
103 sudo chown $USER $ZAQAR_API_LOG_DIR
104
105 iniset $ZAQAR_CONF DEFAULT verbose True
106 iniset $ZAQAR_CONF DEFAULT use_syslog $SYSLOG
107 iniset $ZAQAR_CONF DEFAULT log_file $ZAQAR_API_LOG_FILE
108 iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST
109
Brant Knudson05952372014-09-19 17:22:22 -0500110 configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400111
112 if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then
113 iniset $ZAQAR_CONF drivers storage sqlalchemy
114 iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar`
115 elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
116 iniset $ZAQAR_CONF drivers storage mongodb
117 iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar
118 configure_mongodb
119 cleanup_zaqar
120 fi
121}
122
123function configure_mongodb {
124 # Set nssize to 2GB. This increases the number of namespaces supported
125 # # per database.
126 if is_ubuntu; then
127 sudo sed -i -e "
128 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
129 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
130 " /etc/mongodb.conf
131 restart_service mongodb
132 elif is_fedora; then
133 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
134 restart_service mongod
135 fi
136}
137
138# init_zaqar() - Initialize etc.
139function init_zaqar {
140 # Create cache dir
141 sudo mkdir -p $ZAQAR_AUTH_CACHE_DIR
142 sudo chown $STACK_USER $ZAQAR_AUTH_CACHE_DIR
143 rm -f $ZAQAR_AUTH_CACHE_DIR/*
144}
145
146# install_zaqar() - Collect source and prepare
147function install_zaqar {
148 git_clone $ZAQAR_REPO $ZAQAR_DIR $ZAQAR_BRANCH
149 setup_develop $ZAQAR_DIR
150}
151
152# install_zaqarclient() - Collect source and prepare
153function install_zaqarclient {
154 git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH
155 setup_develop $ZAQARCLIENT_DIR
156}
157
158# start_zaqar() - Start running processes, including screen
159function start_zaqar {
160 if [[ "$USE_SCREEN" = "False" ]]; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100161 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400162 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100163 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400164 fi
165
166 echo "Waiting for Zaqar to start..."
167 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
168 die $LINENO "Zaqar did not start"
169 fi
170}
171
172# stop_zaqar() - Stop running processes
173function stop_zaqar {
Dean Troyer64309192014-08-19 22:17:50 -0500174 local serv
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400175 # Kill the zaqar screen windows
176 for serv in zaqar-server; do
177 screen -S $SCREEN_NAME -p $serv -X kill
178 done
179}
180
181function create_zaqar_accounts {
Dean Troyer64309192014-08-19 22:17:50 -0500182 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400183 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
184
Dean Troyer64309192014-08-19 22:17:50 -0500185 local zaqar_user=$(get_or_create_user "zaqar" \
186 "$SERVICE_PASSWORD" $service_tenant)
187 get_or_add_user_role $ADMIN_ROLE $zaqar_user $service_tenant
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400188
189 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
190
Dean Troyer64309192014-08-19 22:17:50 -0500191 local zaqar_service=$(get_or_create_service "zaqar" \
Victoria Martínez de la Cruzf080e892014-09-19 19:07:10 -0300192 "messaging" "Zaqar Service")
Dean Troyer64309192014-08-19 22:17:50 -0500193 get_or_create_endpoint $zaqar_service \
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400194 "$REGION_NAME" \
195 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
196 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
197 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT"
198 fi
199
200}
201
202
203# Restore xtrace
204$XTRACE
205
206# Local variables:
207# mode: shell-script
208# End: