blob: fe25e1f7d45128af236b766a7afe64c4e9d77d9c [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
Flavio Percocodec13c32014-09-08 09:48:27 +020023# cleanup_zaqar_mongodb
Malini Kamalambal9504bb32014-08-01 17:41:08 -040024
25# Save trace setting
26XTRACE=$(set +o | grep xtrace)
27set +o xtrace
28
29
30# Defaults
31# --------
32
33# Set up default directories
34ZAQAR_DIR=$DEST/zaqar
35ZAQARCLIENT_DIR=$DEST/python-zaqarclient
36ZAQAR_CONF_DIR=/etc/zaqar
37ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf
38ZAQAR_API_LOG_DIR=/var/log/zaqar
39ZAQAR_API_LOG_FILE=$ZAQAR_API_LOG_DIR/queues.log
40ZAQAR_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
108 [ ! -d $ZAQAR_CONF_DIR ] && sudo mkdir -m 755 -p $ZAQAR_CONF_DIR
109 sudo chown $USER $ZAQAR_CONF_DIR
110
111 [ ! -d $ZAQAR_API_LOG_DIR ] && sudo mkdir -m 755 -p $ZAQAR_API_LOG_DIR
112 sudo chown $USER $ZAQAR_API_LOG_DIR
113
114 iniset $ZAQAR_CONF DEFAULT verbose True
115 iniset $ZAQAR_CONF DEFAULT use_syslog $SYSLOG
116 iniset $ZAQAR_CONF DEFAULT log_file $ZAQAR_API_LOG_FILE
117 iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST
118
Brant Knudson05952372014-09-19 17:22:22 -0500119 configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400120
121 if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then
122 iniset $ZAQAR_CONF drivers storage sqlalchemy
123 iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar`
124 elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
125 iniset $ZAQAR_CONF drivers storage mongodb
126 iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar
127 configure_mongodb
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400128 fi
Flavio Percocodec13c32014-09-08 09:48:27 +0200129
130 cleanup_zaqar
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400131}
132
133function configure_mongodb {
134 # Set nssize to 2GB. This increases the number of namespaces supported
135 # # per database.
136 if is_ubuntu; then
137 sudo sed -i -e "
138 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
139 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
140 " /etc/mongodb.conf
141 restart_service mongodb
142 elif is_fedora; then
143 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
144 restart_service mongod
145 fi
146}
147
148# init_zaqar() - Initialize etc.
149function init_zaqar {
150 # Create cache dir
151 sudo mkdir -p $ZAQAR_AUTH_CACHE_DIR
152 sudo chown $STACK_USER $ZAQAR_AUTH_CACHE_DIR
153 rm -f $ZAQAR_AUTH_CACHE_DIR/*
154}
155
156# install_zaqar() - Collect source and prepare
157function install_zaqar {
158 git_clone $ZAQAR_REPO $ZAQAR_DIR $ZAQAR_BRANCH
159 setup_develop $ZAQAR_DIR
160}
161
162# install_zaqarclient() - Collect source and prepare
163function install_zaqarclient {
164 git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH
165 setup_develop $ZAQARCLIENT_DIR
166}
167
168# start_zaqar() - Start running processes, including screen
169function start_zaqar {
170 if [[ "$USE_SCREEN" = "False" ]]; then
Chris Dent2f27a0e2014-09-09 13:46:02 +0100171 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400172 else
Chris Dent2f27a0e2014-09-09 13:46:02 +0100173 run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF"
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400174 fi
175
176 echo "Waiting for Zaqar to start..."
177 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
178 die $LINENO "Zaqar did not start"
179 fi
180}
181
182# stop_zaqar() - Stop running processes
183function stop_zaqar {
Dean Troyer64309192014-08-19 22:17:50 -0500184 local serv
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400185 # Kill the zaqar screen windows
186 for serv in zaqar-server; do
187 screen -S $SCREEN_NAME -p $serv -X kill
188 done
189}
190
191function create_zaqar_accounts {
Dean Troyer64309192014-08-19 22:17:50 -0500192 local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400193 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
194
Dean Troyer64309192014-08-19 22:17:50 -0500195 local zaqar_user=$(get_or_create_user "zaqar" \
196 "$SERVICE_PASSWORD" $service_tenant)
197 get_or_add_user_role $ADMIN_ROLE $zaqar_user $service_tenant
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400198
199 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
200
Dean Troyer64309192014-08-19 22:17:50 -0500201 local zaqar_service=$(get_or_create_service "zaqar" \
Victoria Martínez de la Cruzf080e892014-09-19 19:07:10 -0300202 "messaging" "Zaqar Service")
Dean Troyer64309192014-08-19 22:17:50 -0500203 get_or_create_endpoint $zaqar_service \
Malini Kamalambal9504bb32014-08-01 17:41:08 -0400204 "$REGION_NAME" \
205 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
206 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \
207 "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT"
208 fi
209
210}
211
212
213# Restore xtrace
214$XTRACE
215
216# Local variables:
217# mode: shell-script
218# End: