Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 3 | # lib/rpc_backend |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 4 | # Interface for interactig with different RPC backends |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 5 | |
| 6 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 7 | # |
| 8 | # - ``functions`` file |
Abhishek Chanda | d5b74c6 | 2014-12-12 02:15:55 +0530 | [diff] [blame] | 9 | # - ``RABBIT_{HOST|PASSWORD|USERID}`` must be defined when RabbitMQ is used |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 10 | # - ``RPC_MESSAGING_PROTOCOL`` option for configuring the messaging protocol |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 11 | |
| 12 | # ``stack.sh`` calls the entry points in this order: |
| 13 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 14 | # - check_rpc_backend |
| 15 | # - install_rpc_backend |
| 16 | # - restart_rpc_backend |
| 17 | # - iniset_rpc_backend |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 18 | |
| 19 | # Save trace setting |
| 20 | XTRACE=$(set +o | grep xtrace) |
| 21 | set +o xtrace |
| 22 | |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 23 | RPC_MESSAGING_PROTOCOL=${RPC_MESSAGING_PROTOCOL:-0.9} |
| 24 | |
| 25 | # TODO(sdague): RPC backend selection is super wonky because we treat |
| 26 | # messaging server as a service, which it really isn't for multi host |
| 27 | QPID_HOST=${QPID_HOST:-} |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 28 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 29 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 30 | # Functions |
| 31 | # --------- |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 32 | |
| 33 | # Make sure we only have one rpc backend enabled. |
| 34 | # Also check the specified rpc backend is available on your platform. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 35 | function check_rpc_backend { |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 36 | local c svc |
| 37 | |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 38 | local rpc_needed=1 |
| 39 | # We rely on the fact that filenames in lib/* match the service names |
| 40 | # that can be passed as arguments to is_service_enabled. |
| 41 | # We check for a call to iniset_rpc_backend in these files, meaning |
| 42 | # the service needs a backend. |
Vishvananda Ishaya | 78a53d9 | 2013-05-09 17:20:31 -0700 | [diff] [blame] | 43 | rpc_candidates=$(grep -rl iniset_rpc_backend $TOP_DIR/lib/ | awk -F/ '{print $NF}') |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 44 | for c in ${rpc_candidates}; do |
| 45 | if is_service_enabled $c; then |
| 46 | rpc_needed=0 |
| 47 | break |
| 48 | fi |
| 49 | done |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 50 | local rpc_backend_cnt=0 |
| 51 | for svc in qpid zeromq rabbit; do |
| 52 | is_service_enabled $svc && |
Dean Troyer | ffd1768 | 2014-08-02 16:07:03 -0500 | [diff] [blame] | 53 | (( rpc_backend_cnt++ )) || true |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 54 | done |
| 55 | if [ "$rpc_backend_cnt" -gt 1 ]; then |
| 56 | echo "ERROR: only one rpc backend may be enabled," |
| 57 | echo " set only one of 'rabbit', 'qpid', 'zeromq'" |
| 58 | echo " via ENABLED_SERVICES." |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 59 | elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 60 | echo "ERROR: at least one rpc backend must be enabled," |
| 61 | echo " set one of 'rabbit', 'qpid', 'zeromq'" |
| 62 | echo " via ENABLED_SERVICES." |
| 63 | fi |
| 64 | |
| 65 | if is_service_enabled qpid && ! qpid_is_supported; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 66 | die $LINENO "Qpid support is not available for this version of your distribution." |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 67 | fi |
| 68 | } |
| 69 | |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 70 | # clean up after rpc backend - eradicate all traces so changing backends |
| 71 | # produces a clean switch |
| 72 | function cleanup_rpc_backend { |
| 73 | if is_service_enabled rabbit; then |
| 74 | # Obliterate rabbitmq-server |
| 75 | uninstall_package rabbitmq-server |
Sean Dague | 9a413ab | 2015-02-04 12:44:18 -0500 | [diff] [blame] | 76 | # in case it's not actually running, /bin/true at the end |
| 77 | sudo killall epmd || sudo killall -9 epmd || /bin/true |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 78 | if is_ubuntu; then |
| 79 | # And the Erlang runtime too |
Sahid Orentino Ferdjaoui | e964827 | 2014-02-23 18:55:51 +0100 | [diff] [blame] | 80 | apt_get purge -y erlang* |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 81 | fi |
| 82 | elif is_service_enabled qpid; then |
| 83 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 84 | uninstall_package qpid-cpp-server |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 85 | elif is_ubuntu; then |
| 86 | uninstall_package qpidd |
| 87 | else |
| 88 | exit_distro_not_supported "qpid installation" |
| 89 | fi |
| 90 | elif is_service_enabled zeromq; then |
| 91 | if is_fedora; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 92 | uninstall_package zeromq python-zmq |
| 93 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 94 | uninstall_package redis python-redis |
| 95 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 96 | elif is_ubuntu; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 97 | uninstall_package libzmq1 python-zmq |
| 98 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 99 | uninstall_package redis-server python-redis |
| 100 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 101 | elif is_suse; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 102 | uninstall_package libzmq1 python-pyzmq |
| 103 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 104 | uninstall_package redis python-redis |
| 105 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 106 | else |
| 107 | exit_distro_not_supported "zeromq installation" |
| 108 | fi |
| 109 | fi |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 110 | |
| 111 | # Remove the AMQP 1.0 messaging libraries |
| 112 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 113 | if is_fedora; then |
| 114 | uninstall_package qpid-proton-c-devel |
| 115 | uninstall_package python-qpid-proton |
| 116 | fi |
| 117 | # TODO(kgiusti) ubuntu cleanup |
| 118 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 121 | # install rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 122 | function install_rpc_backend { |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 123 | # Regardless of the broker used, if AMQP 1.0 is configured load |
| 124 | # the necessary messaging client libraries for oslo.messaging |
| 125 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 126 | if is_fedora; then |
| 127 | install_package qpid-proton-c-devel |
| 128 | install_package python-qpid-proton |
| 129 | elif is_ubuntu; then |
| 130 | # TODO(kgiusti) The QPID AMQP 1.0 protocol libraries |
| 131 | # are not yet in the ubuntu repos. Enable these installs |
| 132 | # once they are present: |
| 133 | #install_package libqpid-proton2-dev |
| 134 | #install_package python-qpid-proton |
| 135 | # Also add 'uninstall' directives in cleanup_rpc_backend()! |
| 136 | exit_distro_not_supported "QPID AMQP 1.0 Proton libraries" |
| 137 | else |
| 138 | exit_distro_not_supported "QPID AMQP 1.0 Proton libraries" |
| 139 | fi |
| 140 | # Install pyngus client API |
| 141 | # TODO(kgiusti) can remove once python qpid bindings are |
| 142 | # available on all supported platforms _and_ pyngus is added |
| 143 | # to the requirements.txt file in oslo.messaging |
Sean Dague | 60996b1 | 2015-04-08 09:06:49 -0400 | [diff] [blame] | 144 | pip_install_gr pyngus |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 145 | fi |
| 146 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 147 | if is_service_enabled rabbit; then |
| 148 | # Install rabbitmq-server |
Ian Wienand | 7ccf4e0 | 2014-07-23 14:24:11 +1000 | [diff] [blame] | 149 | install_package rabbitmq-server |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 150 | elif is_service_enabled qpid; then |
| 151 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 152 | install_package qpid-cpp-server |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 153 | elif is_ubuntu; then |
| 154 | install_package qpidd |
| 155 | else |
| 156 | exit_distro_not_supported "qpid installation" |
| 157 | fi |
Kenneth Giusti | 062a3c3 | 2014-09-30 10:14:08 -0400 | [diff] [blame] | 158 | _configure_qpid |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 159 | elif is_service_enabled zeromq; then |
| 160 | if is_fedora; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 161 | install_package zeromq python-zmq |
| 162 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 163 | install_package redis python-redis |
| 164 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 165 | elif is_ubuntu; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 166 | install_package libzmq1 python-zmq |
| 167 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 168 | install_package redis-server python-redis |
| 169 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 170 | elif is_suse; then |
Li Ma | d3ca141 | 2014-12-21 23:36:43 -0800 | [diff] [blame] | 171 | install_package libzmq1 python-pyzmq |
| 172 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
| 173 | install_package redis python-redis |
| 174 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 175 | else |
| 176 | exit_distro_not_supported "zeromq installation" |
| 177 | fi |
Vincent Hou | 93a7a50 | 2013-09-27 06:16:54 -0400 | [diff] [blame] | 178 | # Necessary directory for socket location. |
| 179 | sudo mkdir -p /var/run/openstack |
| 180 | sudo chown $STACK_USER /var/run/openstack |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 181 | fi |
Kenneth Giusti | a1875b7 | 2014-09-15 14:21:55 -0400 | [diff] [blame] | 182 | |
| 183 | # If using the QPID broker, install the QPID python client API |
| 184 | if is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
| 185 | install_package python-qpid |
| 186 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | # restart the rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 190 | function restart_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 191 | if is_service_enabled rabbit; then |
| 192 | # Start rabbitmq-server |
| 193 | echo_summary "Starting RabbitMQ" |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 194 | # NOTE(bnemec): Retry initial rabbitmq configuration to deal with |
| 195 | # the fact that sometimes it fails to start properly. |
Ian Wienand | 64b56a5 | 2014-12-16 09:53:36 +1100 | [diff] [blame] | 196 | # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1144100 |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 197 | local i |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 198 | for i in `seq 10`; do |
Ian Wienand | 64b56a5 | 2014-12-16 09:53:36 +1100 | [diff] [blame] | 199 | local rc=0 |
| 200 | |
| 201 | [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password" |
| 202 | |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 203 | if is_fedora || is_suse; then |
| 204 | # service is not started by default |
| 205 | restart_service rabbitmq-server |
| 206 | fi |
Ian Wienand | 64b56a5 | 2014-12-16 09:53:36 +1100 | [diff] [blame] | 207 | |
| 208 | rabbit_setuser "$RABBIT_USERID" "$RABBIT_PASSWORD" || rc=$? |
| 209 | if [ $rc -ne 0 ]; then |
| 210 | continue |
| 211 | fi |
| 212 | |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 213 | # change the rabbit password since the default is "guest" |
Ian Wienand | 64b56a5 | 2014-12-16 09:53:36 +1100 | [diff] [blame] | 214 | sudo rabbitmqctl change_password \ |
| 215 | $RABBIT_USERID $RABBIT_PASSWORD || rc=$? |
| 216 | if [ $rc -ne 0 ]; then |
| 217 | continue; |
| 218 | fi |
| 219 | |
| 220 | break |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 221 | done |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 222 | if is_service_enabled n-cell; then |
| 223 | # Add partitioned access for the child cell |
| 224 | if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then |
| 225 | sudo rabbitmqctl add_vhost child_cell |
Abhishek Chanda | d5b74c6 | 2014-12-12 02:15:55 +0530 | [diff] [blame] | 226 | sudo rabbitmqctl set_permissions -p child_cell $RABBIT_USERID ".*" ".*" ".*" |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 227 | fi |
| 228 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 229 | elif is_service_enabled qpid; then |
| 230 | echo_summary "Starting qpid" |
| 231 | restart_service qpidd |
| 232 | fi |
| 233 | } |
| 234 | |
gordon chung | b6197e6 | 2015-02-12 15:33:35 -0500 | [diff] [blame] | 235 | # builds transport url string |
| 236 | function get_transport_url { |
| 237 | if is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
| 238 | echo "qpid://$QPID_USERNAME:$QPID_PASSWORD@$QPID_HOST:5672/" |
| 239 | elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then |
| 240 | echo "rabbit://$RABBIT_USERID:$RABBIT_PASSWORD@$RABBIT_HOST:5672/" |
| 241 | fi |
| 242 | } |
| 243 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 244 | # iniset cofiguration |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 245 | function iniset_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 246 | local package=$1 |
| 247 | local file=$2 |
Brant Knudson | 2dd110c | 2015-03-14 12:39:14 -0500 | [diff] [blame] | 248 | local section=${3:-DEFAULT} |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 249 | if is_service_enabled zeromq; then |
Li Ma | ce1524d | 2014-12-21 00:46:34 -0800 | [diff] [blame] | 250 | iniset $file $section rpc_backend "zmq" |
Li Ma | c24b399 | 2014-12-21 23:51:40 -0800 | [diff] [blame] | 251 | iniset $file $section rpc_zmq_host `hostname` |
| 252 | if [ "$ZEROMQ_MATCHMAKER" == "redis" ]; then |
Li Ma | 0f20ad4 | 2015-03-23 23:05:15 -0700 | [diff] [blame] | 253 | iniset $file $section rpc_zmq_matchmaker "redis" |
Li Ma | c24b399 | 2014-12-21 23:51:40 -0800 | [diff] [blame] | 254 | MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1} |
| 255 | iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST |
| 256 | else |
| 257 | die $LINENO "Other matchmaker drivers not supported" |
| 258 | fi |
Jason Dillaman | 056df82 | 2013-07-01 08:52:13 -0400 | [diff] [blame] | 259 | elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 260 | # For Qpid use the 'amqp' oslo.messaging transport when AMQP 1.0 is used |
| 261 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 262 | iniset $file $section rpc_backend "amqp" |
| 263 | else |
Li Ma | 529f811 | 2015-01-23 03:10:49 -0800 | [diff] [blame] | 264 | iniset $file $section rpc_backend "qpid" |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 265 | fi |
Attila Fazekas | a3dc399 | 2013-07-11 11:26:35 +0200 | [diff] [blame] | 266 | iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST} |
Kenneth Giusti | 062a3c3 | 2014-09-30 10:14:08 -0400 | [diff] [blame] | 267 | if [ -n "$QPID_USERNAME" ]; then |
| 268 | iniset $file $section qpid_username $QPID_USERNAME |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 269 | iniset $file $section qpid_password $QPID_PASSWORD |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 270 | fi |
jiajun xu | 4a30b84 | 2013-01-22 11:49:03 +0800 | [diff] [blame] | 271 | elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then |
Li Ma | 529f811 | 2015-01-23 03:10:49 -0800 | [diff] [blame] | 272 | iniset $file $section rpc_backend "rabbit" |
Joe Gordon | d01ff96 | 2015-03-23 15:05:39 -0700 | [diff] [blame] | 273 | iniset $file oslo_messaging_rabbit rabbit_hosts $RABBIT_HOST |
| 274 | iniset $file oslo_messaging_rabbit rabbit_password $RABBIT_PASSWORD |
| 275 | iniset $file oslo_messaging_rabbit rabbit_userid $RABBIT_USERID |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 276 | fi |
| 277 | } |
| 278 | |
| 279 | # Check if qpid can be used on the current distro. |
| 280 | # qpid_is_supported |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 281 | function qpid_is_supported { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 282 | if [[ -z "$DISTRO" ]]; then |
| 283 | GetDistro |
| 284 | fi |
| 285 | |
Sean Dague | 2bb483d | 2014-01-03 09:41:27 -0500 | [diff] [blame] | 286 | # Qpid is not in openSUSE |
| 287 | ( ! is_suse ) |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 288 | } |
| 289 | |
Abhishek Chanda | d5b74c6 | 2014-12-12 02:15:55 +0530 | [diff] [blame] | 290 | function rabbit_setuser { |
| 291 | local user="$1" pass="$2" found="" out="" |
| 292 | out=$(sudo rabbitmqctl list_users) || |
| 293 | { echo "failed to list users" 1>&2; return 1; } |
| 294 | found=$(echo "$out" | awk '$1 == user { print $1 }' "user=$user") |
| 295 | if [ "$found" = "$user" ]; then |
| 296 | sudo rabbitmqctl change_password "$user" "$pass" || |
| 297 | { echo "failed changing pass for '$user'" 1>&2; return 1; } |
| 298 | else |
| 299 | sudo rabbitmqctl add_user "$user" "$pass" || |
| 300 | { echo "failed changing pass for $user"; return 1; } |
| 301 | fi |
| 302 | sudo rabbitmqctl set_permissions "$user" ".*" ".*" ".*" |
| 303 | } |
| 304 | |
Kenneth Giusti | 062a3c3 | 2014-09-30 10:14:08 -0400 | [diff] [blame] | 305 | # Set up the various configuration files used by the qpidd broker |
| 306 | function _configure_qpid { |
| 307 | |
| 308 | # the location of the configuration files have changed since qpidd 0.14 |
| 309 | local qpid_conf_file |
| 310 | if [ -e /etc/qpid/qpidd.conf ]; then |
| 311 | qpid_conf_file=/etc/qpid/qpidd.conf |
| 312 | elif [ -e /etc/qpidd.conf ]; then |
| 313 | qpid_conf_file=/etc/qpidd.conf |
| 314 | else |
| 315 | exit_distro_not_supported "qpidd.conf file not found!" |
| 316 | fi |
| 317 | |
| 318 | # force the ACL file to a known location |
| 319 | local qpid_acl_file=/etc/qpid/qpidd.acl |
| 320 | if [ ! -e $qpid_acl_file ]; then |
| 321 | sudo mkdir -p -m 755 `dirname $qpid_acl_file` |
| 322 | sudo touch $qpid_acl_file |
| 323 | sudo chmod o+r $qpid_acl_file |
| 324 | fi |
| 325 | sudo sed -i.bak '/^acl-file=/d' $qpid_conf_file |
| 326 | echo "acl-file=$qpid_acl_file" | sudo tee --append $qpid_conf_file |
| 327 | |
| 328 | sudo sed -i '/^auth=/d' $qpid_conf_file |
| 329 | if [ -z "$QPID_USERNAME" ]; then |
| 330 | # no QPID user configured, so disable authentication |
| 331 | # and access control |
| 332 | echo "auth=no" | sudo tee --append $qpid_conf_file |
| 333 | cat <<EOF | sudo tee $qpid_acl_file |
| 334 | acl allow all all |
| 335 | EOF |
| 336 | else |
| 337 | # Configure qpidd to use PLAIN authentication, and add |
| 338 | # QPID_USERNAME to the ACL: |
| 339 | echo "auth=yes" | sudo tee --append $qpid_conf_file |
| 340 | if [ -z "$QPID_PASSWORD" ]; then |
| 341 | read_password QPID_PASSWORD "ENTER A PASSWORD FOR QPID USER $QPID_USERNAME" |
| 342 | fi |
| 343 | # Create ACL to allow $QPID_USERNAME full access |
| 344 | cat <<EOF | sudo tee $qpid_acl_file |
| 345 | group admin ${QPID_USERNAME}@QPID |
| 346 | acl allow admin all |
| 347 | acl deny all all |
| 348 | EOF |
| 349 | # Add user to SASL database |
| 350 | if is_ubuntu; then |
| 351 | install_package sasl2-bin |
| 352 | elif is_fedora; then |
| 353 | install_package cyrus-sasl-lib |
Mehdi Abaakouk | d1e3ff1 | 2015-02-10 17:54:53 +0100 | [diff] [blame] | 354 | install_package cyrus-sasl-plain |
Kenneth Giusti | 062a3c3 | 2014-09-30 10:14:08 -0400 | [diff] [blame] | 355 | fi |
| 356 | local sasl_conf_file=/etc/sasl2/qpidd.conf |
| 357 | sudo sed -i.bak '/PLAIN/!s/mech_list: /mech_list: PLAIN /' $sasl_conf_file |
| 358 | local sasl_db=`sudo grep sasldb_path $sasl_conf_file | cut -f 2 -d ":" | tr -d [:blank:]` |
| 359 | if [ ! -e $sasl_db ]; then |
| 360 | sudo mkdir -p -m 755 `dirname $sasl_db` |
| 361 | fi |
| 362 | echo $QPID_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db -u QPID $QPID_USERNAME |
| 363 | sudo chmod o+r $sasl_db |
| 364 | fi |
| 365 | |
| 366 | # If AMQP 1.0 is specified, ensure that the version of the |
| 367 | # broker can support AMQP 1.0 and configure the queue and |
| 368 | # topic address patterns used by oslo.messaging. |
| 369 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 370 | QPIDD=$(type -p qpidd) |
| 371 | if ! $QPIDD --help | grep -q "queue-patterns"; then |
| 372 | exit_distro_not_supported "qpidd with AMQP 1.0 support" |
| 373 | fi |
| 374 | if ! grep -q "queue-patterns=exclusive" $qpid_conf_file; then |
| 375 | cat <<EOF | sudo tee --append $qpid_conf_file |
| 376 | queue-patterns=exclusive |
| 377 | queue-patterns=unicast |
| 378 | topic-patterns=broadcast |
| 379 | EOF |
| 380 | fi |
| 381 | fi |
| 382 | } |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 383 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 384 | # Restore xtrace |
| 385 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 386 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 387 | # Tell emacs to use shell-script-mode |
| 388 | ## Local variables: |
| 389 | ## mode: shell-script |
| 390 | ## End: |