| 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 |  | 
 | 46 | # install rpc backend | 
 | 47 | function install_rpc_backend() { | 
 | 48 |     if is_service_enabled rabbit; then | 
 | 49 |         # Install rabbitmq-server | 
 | 50 |         # the temp file is necessary due to LP: #878600 | 
 | 51 |         tfile=$(mktemp) | 
 | 52 |         install_package rabbitmq-server > "$tfile" 2>&1 | 
 | 53 |         cat "$tfile" | 
 | 54 |         rm -f "$tfile" | 
 | 55 |     elif is_service_enabled qpid; then | 
 | 56 |         if is_fedora; then | 
 | 57 |             install_package qpid-cpp-server-daemon | 
 | 58 |         elif is_ubuntu; then | 
 | 59 |             install_package qpidd | 
| Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 60 |             sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf | 
 | 61 |             sudo chmod o+r /etc/qpid/qpidd.sasldb | 
| Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 62 |         else | 
 | 63 |             exit_distro_not_supported "qpid installation" | 
 | 64 |         fi | 
 | 65 |     elif is_service_enabled zeromq; then | 
 | 66 |         if is_fedora; then | 
 | 67 |             install_package zeromq python-zmq | 
 | 68 |         elif is_ubuntu; then | 
 | 69 |             install_package libzmq1 python-zmq | 
 | 70 |         elif is_suse; then | 
 | 71 |             install_package libzmq1 python-pyzmq | 
 | 72 |         else | 
 | 73 |             exit_distro_not_supported "zeromq installation" | 
 | 74 |         fi | 
 | 75 |     fi | 
 | 76 | } | 
 | 77 |  | 
 | 78 | # restart the rpc backend | 
 | 79 | function restart_rpc_backend() { | 
 | 80 |     if is_service_enabled rabbit; then | 
 | 81 |         # Start rabbitmq-server | 
 | 82 |         echo_summary "Starting RabbitMQ" | 
 | 83 |         if is_fedora || is_suse; then | 
 | 84 |             # service is not started by default | 
 | 85 |             restart_service rabbitmq-server | 
 | 86 |         fi | 
 | 87 |         # change the rabbit password since the default is "guest" | 
 | 88 |         sudo rabbitmqctl change_password guest $RABBIT_PASSWORD | 
 | 89 |     elif is_service_enabled qpid; then | 
 | 90 |         echo_summary "Starting qpid" | 
 | 91 |         restart_service qpidd | 
 | 92 |     fi | 
 | 93 | } | 
 | 94 |  | 
 | 95 | # iniset cofiguration | 
 | 96 | function iniset_rpc_backend() { | 
 | 97 |     local package=$1 | 
 | 98 |     local file=$2 | 
 | 99 |     local section=$3 | 
 | 100 |     if is_service_enabled zeromq; then | 
 | 101 |         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq | 
 | 102 |     elif is_service_enabled qpid; then | 
 | 103 |         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid | 
| Eoghan Glynn | 8c11f56 | 2013-03-01 12:09:01 +0000 | [diff] [blame] | 104 |         if is_ubuntu; then | 
 | 105 |             QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1` | 
 | 106 |             iniset $file $section qpid_password $QPID_PASSWORD | 
 | 107 |             iniset $file $section qpid_username admin | 
 | 108 |         fi | 
| jiajun xu | 4a30b84 | 2013-01-22 11:49:03 +0800 | [diff] [blame] | 109 |     elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then | 
| Akihiro MOTOKI | b0f1c38 | 2013-01-13 17:58:12 +0900 | [diff] [blame] | 110 |         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu | 
 | 111 |         iniset $file $section rabbit_host $RABBIT_HOST | 
 | 112 |         iniset $file $section rabbit_password $RABBIT_PASSWORD | 
 | 113 |     fi | 
 | 114 | } | 
 | 115 |  | 
 | 116 | # Check if qpid can be used on the current distro. | 
 | 117 | # qpid_is_supported | 
 | 118 | function qpid_is_supported() { | 
 | 119 |     if [[ -z "$DISTRO" ]]; then | 
 | 120 |         GetDistro | 
 | 121 |     fi | 
 | 122 |  | 
 | 123 |     # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is | 
 | 124 |     # not in openSUSE either right now. | 
 | 125 |     ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) ) | 
 | 126 | } | 
 | 127 |  | 
 | 128 | # Restore xtrace | 
 | 129 | $XTRACE |