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