| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 3 | # 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 Percoco | dec13c3 | 2014-09-08 09:48:27 +0200 | [diff] [blame] | 25 | # cleanup_zaqar_mongodb | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 26 |  | 
|  | 27 | # Save trace setting | 
|  | 28 | XTRACE=$(set +o | grep xtrace) | 
|  | 29 | set +o xtrace | 
|  | 30 |  | 
|  | 31 |  | 
|  | 32 | # Defaults | 
|  | 33 | # -------- | 
|  | 34 |  | 
|  | 35 | # Set up default directories | 
|  | 36 | ZAQAR_DIR=$DEST/zaqar | 
|  | 37 | ZAQARCLIENT_DIR=$DEST/python-zaqarclient | 
|  | 38 | ZAQAR_CONF_DIR=/etc/zaqar | 
|  | 39 | ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 40 | ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar} | 
|  | 41 |  | 
|  | 42 | # Support potential entry-points console scripts | 
|  | 43 | ZAQAR_BIN_DIR=$(get_python_exec_prefix) | 
|  | 44 |  | 
|  | 45 | # Set up database backend | 
|  | 46 | ZAQAR_BACKEND=${ZAQAR_BACKEND:-mongodb} | 
|  | 47 |  | 
|  | 48 |  | 
|  | 49 | # Set Zaqar repository | 
|  | 50 | ZAQAR_REPO=${ZAQAR_REPO:-${GIT_BASE}/openstack/zaqar.git} | 
|  | 51 | ZAQAR_BRANCH=${ZAQAR_BRANCH:-master} | 
|  | 52 |  | 
|  | 53 | # Set client library repository | 
|  | 54 | ZAQARCLIENT_REPO=${ZAQARCLIENT_REPO:-${GIT_BASE}/openstack/python-zaqarclient.git} | 
|  | 55 | ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master} | 
|  | 56 |  | 
|  | 57 | # Set Zaqar Connection Info | 
|  | 58 | ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST} | 
|  | 59 | ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888} | 
|  | 60 | ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} | 
|  | 61 |  | 
|  | 62 | # Tell Tempest this project is present | 
|  | 63 | TEMPEST_SERVICES+=,zaqar | 
|  | 64 |  | 
|  | 65 |  | 
|  | 66 | # Functions | 
|  | 67 | # --------- | 
|  | 68 |  | 
|  | 69 | # Test if any Zaqar services are enabled | 
|  | 70 | # is_zaqar_enabled | 
|  | 71 | function is_zaqar_enabled { | 
|  | 72 | [[ ,${ENABLED_SERVICES} =~ ,"zaqar-" ]] && return 0 | 
|  | 73 | return 1 | 
|  | 74 | } | 
|  | 75 |  | 
| Flavio Percoco | dec13c3 | 2014-09-08 09:48:27 +0200 | [diff] [blame] | 76 | # cleanup_zaqar() - Cleans up general things from previous | 
|  | 77 | # runs and storage specific left overs. | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 78 | function cleanup_zaqar { | 
| Flavio Percoco | dec13c3 | 2014-09-08 09:48:27 +0200 | [diff] [blame] | 79 | 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 | 
|  | 86 | function cleanup_zaqar_mongodb { | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 87 | 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 | 
|  | 100 | function configure_zaqarclient { | 
|  | 101 | setup_develop $ZAQARCLIENT_DIR | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | # configure_zaqar() - Set config files, create data dirs, etc | 
|  | 105 | function 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 |  | 
| Victoria Martinez de la Cruz | 5bef3e1 | 2014-12-04 10:24:37 -0300 | [diff] [blame] | 111 | iniset $ZAQAR_CONF DEFAULT debug True | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 112 | iniset $ZAQAR_CONF DEFAULT verbose True | 
| Flavio Percoco | b64738f | 2014-11-24 16:44:50 +0100 | [diff] [blame] | 113 | iniset $ZAQAR_CONF DEFAULT admin_mode True | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 114 | iniset $ZAQAR_CONF DEFAULT use_syslog $SYSLOG | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 115 | iniset $ZAQAR_CONF 'drivers:transport:wsgi' bind $ZAQAR_SERVICE_HOST | 
|  | 116 |  | 
| Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 117 | configure_auth_token_middleware $ZAQAR_CONF zaqar $ZAQAR_AUTH_CACHE_DIR | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 118 |  | 
|  | 119 | if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then | 
|  | 120 | iniset $ZAQAR_CONF drivers storage sqlalchemy | 
|  | 121 | iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar` | 
|  | 122 | elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then | 
|  | 123 | iniset $ZAQAR_CONF  drivers storage mongodb | 
|  | 124 | iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar | 
|  | 125 | configure_mongodb | 
| Flavio Percoco | e29a55a | 2014-09-05 16:03:01 +0200 | [diff] [blame] | 126 | elif [ "$ZAQAR_BACKEND" = 'redis' ] ; then | 
|  | 127 | iniset $ZAQAR_CONF  drivers storage redis | 
|  | 128 | iniset $ZAQAR_CONF 'drivers:storage:redis' uri redis://localhost:6379 | 
|  | 129 | configure_redis | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 130 | fi | 
| Flavio Percoco | dec13c3 | 2014-09-08 09:48:27 +0200 | [diff] [blame] | 131 |  | 
| Zhi Yan Liu | 0f52d93 | 2014-12-30 14:37:02 +0800 | [diff] [blame] | 132 | if is_service_enabled qpid || [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then | 
|  | 133 | iniset $ZAQAR_CONF DEFAULT notification_driver messaging | 
|  | 134 | iniset $ZAQAR_CONF DEFAULT control_exchange zaqar | 
|  | 135 | fi | 
| Brant Knudson | 2dd110c | 2015-03-14 12:39:14 -0500 | [diff] [blame^] | 136 | iniset_rpc_backend zaqar $ZAQAR_CONF | 
| Zhi Yan Liu | 0f52d93 | 2014-12-30 14:37:02 +0800 | [diff] [blame] | 137 |  | 
| Flavio Percoco | dec13c3 | 2014-09-08 09:48:27 +0200 | [diff] [blame] | 138 | cleanup_zaqar | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 139 | } | 
|  | 140 |  | 
| Flavio Percoco | e29a55a | 2014-09-05 16:03:01 +0200 | [diff] [blame] | 141 | function configure_redis { | 
|  | 142 | if is_ubuntu; then | 
|  | 143 | install_package redis-server | 
| Flavio Percoco | b592454 | 2015-02-20 13:51:22 +0100 | [diff] [blame] | 144 | pip_install redis | 
| Flavio Percoco | e29a55a | 2014-09-05 16:03:01 +0200 | [diff] [blame] | 145 | elif is_fedora; then | 
|  | 146 | install_package redis | 
| Flavio Percoco | b592454 | 2015-02-20 13:51:22 +0100 | [diff] [blame] | 147 | pip_install redis | 
| Flavio Percoco | e29a55a | 2014-09-05 16:03:01 +0200 | [diff] [blame] | 148 | else | 
|  | 149 | exit_distro_not_supported "redis installation" | 
|  | 150 | fi | 
| Flavio Percoco | e29a55a | 2014-09-05 16:03:01 +0200 | [diff] [blame] | 151 | } | 
|  | 152 |  | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 153 | function 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. | 
|  | 169 | function 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 | 
|  | 177 | function 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 | 
|  | 183 | function 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 | 
|  | 189 | function start_zaqar { | 
|  | 190 | if [[ "$USE_SCREEN" = "False" ]]; then | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 191 | run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon" | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 192 | else | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 193 | run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF" | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 194 | 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 | 
|  | 203 | function stop_zaqar { | 
| Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 204 | local serv | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 205 | # 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 |  | 
|  | 211 | function create_zaqar_accounts { | 
| Jamie Lennox | e8bc2b8 | 2015-02-10 20:38:56 +1100 | [diff] [blame] | 212 | create_service_user "zaqar" | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 213 |  | 
|  | 214 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 215 |  | 
| Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 216 | local zaqar_service=$(get_or_create_service "zaqar" \ | 
| Victoria MartÃnez de la Cruz | f080e89 | 2014-09-19 19:07:10 -0300 | [diff] [blame] | 217 | "messaging" "Zaqar Service") | 
| Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 218 | get_or_create_endpoint $zaqar_service \ | 
| Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 219 | "$REGION_NAME" \ | 
|  | 220 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ | 
|  | 221 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ | 
|  | 222 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" | 
|  | 223 | fi | 
|  | 224 |  | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 |  | 
|  | 228 | # Restore xtrace | 
|  | 229 | $XTRACE | 
|  | 230 |  | 
|  | 231 | # Local variables: | 
|  | 232 | # mode: shell-script | 
|  | 233 | # End: |