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 | |
| 24 | # Make sure we only have one rpc backend enabled. |
| 25 | # Also check the specified rpc backend is available on your platform. |
| 26 | function check_rpc_backend() { |
| 27 | local rpc_backend_cnt=0 |
| 28 | for svc in qpid zeromq rabbit; do |
| 29 | is_service_enabled $svc && |
| 30 | ((rpc_backend_cnt++)) |
| 31 | done |
| 32 | if [ "$rpc_backend_cnt" -gt 1 ]; then |
| 33 | echo "ERROR: only one rpc backend may be enabled," |
| 34 | echo " set only one of 'rabbit', 'qpid', 'zeromq'" |
| 35 | echo " via ENABLED_SERVICES." |
| 36 | elif [ "$rpc_backend_cnt" == 0 ]; then |
| 37 | echo "ERROR: at least one rpc backend must be enabled," |
| 38 | echo " set one of 'rabbit', 'qpid', 'zeromq'" |
| 39 | echo " via ENABLED_SERVICES." |
| 40 | fi |
| 41 | |
| 42 | if is_service_enabled qpid && ! qpid_is_supported; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 43 | 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] | 44 | fi |
| 45 | } |
| 46 | |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 47 | # clean up after rpc backend - eradicate all traces so changing backends |
| 48 | # produces a clean switch |
| 49 | function cleanup_rpc_backend { |
| 50 | if is_service_enabled rabbit; then |
| 51 | # Obliterate rabbitmq-server |
| 52 | uninstall_package rabbitmq-server |
| 53 | sudo killall epmd |
| 54 | if is_ubuntu; then |
| 55 | # And the Erlang runtime too |
| 56 | sudo aptitude purge -y ~nerlang |
| 57 | fi |
| 58 | elif is_service_enabled qpid; then |
| 59 | if is_fedora; then |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 60 | if [[ $DISTRO =~ (rhel6) ]]; then |
| 61 | uninstall_package qpid-cpp-server |
| 62 | else |
| 63 | uninstall_package qpid-cpp-server-daemon |
| 64 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 65 | elif is_ubuntu; then |
| 66 | uninstall_package qpidd |
| 67 | else |
| 68 | exit_distro_not_supported "qpid installation" |
| 69 | fi |
| 70 | elif is_service_enabled zeromq; then |
| 71 | if is_fedora; then |
| 72 | uninstall_package zeromq python-zmq |
| 73 | elif is_ubuntu; then |
| 74 | uninstall_package libzmq1 python-zmq |
| 75 | elif is_suse; then |
| 76 | uninstall_package libzmq1 python-pyzmq |
| 77 | else |
| 78 | exit_distro_not_supported "zeromq installation" |
| 79 | fi |
| 80 | fi |
| 81 | } |
| 82 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 83 | # install rpc backend |
| 84 | function install_rpc_backend() { |
| 85 | if is_service_enabled rabbit; then |
| 86 | # Install rabbitmq-server |
| 87 | # the temp file is necessary due to LP: #878600 |
| 88 | tfile=$(mktemp) |
| 89 | install_package rabbitmq-server > "$tfile" 2>&1 |
| 90 | cat "$tfile" |
| 91 | rm -f "$tfile" |
| 92 | elif is_service_enabled qpid; then |
| 93 | if is_fedora; then |
Ian Wienand | 64dd03d | 2013-04-11 12:01:09 +1000 | [diff] [blame] | 94 | if [[ $DISTRO =~ (rhel6) ]]; then |
| 95 | install_package qpid-cpp-server |
| 96 | |
| 97 | # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to |
| 98 | # be no or you get GSS authentication errors as it |
| 99 | # attempts to default to this. |
| 100 | sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf |
| 101 | else |
| 102 | install_package qpid-cpp-server-daemon |
| 103 | fi |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 104 | elif is_ubuntu; then |
| 105 | install_package qpidd |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 106 | sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf |
| 107 | sudo chmod o+r /etc/qpid/qpidd.sasldb |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 108 | else |
| 109 | exit_distro_not_supported "qpid installation" |
| 110 | fi |
| 111 | elif is_service_enabled zeromq; then |
| 112 | if is_fedora; then |
| 113 | install_package zeromq python-zmq |
| 114 | elif is_ubuntu; then |
| 115 | install_package libzmq1 python-zmq |
| 116 | elif is_suse; then |
| 117 | install_package libzmq1 python-pyzmq |
| 118 | else |
| 119 | exit_distro_not_supported "zeromq installation" |
| 120 | fi |
| 121 | fi |
| 122 | } |
| 123 | |
| 124 | # restart the rpc backend |
| 125 | function restart_rpc_backend() { |
| 126 | if is_service_enabled rabbit; then |
| 127 | # Start rabbitmq-server |
| 128 | echo_summary "Starting RabbitMQ" |
| 129 | if is_fedora || is_suse; then |
| 130 | # service is not started by default |
| 131 | restart_service rabbitmq-server |
| 132 | fi |
| 133 | # change the rabbit password since the default is "guest" |
| 134 | sudo rabbitmqctl change_password guest $RABBIT_PASSWORD |
| 135 | elif is_service_enabled qpid; then |
| 136 | echo_summary "Starting qpid" |
| 137 | restart_service qpidd |
| 138 | fi |
| 139 | } |
| 140 | |
| 141 | # iniset cofiguration |
| 142 | function iniset_rpc_backend() { |
| 143 | local package=$1 |
| 144 | local file=$2 |
| 145 | local section=$3 |
| 146 | if is_service_enabled zeromq; then |
| 147 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq |
| 148 | elif is_service_enabled qpid; then |
| 149 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid |
Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 150 | if is_ubuntu; then |
| 151 | QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1` |
| 152 | iniset $file $section qpid_password $QPID_PASSWORD |
| 153 | iniset $file $section qpid_username admin |
| 154 | fi |
jiajun xu | 4a30b84 | 2013-01-22 11:49:03 +0800 | [diff] [blame] | 155 | elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 156 | iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu |
| 157 | iniset $file $section rabbit_host $RABBIT_HOST |
| 158 | iniset $file $section rabbit_password $RABBIT_PASSWORD |
| 159 | fi |
| 160 | } |
| 161 | |
| 162 | # Check if qpid can be used on the current distro. |
| 163 | # qpid_is_supported |
| 164 | function qpid_is_supported() { |
| 165 | if [[ -z "$DISTRO" ]]; then |
| 166 | GetDistro |
| 167 | fi |
| 168 | |
| 169 | # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is |
| 170 | # not in openSUSE either right now. |
| 171 | ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) ) |
| 172 | } |
| 173 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 174 | |
Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 175 | # Restore xtrace |
| 176 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 177 | |
| 178 | # Local variables: |
| 179 | # mode: shell-script |
| 180 | # End: |