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