File: plugin.sh

package info (click to toggle)
zaqar 21.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,964 kB
  • sloc: python: 28,819; sh: 513; java: 135; makefile: 63; javascript: 50
file content (333 lines) | stat: -rwxr-xr-x 11,931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/bin/bash
#
# lib/zaqar
# Install and start **Zaqar** service

# To enable a minimal set of Zaqar services, add the following to localrc:
#
#     enable_service zaqar-websocket zaqar-wsgi
#
# Dependencies:
# - functions
# - OS_AUTH_URL for auth in api
# - DEST set to the destination directory
# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
# - STACK_USER service user

# stack.sh
# ---------
# install_zaqar
# install_zaqarui
# configure_zaqar
# init_zaqar
# start_zaqar
# stop_zaqar
# cleanup_zaqar
# cleanup_zaqar_mongodb

# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace

# Functions
# ---------

# Test if any Zaqar services are enabled
# is_zaqar_enabled
function is_zaqar_enabled {
    [[ ,${ENABLED_SERVICES} =~ ,"zaqar" ]] && return 0
    return 1
}

# cleanup_zaqar() - Cleans up general things from previous
# runs and storage specific left overs.
function cleanup_zaqar {
    if [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
        cleanup_zaqar_mongodb
    fi
    remove_uwsgi_config "$ZAQAR_UWSGI_CONF" "zaqar"
}

# cleanup_zaqar_mongodb() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
# After mongodb 6.0, the mongo shell has been remove, now using mongosh.
function cleanup_zaqar_mongodb {
    if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongosh zaqar --eval 'db.dropDatabase();'; do sleep 1; done"; then
        die $LINENO "Mongo DB did not start"
    else
        mongo_version=$(mongosh zaqar --eval 'db.version();')
        required_mongo_version='6.0'
        if [[ $mongo_version < $required_mongo_version ]]; then
            die $LINENO "Zaqar needs Mongo DB version >= 6.0 to run."
        fi
    fi
}

# configure_zaqarclient() - Set config files, create data dirs, etc
function configure_zaqarclient {
    setup_develop $ZAQARCLIENT_DIR
}

# configure_zaqar() - Set config files, create data dirs, etc
function configure_zaqar {
    setup_develop $ZAQAR_DIR

    [ ! -d $ZAQAR_CONF_DIR ] && sudo mkdir -m 755 -p $ZAQAR_CONF_DIR
    sudo chown $USER $ZAQAR_CONF_DIR

    [ ! -d $ZAQAR_API_LOG_DIR ] && sudo mkdir -m 755 -p $ZAQAR_API_LOG_DIR
    sudo chown $USER $ZAQAR_API_LOG_DIR

    iniset $ZAQAR_CONF DEFAULT debug True
    iniset $ZAQAR_CONF DEFAULT unreliable True
    iniset $ZAQAR_CONF DEFAULT admin_mode True
    iniset $ZAQAR_CONF DEFAULT enable_deprecated_api_versions 1.1
    iniset $ZAQAR_CONF signed_url secret_key notreallysecret

    if is_service_enabled key; then
        iniset $ZAQAR_CONF DEFAULT auth_strategy keystone
    fi

    iniset $ZAQAR_CONF storage message_pipeline zaqar.notification.notifier

    # Enable pooling by default for now
    iniset $ZAQAR_CONF DEFAULT admin_mode True
    iniset $ZAQAR_CONF 'drivers:transport:websocket' bind $(ipv6_unquote $ZAQAR_SERVICE_HOST)
    iniset $ZAQAR_CONF 'drivers:transport:websocket' port $ZAQAR_WEBSOCKET_PORT
    iniset $ZAQAR_CONF drivers transport websocket

    configure_keystone_authtoken_middleware $ZAQAR_CONF zaqar

    iniset $ZAQAR_CONF trustee auth_type password
    iniset $ZAQAR_CONF trustee auth_url $KEYSTONE_AUTH_URI
    iniset $ZAQAR_CONF trustee username $ZAQAR_TRUSTEE_USER
    iniset $ZAQAR_CONF trustee password $ZAQAR_TRUSTEE_PASSWORD
    iniset $ZAQAR_CONF trustee user_domain_id $ZAQAR_TRUSTEE_DOMAIN

    iniset $ZAQAR_CONF DEFAULT pooling True
    iniset $ZAQAR_CONF 'pooling:catalog' enable_virtual_pool True

    if [ "$ZAQAR_BACKEND" = 'mongodb' ] ; then
        iniset $ZAQAR_CONF  drivers message_store mongodb
        iniset $ZAQAR_CONF 'drivers:message_store:mongodb' uri mongodb://localhost:27017/zaqar
        iniset $ZAQAR_CONF 'drivers:message_store:mongodb' database zaqar

        iniset $ZAQAR_CONF  drivers management_store mongodb
        iniset $ZAQAR_CONF 'drivers:management_store:mongodb' uri mongodb://localhost:27017/zaqar_mgmt
        iniset $ZAQAR_CONF 'drivers:management_store:mongodb' database zaqar_mgmt
        configure_mongodb
    elif [ "$ZAQAR_BACKEND" = 'redis' ] ; then
        recreate_database zaqar
        iniset $ZAQAR_CONF  drivers management_store sqlalchemy
        iniset $ZAQAR_CONF 'drivers:management_store:sqlalchemy' uri `database_connection_url zaqar`
        iniset $ZAQAR_CONF 'drivers:management_store:sqlalchemy' database zaqar_mgmt

        $ZAQAR_BIN_DIR/zaqar-sql-db-manage --config-file $ZAQAR_CONF upgrade head

        iniset $ZAQAR_CONF  drivers message_store redis
        iniset $ZAQAR_CONF 'drivers:message_store:redis' uri redis://localhost:6379
        iniset $ZAQAR_CONF 'drivers:message_store:redis' database zaqar
        configure_redis
    elif [ "$ZAQAR_BACKEND" = 'swift' ] ; then
        recreate_database zaqar
        iniset $ZAQAR_CONF  drivers management_store sqlalchemy
        iniset $ZAQAR_CONF 'drivers:management_store:sqlalchemy' uri `database_connection_url zaqar`
        iniset $ZAQAR_CONF 'drivers:management_store:sqlalchemy' database zaqar_mgmt

        $ZAQAR_BIN_DIR/zaqar-sql-db-manage --config-file $ZAQAR_CONF upgrade head

        iniset $ZAQAR_CONF  drivers message_store swift
        iniset $ZAQAR_CONF 'drivers:message_store:swift' auth_url $KEYSTONE_AUTH_URI
        iniset $ZAQAR_CONF 'drivers:message_store:swift' uri swift://zaqar:$SERVICE_PASSWORD@/service
    fi

    if is_service_enabled qpid || [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
        iniset $ZAQAR_CONF DEFAULT notification_driver messaging
        iniset $ZAQAR_CONF DEFAULT control_exchange zaqar
    fi
    iniset_rpc_backend zaqar $ZAQAR_CONF DEFAULT

    write_uwsgi_config "$ZAQAR_UWSGI_CONF" "$ZAQAR_UWSGI" "/messaging" "" "zaqar"
}

function configure_redis {
    if is_ubuntu; then
        install_package redis-server
        pip_install redis
    elif is_fedora; then
        install_package redis
        pip_install redis
    else
        exit_distro_not_supported "redis installation"
    fi
}

function configure_mongodb {
    # Set nssize to 2GB. This increases the number of namespaces supported
    # per database.
    pip_install pymongo
    if is_ubuntu; then
        # NOTE: To fix the mongodb's issue in ubuntu 22.04/24.04 LTS
        ubuntu_version=$(source /etc/os-release ; echo $VERSION_ID)
        if [[ $ubuntu_version == '24.04' ]]; then
            if [[ ! -d /etc/apt/sources.list.d ]]; then
                sudo mkdir -p /etc/apt/sources.list.d
            fi
            wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo apt-key add -
            echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
            sudo apt update
            install_package mongodb-org
            restart_service mongod
            sudo systemctl status mongod
        elif [[ $ubuntu_version == '22.04' ]]; then
            wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
            echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
            sudo apt update
            install_package mongodb-org
            restart_service mongod
            sudo systemctl status mongod
        else
            install_package mongodb-server
            restart_service mongodb
        fi
    elif is_fedora; then
        fedora_version=$(source /etc/os-release ; echo $VERSION_ID)
        if [[ $fedora_version == '9' ]]; then
            cat > /etc/yum.repos.d/mongodb-org-6.0.repo << __EOF__
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
__EOF__
            install_package mongodb-org
            restart_service mongod
        else
            install_package mongodb
            install_package mongodb-server
            restart_service mongod
        fi
    fi
}

# init_zaqar() - Initialize etc.
function init_zaqar {
    # Nothing to do
    :
}

# install_zaqar() - Collect source and prepare
function install_zaqar {
    setup_develop $ZAQAR_DIR

    if is_service_enabled horizon; then
        install_zaqarui
    fi
    pip_install uwsgi
}

function install_zaqarui {
    git_clone $ZAQARUI_REPO $ZAQARUI_DIR $ZAQARUI_BRANCH
    # NOTE(flwang): Workaround for devstack bug: 1540328
    # where devstack install 'test-requirements' but should not do it
    # for zaqar-ui project as it installs Horizon from url.
    # Remove following two 'mv' commands when mentioned bug is fixed.
    mv $ZAQARUI_DIR/test-requirements.txt $ZAQARUI_DIR/_test-requirements.txt
    setup_develop $ZAQARUI_DIR
    mv $ZAQARUI_DIR/_test-requirements.txt $ZAQARUI_DIR/test-requirements.txt
    cp -a $ZAQARUI_DIR/zaqar_ui/enabled/* $HORIZON_DIR/openstack_dashboard/local/enabled/
    if [ -d $ZAQARUI_DIR/zaqar-ui/locale ]; then
        (cd $ZAQARUI_DIR/zaqar-ui; DJANGO_SETTINGS_MODULE=openstack_dashboard.settings ../manage.py compilemessages)
    fi
}

# install_zaqarclient() - Collect source and prepare
function install_zaqarclient {
    git_clone $ZAQARCLIENT_REPO $ZAQARCLIENT_DIR $ZAQARCLIENT_BRANCH
    # NOTE(flaper87): Ideally, this should be developed, but apparently
    # there's a bug in devstack that skips test-requirements when using
    # setup_develop
    setup_install $ZAQARCLIENT_DIR
}

# start_zaqar() - Start running processes, including screen
function start_zaqar {
    run_process zaqar-wsgi "$ZAQAR_BIN_DIR/uwsgi --ini $ZAQAR_UWSGI_CONF"
    run_process zaqar-websocket "$ZAQAR_BIN_DIR/zaqar-server --config-file $ZAQAR_CONF"

    echo "Waiting for Zaqar to start..."
    local www_authenticate_uri=http://${ZAQAR_SERVICE_HOST}/identity
    local ping_url=$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST/messaging/v2/ping
    token=$(openstack token issue -c id -f value --os-auth-url ${www_authenticate_uri})
    if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q --header=\"Client-ID:$(uuidgen)\" --header=\"X-Auth-Token:$token\" -O- $ping_url; do sleep 1; done"; then
        die $LINENO "Zaqar did not start"
    fi
}

# stop_zaqar() - Stop running processes
function stop_zaqar {
    local serv
    # Kill the zaqar screen windows
    for serv in zaqar-wsgi zaqar-websocket; do
        stop_process serv
    done
}

function create_zaqar_accounts {
    create_service_user "zaqar"

    if [[ "$KEYSTONE_IDENTITY_BACKEND" = 'sql' ]]; then

        get_or_create_service "zaqar" "messaging" "Zaqar Service"
        get_or_create_endpoint "messaging" \
            "$REGION_NAME" \
            "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST/messaging"

        get_or_create_service "zaqar-websocket" \
            "messaging-websocket" "Zaqar Websocket Service"
        get_or_create_endpoint "messaging-websocket" \
            "$REGION_NAME" \
            "$ZAQAR_SERVICE_PROTOCOL://$ZAQAR_SERVICE_HOST:$ZAQAR_WEBSOCKET_PORT"
    fi

    if [ "$ZAQAR_BACKEND" = 'swift' ] ; then
        get_or_add_user_project_role ResellerAdmin zaqar service
    fi
}

if is_service_enabled zaqar-websocket || is_service_enabled zaqar-wsgi; then
    if [[ "$1" == "stack" && "$2" == "install" ]]; then
        echo_summary "Installing Zaqar"
        install_zaqarclient
        install_zaqar
    elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
        echo_summary "Configuring Zaqar"
        configure_zaqar
        configure_zaqarclient

        if is_service_enabled key; then
           create_zaqar_accounts
        fi

    elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
        echo_summary "Initializing Zaqar"
        init_zaqar
        start_zaqar
    fi

    if [[ "$1" == "unstack" ]]; then
        stop_zaqar
    fi

    if [[ "$1" == "clean" ]]; then
        cleanup_zaqar
    fi
fi

# Restore xtrace
$XTRACE

# Local variables:
# mode: shell-script
# End: