Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 1 | # lib/rpc_backend |
| 2 | # Interface for interactig with different rpc backend |
| 3 | # rpc backend settings |
| 4 | |
| 5 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 6 | # |
| 7 | # - ``functions`` file |
| 8 | # - ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 9 | # - ``RPC_MESSAGING_PROTOCOL`` option for configuring the messaging protocol |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 10 | |
| 11 | # ``stack.sh`` calls the entry points in this order: |
| 12 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 13 | # - check_rpc_backend |
| 14 | # - install_rpc_backend |
| 15 | # - restart_rpc_backend |
| 16 | # - iniset_rpc_backend |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 17 | |
| 18 | # Save trace setting |
| 19 | XTRACE=$(set +o | grep xtrace) |
| 20 | set +o xtrace |
| 21 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 22 | |
| 23 | # Functions |
| 24 | # --------- |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 25 | |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 26 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 27 | # Make sure we only have one rpc backend enabled. |
| 28 | # Also check the specified rpc backend is available on your platform. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 29 | function check_rpc_backend { |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 30 | local c svc |
| 31 | |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 32 | local rpc_needed=1 |
| 33 | # We rely on the fact that filenames in lib/* match the service names |
| 34 | # that can be passed as arguments to is_service_enabled. |
| 35 | # We check for a call to iniset_rpc_backend in these files, meaning |
| 36 | # the service needs a backend. |
Vishvananda Ishaya | 78a53d9 | 2013-05-09 17:20:31 -0700 | [diff] [blame] | 37 | 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] | 38 | for c in ${rpc_candidates}; do |
| 39 | if is_service_enabled $c; then |
| 40 | rpc_needed=0 |
| 41 | break |
| 42 | fi |
| 43 | done |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 44 | local rpc_backend_cnt=0 |
| 45 | for svc in qpid zeromq rabbit; do |
| 46 | is_service_enabled $svc && |
Dean Troyer | ffd1768 | 2014-08-02 16:07:03 -0500 | [diff] [blame] | 47 | (( rpc_backend_cnt++ )) || true |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 48 | done |
| 49 | if [ "$rpc_backend_cnt" -gt 1 ]; then |
| 50 | echo "ERROR: only one rpc backend may be enabled," |
| 51 | echo " set only one of 'rabbit', 'qpid', 'zeromq'" |
| 52 | echo " via ENABLED_SERVICES." |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 53 | elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 54 | echo "ERROR: at least one rpc backend must be enabled," |
| 55 | echo " set one of 'rabbit', 'qpid', 'zeromq'" |
| 56 | echo " via ENABLED_SERVICES." |
| 57 | fi |
| 58 | |
| 59 | if is_service_enabled qpid && ! qpid_is_supported; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 60 | 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] | 61 | fi |
| 62 | } |
| 63 | |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 64 | # clean up after rpc backend - eradicate all traces so changing backends |
| 65 | # produces a clean switch |
| 66 | function cleanup_rpc_backend { |
| 67 | if is_service_enabled rabbit; then |
| 68 | # Obliterate rabbitmq-server |
| 69 | uninstall_package rabbitmq-server |
DennyZhang | 557744f | 2013-10-14 09:50:13 -0500 | [diff] [blame] | 70 | sudo killall epmd || sudo killall -9 epmd |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 71 | if is_ubuntu; then |
| 72 | # And the Erlang runtime too |
Sahid Orentino Ferdjaoui | e964827 | 2014-02-23 18:55:51 +0100 | [diff] [blame] | 73 | apt_get purge -y erlang* |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 74 | fi |
| 75 | elif is_service_enabled qpid; then |
| 76 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 77 | uninstall_package qpid-cpp-server |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 78 | elif is_ubuntu; then |
| 79 | uninstall_package qpidd |
| 80 | else |
| 81 | exit_distro_not_supported "qpid installation" |
| 82 | fi |
| 83 | elif is_service_enabled zeromq; then |
| 84 | if is_fedora; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 85 | uninstall_package zeromq python-zmq redis |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 86 | elif is_ubuntu; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 87 | uninstall_package libzmq1 python-zmq redis-server |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 88 | elif is_suse; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 89 | uninstall_package libzmq1 python-pyzmq redis |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 90 | else |
| 91 | exit_distro_not_supported "zeromq installation" |
| 92 | fi |
| 93 | fi |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 94 | |
| 95 | # Remove the AMQP 1.0 messaging libraries |
| 96 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 97 | if is_fedora; then |
| 98 | uninstall_package qpid-proton-c-devel |
| 99 | uninstall_package python-qpid-proton |
| 100 | fi |
| 101 | # TODO(kgiusti) ubuntu cleanup |
| 102 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 103 | } |
| 104 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 105 | # install rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 106 | function install_rpc_backend { |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 107 | # Regardless of the broker used, if AMQP 1.0 is configured load |
| 108 | # the necessary messaging client libraries for oslo.messaging |
| 109 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 110 | if is_fedora; then |
| 111 | install_package qpid-proton-c-devel |
| 112 | install_package python-qpid-proton |
| 113 | elif is_ubuntu; then |
| 114 | # TODO(kgiusti) The QPID AMQP 1.0 protocol libraries |
| 115 | # are not yet in the ubuntu repos. Enable these installs |
| 116 | # once they are present: |
| 117 | #install_package libqpid-proton2-dev |
| 118 | #install_package python-qpid-proton |
| 119 | # Also add 'uninstall' directives in cleanup_rpc_backend()! |
| 120 | exit_distro_not_supported "QPID AMQP 1.0 Proton libraries" |
| 121 | else |
| 122 | exit_distro_not_supported "QPID AMQP 1.0 Proton libraries" |
| 123 | fi |
| 124 | # Install pyngus client API |
| 125 | # TODO(kgiusti) can remove once python qpid bindings are |
| 126 | # available on all supported platforms _and_ pyngus is added |
| 127 | # to the requirements.txt file in oslo.messaging |
| 128 | pip_install pyngus |
| 129 | fi |
| 130 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 131 | if is_service_enabled rabbit; then |
| 132 | # Install rabbitmq-server |
Ian Wienand | 7ccf4e0 | 2014-07-23 14:24:11 +1000 | [diff] [blame] | 133 | install_package rabbitmq-server |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 134 | elif is_service_enabled qpid; then |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 135 | local qpid_conf_file=/etc/qpid/qpidd.conf |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 136 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 137 | install_package qpid-cpp-server |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 138 | if [[ $DISTRO =~ (rhel6) ]]; then |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 139 | qpid_conf_file=/etc/qpidd.conf |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 140 | # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to |
| 141 | # be no or you get GSS authentication errors as it |
| 142 | # attempts to default to this. |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 143 | sudo sed -i.bak 's/^auth=yes$/auth=no/' $qpid_conf_file |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 144 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 145 | elif is_ubuntu; then |
| 146 | install_package qpidd |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 147 | sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf |
| 148 | sudo chmod o+r /etc/qpid/qpidd.sasldb |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 149 | else |
| 150 | exit_distro_not_supported "qpid installation" |
| 151 | fi |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 152 | # If AMQP 1.0 is specified, ensure that the version of the |
| 153 | # broker can support AMQP 1.0 and configure the queue and |
| 154 | # topic address patterns used by oslo.messaging. |
| 155 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 156 | QPIDD=$(type -p qpidd) |
| 157 | if ! $QPIDD --help | grep -q "queue-patterns"; then |
| 158 | exit_distro_not_supported "qpidd with AMQP 1.0 support" |
| 159 | fi |
| 160 | if ! grep -q "queue-patterns=exclusive" $qpid_conf_file; then |
| 161 | cat <<EOF | sudo tee --append $qpid_conf_file |
| 162 | queue-patterns=exclusive |
| 163 | queue-patterns=unicast |
| 164 | topic-patterns=broadcast |
| 165 | EOF |
| 166 | fi |
| 167 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 168 | elif is_service_enabled zeromq; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 169 | # NOTE(ewindisch): Redis is not strictly necessary |
| 170 | # but there is a matchmaker driver that works |
| 171 | # really well & out of the box for multi-node. |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 172 | if is_fedora; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 173 | install_package zeromq python-zmq redis |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 174 | elif is_ubuntu; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 175 | install_package libzmq1 python-zmq redis-server |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 176 | elif is_suse; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 177 | install_package libzmq1 python-pyzmq redis |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 178 | else |
| 179 | exit_distro_not_supported "zeromq installation" |
| 180 | fi |
Vincent Hou | 93a7a50 | 2013-09-27 06:16:54 -0400 | [diff] [blame] | 181 | # Necessary directory for socket location. |
| 182 | sudo mkdir -p /var/run/openstack |
| 183 | sudo chown $STACK_USER /var/run/openstack |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 184 | fi |
Kenneth Giusti | a1875b7 | 2014-09-15 14:21:55 -0400 | [diff] [blame] | 185 | |
| 186 | # If using the QPID broker, install the QPID python client API |
| 187 | if is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
| 188 | install_package python-qpid |
| 189 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | # restart the rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 193 | function restart_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 194 | if is_service_enabled rabbit; then |
| 195 | # Start rabbitmq-server |
| 196 | echo_summary "Starting RabbitMQ" |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 197 | # NOTE(bnemec): Retry initial rabbitmq configuration to deal with |
| 198 | # the fact that sometimes it fails to start properly. |
| 199 | # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028 |
Dean Troyer | 3ef23bc | 2014-07-25 14:56:22 -0500 | [diff] [blame] | 200 | local i |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 201 | for i in `seq 10`; do |
| 202 | if is_fedora || is_suse; then |
| 203 | # service is not started by default |
| 204 | restart_service rabbitmq-server |
| 205 | fi |
| 206 | # change the rabbit password since the default is "guest" |
| 207 | sudo rabbitmqctl change_password guest $RABBIT_PASSWORD && break |
| 208 | [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password" |
| 209 | done |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 210 | if is_service_enabled n-cell; then |
| 211 | # Add partitioned access for the child cell |
| 212 | if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then |
| 213 | sudo rabbitmqctl add_vhost child_cell |
| 214 | sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*" |
| 215 | fi |
| 216 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 217 | elif is_service_enabled qpid; then |
| 218 | echo_summary "Starting qpid" |
| 219 | restart_service qpidd |
| 220 | fi |
| 221 | } |
| 222 | |
| 223 | # iniset cofiguration |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 224 | function iniset_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 225 | local package=$1 |
| 226 | local file=$2 |
| 227 | local section=$3 |
| 228 | if is_service_enabled zeromq; then |
| 229 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 230 | iniset $file $section rpc_zmq_matchmaker \ |
| 231 | ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis |
| 232 | # Set MATCHMAKER_REDIS_HOST if running multi-node. |
| 233 | MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1} |
| 234 | iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST |
Jason Dillaman | 056df82 | 2013-07-01 08:52:13 -0400 | [diff] [blame] | 235 | elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
Kenneth Giusti | 7e58c06 | 2014-07-23 16:44:37 -0400 | [diff] [blame] | 236 | # For Qpid use the 'amqp' oslo.messaging transport when AMQP 1.0 is used |
| 237 | if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then |
| 238 | iniset $file $section rpc_backend "amqp" |
| 239 | else |
| 240 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid |
| 241 | fi |
Attila Fazekas | a3dc399 | 2013-07-11 11:26:35 +0200 | [diff] [blame] | 242 | iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST} |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 243 | if is_ubuntu; then |
| 244 | QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1` |
| 245 | iniset $file $section qpid_password $QPID_PASSWORD |
| 246 | iniset $file $section qpid_username admin |
| 247 | fi |
jiajun xu | 4a30b84 | 2013-01-22 11:49:03 +0800 | [diff] [blame] | 248 | elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 249 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu |
Nicolas Simonds | 8f084c6 | 2014-02-28 17:01:41 -0800 | [diff] [blame] | 250 | iniset $file $section rabbit_hosts $RABBIT_HOST |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 251 | iniset $file $section rabbit_password $RABBIT_PASSWORD |
| 252 | fi |
| 253 | } |
| 254 | |
| 255 | # Check if qpid can be used on the current distro. |
| 256 | # qpid_is_supported |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 257 | function qpid_is_supported { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 258 | if [[ -z "$DISTRO" ]]; then |
| 259 | GetDistro |
| 260 | fi |
| 261 | |
Sean Dague | 2bb483d | 2014-01-03 09:41:27 -0500 | [diff] [blame] | 262 | # Qpid is not in openSUSE |
| 263 | ( ! is_suse ) |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 264 | } |
| 265 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 266 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 267 | # Restore xtrace |
| 268 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 269 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 270 | # Tell emacs to use shell-script-mode |
| 271 | ## Local variables: |
| 272 | ## mode: shell-script |
| 273 | ## End: |