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