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