Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 1 | # 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 |
| 25 | XTRACE=$(set +o | grep xtrace) |
| 26 | set +o xtrace |
| 27 | |
| 28 | |
| 29 | # Defaults |
| 30 | # -------- |
| 31 | |
| 32 | # Set up default directories |
| 33 | ZAQAR_DIR=$DEST/zaqar |
| 34 | ZAQARCLIENT_DIR=$DEST/python-zaqarclient |
| 35 | ZAQAR_CONF_DIR=/etc/zaqar |
| 36 | ZAQAR_CONF=$ZAQAR_CONF_DIR/zaqar.conf |
| 37 | ZAQAR_API_LOG_DIR=/var/log/zaqar |
| 38 | ZAQAR_API_LOG_FILE=$ZAQAR_API_LOG_DIR/queues.log |
| 39 | ZAQAR_AUTH_CACHE_DIR=${ZAQAR_AUTH_CACHE_DIR:-/var/cache/zaqar} |
| 40 | |
| 41 | # Support potential entry-points console scripts |
| 42 | ZAQAR_BIN_DIR=$(get_python_exec_prefix) |
| 43 | |
| 44 | # Set up database backend |
| 45 | ZAQAR_BACKEND=${ZAQAR_BACKEND:-mongodb} |
| 46 | |
| 47 | |
| 48 | # Set Zaqar repository |
| 49 | ZAQAR_REPO=${ZAQAR_REPO:-${GIT_BASE}/openstack/zaqar.git} |
| 50 | ZAQAR_BRANCH=${ZAQAR_BRANCH:-master} |
| 51 | |
| 52 | # Set client library repository |
| 53 | ZAQARCLIENT_REPO=${ZAQARCLIENT_REPO:-${GIT_BASE}/openstack/python-zaqarclient.git} |
| 54 | ZAQARCLIENT_BRANCH=${ZAQARCLIENT_BRANCH:-master} |
| 55 | |
| 56 | # Set Zaqar Connection Info |
| 57 | ZAQAR_SERVICE_HOST=${ZAQAR_SERVICE_HOST:-$SERVICE_HOST} |
| 58 | ZAQAR_SERVICE_PORT=${ZAQAR_SERVICE_PORT:-8888} |
| 59 | ZAQAR_SERVICE_PROTOCOL=${ZAQAR_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 60 | |
| 61 | # Tell Tempest this project is present |
| 62 | TEMPEST_SERVICES+=,zaqar |
| 63 | |
| 64 | |
| 65 | # Functions |
| 66 | # --------- |
| 67 | |
| 68 | # Test if any Zaqar services are enabled |
| 69 | # is_zaqar_enabled |
| 70 | function 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 |
| 77 | function 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 |
| 91 | function configure_zaqarclient { |
| 92 | setup_develop $ZAQARCLIENT_DIR |
| 93 | } |
| 94 | |
| 95 | # configure_zaqar() - Set config files, create data dirs, etc |
| 96 | function 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 | |
| 110 | iniset $ZAQAR_CONF keystone_authtoken auth_protocol http |
| 111 | iniset $ZAQAR_CONF keystone_authtoken admin_user zaqar |
| 112 | iniset $ZAQAR_CONF keystone_authtoken admin_password $SERVICE_PASSWORD |
| 113 | iniset $ZAQAR_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 114 | iniset $ZAQAR_CONF keystone_authtoken signing_dir $ZAQAR_AUTH_CACHE_DIR |
| 115 | |
| 116 | if [ "$ZAQAR_BACKEND" = 'mysql' ] || [ "$ZAQAR_BACKEND" = 'postgresql' ] ; then |
| 117 | iniset $ZAQAR_CONF drivers storage sqlalchemy |
| 118 | iniset $ZAQAR_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url zaqar` |
| 119 | elif [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then |
| 120 | iniset $ZAQAR_CONF drivers storage mongodb |
| 121 | iniset $ZAQAR_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/zaqar |
| 122 | configure_mongodb |
| 123 | cleanup_zaqar |
| 124 | fi |
| 125 | } |
| 126 | |
| 127 | function configure_mongodb { |
| 128 | # Set nssize to 2GB. This increases the number of namespaces supported |
| 129 | # # per database. |
| 130 | if is_ubuntu; then |
| 131 | sudo sed -i -e " |
| 132 | s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1| |
| 133 | s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047| |
| 134 | " /etc/mongodb.conf |
| 135 | restart_service mongodb |
| 136 | elif is_fedora; then |
| 137 | sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod |
| 138 | restart_service mongod |
| 139 | fi |
| 140 | } |
| 141 | |
| 142 | # init_zaqar() - Initialize etc. |
| 143 | function init_zaqar { |
| 144 | # Create cache dir |
| 145 | sudo mkdir -p $ZAQAR_AUTH_CACHE_DIR |
| 146 | sudo chown $STACK_USER $ZAQAR_AUTH_CACHE_DIR |
| 147 | rm -f $ZAQAR_AUTH_CACHE_DIR/* |
| 148 | } |
| 149 | |
| 150 | # install_zaqar() - Collect source and prepare |
| 151 | function install_zaqar { |
| 152 | git_clone $ZAQAR_REPO $ZAQAR_DIR $ZAQAR_BRANCH |
| 153 | setup_develop $ZAQAR_DIR |
| 154 | } |
| 155 | |
| 156 | # install_zaqarclient() - Collect source and prepare |
| 157 | function install_zaqarclient { |
| 158 | git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH |
| 159 | setup_develop $ZAQARCLIENT_DIR |
| 160 | } |
| 161 | |
| 162 | # start_zaqar() - Start running processes, including screen |
| 163 | function start_zaqar { |
| 164 | if [[ "$USE_SCREEN" = "False" ]]; then |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 165 | run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF --daemon" |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 166 | else |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 167 | run_process zaqar-server "zaqar-server --config-file $ZAQAR_CONF" |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 168 | fi |
| 169 | |
| 170 | echo "Waiting for Zaqar to start..." |
| 171 | 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 |
| 172 | die $LINENO "Zaqar did not start" |
| 173 | fi |
| 174 | } |
| 175 | |
| 176 | # stop_zaqar() - Stop running processes |
| 177 | function stop_zaqar { |
Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 178 | local serv |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 179 | # Kill the zaqar screen windows |
| 180 | for serv in zaqar-server; do |
| 181 | screen -S $SCREEN_NAME -p $serv -X kill |
| 182 | done |
| 183 | } |
| 184 | |
| 185 | function create_zaqar_accounts { |
Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 186 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 187 | ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") |
| 188 | |
Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 189 | local zaqar_user=$(get_or_create_user "zaqar" \ |
| 190 | "$SERVICE_PASSWORD" $service_tenant) |
| 191 | get_or_add_user_role $ADMIN_ROLE $zaqar_user $service_tenant |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 192 | |
| 193 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
| 194 | |
Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 195 | local zaqar_service=$(get_or_create_service "zaqar" \ |
Victoria MartÃnez de la Cruz | f080e89 | 2014-09-19 19:07:10 -0300 | [diff] [blame^] | 196 | "messaging" "Zaqar Service") |
Dean Troyer | 6430919 | 2014-08-19 22:17:50 -0500 | [diff] [blame] | 197 | get_or_create_endpoint $zaqar_service \ |
Malini Kamalambal | 9504bb3 | 2014-08-01 17:41:08 -0400 | [diff] [blame] | 198 | "$REGION_NAME" \ |
| 199 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ |
| 200 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" \ |
| 201 | "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_SERVICE_PORT" |
| 202 | fi |
| 203 | |
| 204 | } |
| 205 | |
| 206 | |
| 207 | # Restore xtrace |
| 208 | $XTRACE |
| 209 | |
| 210 | # Local variables: |
| 211 | # mode: shell-script |
| 212 | # End: |