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 |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 9 | |
| 10 | # ``stack.sh`` calls the entry points in this order: |
| 11 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 12 | # - check_rpc_backend |
| 13 | # - install_rpc_backend |
| 14 | # - restart_rpc_backend |
| 15 | # - iniset_rpc_backend |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 16 | |
| 17 | # Save trace setting |
| 18 | XTRACE=$(set +o | grep xtrace) |
| 19 | set +o xtrace |
| 20 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 21 | |
| 22 | # Functions |
| 23 | # --------- |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 24 | |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 25 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 26 | # Make sure we only have one rpc backend enabled. |
| 27 | # Also check the specified rpc backend is available on your platform. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 28 | function check_rpc_backend { |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 29 | local rpc_needed=1 |
| 30 | # We rely on the fact that filenames in lib/* match the service names |
| 31 | # that can be passed as arguments to is_service_enabled. |
| 32 | # We check for a call to iniset_rpc_backend in these files, meaning |
| 33 | # the service needs a backend. |
Vishvananda Ishaya | 78a53d9 | 2013-05-09 17:20:31 -0700 | [diff] [blame] | 34 | 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] | 35 | for c in ${rpc_candidates}; do |
| 36 | if is_service_enabled $c; then |
| 37 | rpc_needed=0 |
| 38 | break |
| 39 | fi |
| 40 | done |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 41 | local rpc_backend_cnt=0 |
| 42 | for svc in qpid zeromq rabbit; do |
| 43 | is_service_enabled $svc && |
| 44 | ((rpc_backend_cnt++)) |
| 45 | done |
| 46 | if [ "$rpc_backend_cnt" -gt 1 ]; then |
| 47 | echo "ERROR: only one rpc backend may be enabled," |
| 48 | echo " set only one of 'rabbit', 'qpid', 'zeromq'" |
| 49 | echo " via ENABLED_SERVICES." |
Matthieu Huin | 7a7a466 | 2013-04-15 17:13:41 +0200 | [diff] [blame] | 50 | elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 51 | echo "ERROR: at least one rpc backend must be enabled," |
| 52 | echo " set one of 'rabbit', 'qpid', 'zeromq'" |
| 53 | echo " via ENABLED_SERVICES." |
| 54 | fi |
| 55 | |
| 56 | if is_service_enabled qpid && ! qpid_is_supported; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 57 | 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] | 58 | fi |
| 59 | } |
| 60 | |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 61 | # clean up after rpc backend - eradicate all traces so changing backends |
| 62 | # produces a clean switch |
| 63 | function cleanup_rpc_backend { |
| 64 | if is_service_enabled rabbit; then |
| 65 | # Obliterate rabbitmq-server |
| 66 | uninstall_package rabbitmq-server |
DennyZhang | 557744f | 2013-10-14 09:50:13 -0500 | [diff] [blame] | 67 | sudo killall epmd || sudo killall -9 epmd |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 68 | if is_ubuntu; then |
| 69 | # And the Erlang runtime too |
Sahid Orentino Ferdjaoui | e964827 | 2014-02-23 18:55:51 +0100 | [diff] [blame] | 70 | apt_get purge -y erlang* |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 71 | fi |
| 72 | elif is_service_enabled qpid; then |
| 73 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 74 | uninstall_package qpid-cpp-server |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 75 | elif is_ubuntu; then |
| 76 | uninstall_package qpidd |
| 77 | else |
| 78 | exit_distro_not_supported "qpid installation" |
| 79 | fi |
| 80 | elif is_service_enabled zeromq; then |
| 81 | if is_fedora; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 82 | uninstall_package zeromq python-zmq redis |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 83 | elif is_ubuntu; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 84 | uninstall_package libzmq1 python-zmq redis-server |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 85 | elif is_suse; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 86 | uninstall_package libzmq1 python-pyzmq redis |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 87 | else |
| 88 | exit_distro_not_supported "zeromq installation" |
| 89 | fi |
| 90 | fi |
| 91 | } |
| 92 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 93 | # install rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 94 | function install_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 95 | if is_service_enabled rabbit; then |
| 96 | # Install rabbitmq-server |
| 97 | # the temp file is necessary due to LP: #878600 |
| 98 | tfile=$(mktemp) |
| 99 | install_package rabbitmq-server > "$tfile" 2>&1 |
| 100 | cat "$tfile" |
| 101 | rm -f "$tfile" |
| 102 | elif is_service_enabled qpid; then |
| 103 | if is_fedora; then |
zhhuabj | 5595fdc | 2013-05-08 18:27:20 +0800 | [diff] [blame] | 104 | install_package qpid-cpp-server |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 105 | if [[ $DISTRO =~ (rhel6) ]]; then |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 106 | # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to |
| 107 | # be no or you get GSS authentication errors as it |
| 108 | # attempts to default to this. |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 109 | sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 110 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 111 | elif is_ubuntu; then |
| 112 | install_package qpidd |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 113 | sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf |
| 114 | sudo chmod o+r /etc/qpid/qpidd.sasldb |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 115 | else |
| 116 | exit_distro_not_supported "qpid installation" |
| 117 | fi |
| 118 | elif is_service_enabled zeromq; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 119 | # NOTE(ewindisch): Redis is not strictly necessary |
| 120 | # but there is a matchmaker driver that works |
| 121 | # really well & out of the box for multi-node. |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 122 | if is_fedora; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 123 | install_package zeromq python-zmq redis |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 124 | elif is_ubuntu; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 125 | install_package libzmq1 python-zmq redis-server |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 126 | elif is_suse; then |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 127 | install_package libzmq1 python-pyzmq redis |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 128 | else |
| 129 | exit_distro_not_supported "zeromq installation" |
| 130 | fi |
Vincent Hou | 93a7a50 | 2013-09-27 06:16:54 -0400 | [diff] [blame] | 131 | # Necessary directory for socket location. |
| 132 | sudo mkdir -p /var/run/openstack |
| 133 | sudo chown $STACK_USER /var/run/openstack |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 134 | fi |
| 135 | } |
| 136 | |
| 137 | # restart the rpc backend |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 138 | function restart_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 139 | if is_service_enabled rabbit; then |
| 140 | # Start rabbitmq-server |
| 141 | echo_summary "Starting RabbitMQ" |
Ben Nemec | ec5918f | 2014-01-30 16:07:23 +0000 | [diff] [blame] | 142 | # NOTE(bnemec): Retry initial rabbitmq configuration to deal with |
| 143 | # the fact that sometimes it fails to start properly. |
| 144 | # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028 |
| 145 | for i in `seq 10`; do |
| 146 | if is_fedora || is_suse; then |
| 147 | # service is not started by default |
| 148 | restart_service rabbitmq-server |
| 149 | fi |
| 150 | # change the rabbit password since the default is "guest" |
| 151 | sudo rabbitmqctl change_password guest $RABBIT_PASSWORD && break |
| 152 | [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password" |
| 153 | done |
Kieran Spear | fb2a3ae | 2013-03-11 23:55:49 +0000 | [diff] [blame] | 154 | if is_service_enabled n-cell; then |
| 155 | # Add partitioned access for the child cell |
| 156 | if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then |
| 157 | sudo rabbitmqctl add_vhost child_cell |
| 158 | sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*" |
| 159 | fi |
| 160 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 161 | elif is_service_enabled qpid; then |
| 162 | echo_summary "Starting qpid" |
| 163 | restart_service qpidd |
| 164 | fi |
| 165 | } |
| 166 | |
| 167 | # iniset cofiguration |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 168 | function iniset_rpc_backend { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 169 | local package=$1 |
| 170 | local file=$2 |
| 171 | local section=$3 |
| 172 | if is_service_enabled zeromq; then |
| 173 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq |
Eric Windisch | 800bf38 | 2013-05-24 11:21:11 -0400 | [diff] [blame] | 174 | iniset $file $section rpc_zmq_matchmaker \ |
| 175 | ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis |
| 176 | # Set MATCHMAKER_REDIS_HOST if running multi-node. |
| 177 | MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1} |
| 178 | iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST |
Jason Dillaman | 056df82 | 2013-07-01 08:52:13 -0400 | [diff] [blame] | 179 | elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 180 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid |
Attila Fazekas | a3dc399 | 2013-07-11 11:26:35 +0200 | [diff] [blame] | 181 | iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST} |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 182 | if is_ubuntu; then |
| 183 | QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1` |
| 184 | iniset $file $section qpid_password $QPID_PASSWORD |
| 185 | iniset $file $section qpid_username admin |
| 186 | fi |
jiajun xu | 4a30b84 | 2013-01-22 11:49:03 +0800 | [diff] [blame] | 187 | elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 188 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu |
Nicolas Simonds | 8f084c6 | 2014-02-28 17:01:41 -0800 | [diff] [blame] | 189 | iniset $file $section rabbit_hosts $RABBIT_HOST |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 190 | iniset $file $section rabbit_password $RABBIT_PASSWORD |
| 191 | fi |
| 192 | } |
| 193 | |
| 194 | # Check if qpid can be used on the current distro. |
| 195 | # qpid_is_supported |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 196 | function qpid_is_supported { |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 197 | if [[ -z "$DISTRO" ]]; then |
| 198 | GetDistro |
| 199 | fi |
| 200 | |
Sean Dague | 2bb483d | 2014-01-03 09:41:27 -0500 | [diff] [blame] | 201 | # Qpid is not in openSUSE |
| 202 | ( ! is_suse ) |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 203 | } |
| 204 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 205 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 206 | # Restore xtrace |
| 207 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 208 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 209 | # Tell emacs to use shell-script-mode |
| 210 | ## Local variables: |
| 211 | ## mode: shell-script |
| 212 | ## End: |