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