2014-12-05 14:25:28 -05:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2013-01-13 17:58:12 +09:00
|
|
|
# lib/rpc_backend
|
2015-06-16 07:19:22 -04:00
|
|
|
# Interface for installing RabbitMQ on the system
|
2013-01-13 17:58:12 +09:00
|
|
|
|
|
|
|
# Dependencies:
|
2013-10-24 11:27:02 +01:00
|
|
|
#
|
|
|
|
# - ``functions`` file
|
2014-12-12 02:15:55 +05:30
|
|
|
# - ``RABBIT_{HOST|PASSWORD|USERID}`` must be defined when RabbitMQ is used
|
2013-01-13 17:58:12 +09:00
|
|
|
|
|
|
|
# ``stack.sh`` calls the entry points in this order:
|
|
|
|
#
|
2013-10-24 11:27:02 +01:00
|
|
|
# - check_rpc_backend
|
|
|
|
# - install_rpc_backend
|
|
|
|
# - restart_rpc_backend
|
2015-06-16 07:19:22 -04:00
|
|
|
# - iniset_rpc_backend (stable interface)
|
|
|
|
#
|
|
|
|
# Note: if implementing an out of tree plugin for an RPC backend, you
|
|
|
|
# should install all services through normal plugin methods, then
|
|
|
|
# redefine ``iniset_rpc_backend`` in your code. That's the one portion
|
|
|
|
# of this file which is a standard interface.
|
2013-01-13 17:58:12 +09:00
|
|
|
|
|
|
|
# Save trace setting
|
|
|
|
XTRACE=$(set +o | grep xtrace)
|
|
|
|
set +o xtrace
|
|
|
|
|
2013-04-08 15:38:03 -05:00
|
|
|
# Functions
|
|
|
|
# ---------
|
2013-01-13 17:58:12 +09:00
|
|
|
|
2013-03-07 16:11:40 -06:00
|
|
|
# clean up after rpc backend - eradicate all traces so changing backends
|
|
|
|
# produces a clean switch
|
|
|
|
function cleanup_rpc_backend {
|
|
|
|
if is_service_enabled rabbit; then
|
|
|
|
# Obliterate rabbitmq-server
|
|
|
|
uninstall_package rabbitmq-server
|
2015-02-04 12:44:18 -05:00
|
|
|
# in case it's not actually running, /bin/true at the end
|
|
|
|
sudo killall epmd || sudo killall -9 epmd || /bin/true
|
2013-03-07 16:11:40 -06:00
|
|
|
if is_ubuntu; then
|
|
|
|
# And the Erlang runtime too
|
2014-02-23 18:55:51 +01:00
|
|
|
apt_get purge -y erlang*
|
2013-03-07 16:11:40 -06:00
|
|
|
fi
|
2014-07-23 16:44:37 -04:00
|
|
|
fi
|
2013-03-07 16:11:40 -06:00
|
|
|
}
|
|
|
|
|
2013-01-13 17:58:12 +09:00
|
|
|
# install rpc backend
|
2014-02-21 15:35:08 +11:00
|
|
|
function install_rpc_backend {
|
2013-01-13 17:58:12 +09:00
|
|
|
if is_service_enabled rabbit; then
|
|
|
|
# Install rabbitmq-server
|
2014-07-23 14:24:11 +10:00
|
|
|
install_package rabbitmq-server
|
2014-09-15 14:21:55 -04:00
|
|
|
fi
|
2013-01-13 17:58:12 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
# restart the rpc backend
|
2014-02-21 15:35:08 +11:00
|
|
|
function restart_rpc_backend {
|
2013-01-13 17:58:12 +09:00
|
|
|
if is_service_enabled rabbit; then
|
|
|
|
# Start rabbitmq-server
|
|
|
|
echo_summary "Starting RabbitMQ"
|
2014-01-30 16:07:23 +00:00
|
|
|
# NOTE(bnemec): Retry initial rabbitmq configuration to deal with
|
|
|
|
# the fact that sometimes it fails to start properly.
|
2014-12-16 09:53:36 +11:00
|
|
|
# Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1144100
|
2015-05-15 12:51:43 +10:00
|
|
|
# NOTE(tonyb): Extend the orginal retry logic to only restart rabbitmq
|
|
|
|
# every second time around the loop.
|
|
|
|
# See: https://bugs.launchpad.net/devstack/+bug/1449056 for details on
|
|
|
|
# why this is needed. This can bee seen on vivid and Debian unstable
|
|
|
|
# (May 2015)
|
|
|
|
# TODO(tonyb): Remove this when Debian and Ubuntu have a fixed systemd
|
|
|
|
# service file.
|
2014-07-25 14:56:22 -05:00
|
|
|
local i
|
2015-05-15 12:51:43 +10:00
|
|
|
for i in `seq 20`; do
|
2014-12-16 09:53:36 +11:00
|
|
|
local rc=0
|
|
|
|
|
2015-05-15 12:51:43 +10:00
|
|
|
[[ $i -eq "20" ]] && die $LINENO "Failed to set rabbitmq password"
|
2014-12-16 09:53:36 +11:00
|
|
|
|
2015-05-15 12:51:43 +10:00
|
|
|
if [[ $(( i % 2 )) == "0" ]] ; then
|
|
|
|
restart_service rabbitmq-server
|
|
|
|
fi
|
2014-12-16 09:53:36 +11:00
|
|
|
|
|
|
|
rabbit_setuser "$RABBIT_USERID" "$RABBIT_PASSWORD" || rc=$?
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2014-01-30 16:07:23 +00:00
|
|
|
# change the rabbit password since the default is "guest"
|
2014-12-16 09:53:36 +11:00
|
|
|
sudo rabbitmqctl change_password \
|
|
|
|
$RABBIT_USERID $RABBIT_PASSWORD || rc=$?
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
break
|
2014-01-30 16:07:23 +00:00
|
|
|
done
|
2013-03-11 23:55:49 +00:00
|
|
|
if is_service_enabled n-cell; then
|
|
|
|
# Add partitioned access for the child cell
|
|
|
|
if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
|
|
|
|
sudo rabbitmqctl add_vhost child_cell
|
2014-12-12 02:15:55 +05:30
|
|
|
sudo rabbitmqctl set_permissions -p child_cell $RABBIT_USERID ".*" ".*" ".*"
|
2013-03-11 23:55:49 +00:00
|
|
|
fi
|
|
|
|
fi
|
2013-01-13 17:58:12 +09:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-02-12 15:33:35 -05:00
|
|
|
# builds transport url string
|
|
|
|
function get_transport_url {
|
2015-06-16 07:19:22 -04:00
|
|
|
if is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
|
2015-02-12 15:33:35 -05:00
|
|
|
echo "rabbit://$RABBIT_USERID:$RABBIT_PASSWORD@$RABBIT_HOST:5672/"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-01-13 17:58:12 +09:00
|
|
|
# iniset cofiguration
|
2014-02-21 15:35:08 +11:00
|
|
|
function iniset_rpc_backend {
|
2013-01-13 17:58:12 +09:00
|
|
|
local package=$1
|
|
|
|
local file=$2
|
2015-03-14 12:39:14 -05:00
|
|
|
local section=${3:-DEFAULT}
|
2015-06-16 07:19:22 -04:00
|
|
|
if is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
|
2015-01-23 03:10:49 -08:00
|
|
|
iniset $file $section rpc_backend "rabbit"
|
2015-03-23 15:05:39 -07:00
|
|
|
iniset $file oslo_messaging_rabbit rabbit_hosts $RABBIT_HOST
|
|
|
|
iniset $file oslo_messaging_rabbit rabbit_password $RABBIT_PASSWORD
|
|
|
|
iniset $file oslo_messaging_rabbit rabbit_userid $RABBIT_USERID
|
2015-04-09 11:46:56 +02:00
|
|
|
if [ -n "$RABBIT_HEARTBEAT_TIMEOUT_THRESHOLD" ]; then
|
|
|
|
iniset $file oslo_messaging_rabbit heartbeat_timeout_threshold $RABBIT_HEARTBEAT_TIMEOUT_THRESHOLD
|
|
|
|
fi
|
|
|
|
if [ -n "$RABBIT_HEARTBEAT_RATE" ]; then
|
|
|
|
iniset $file oslo_messaging_rabbit heartbeat_rate $RABBIT_HEARTBEAT_RATE
|
|
|
|
fi
|
2013-01-13 17:58:12 +09:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-12-12 02:15:55 +05:30
|
|
|
function rabbit_setuser {
|
|
|
|
local user="$1" pass="$2" found="" out=""
|
|
|
|
out=$(sudo rabbitmqctl list_users) ||
|
|
|
|
{ echo "failed to list users" 1>&2; return 1; }
|
|
|
|
found=$(echo "$out" | awk '$1 == user { print $1 }' "user=$user")
|
|
|
|
if [ "$found" = "$user" ]; then
|
|
|
|
sudo rabbitmqctl change_password "$user" "$pass" ||
|
|
|
|
{ echo "failed changing pass for '$user'" 1>&2; return 1; }
|
|
|
|
else
|
|
|
|
sudo rabbitmqctl add_user "$user" "$pass" ||
|
|
|
|
{ echo "failed changing pass for $user"; return 1; }
|
|
|
|
fi
|
|
|
|
sudo rabbitmqctl set_permissions "$user" ".*" ".*" ".*"
|
|
|
|
}
|
|
|
|
|
2013-01-13 17:58:12 +09:00
|
|
|
# Restore xtrace
|
|
|
|
$XTRACE
|
2013-03-29 14:34:53 -04:00
|
|
|
|
2013-10-24 11:27:02 +01:00
|
|
|
# Tell emacs to use shell-script-mode
|
|
|
|
## Local variables:
|
|
|
|
## mode: shell-script
|
|
|
|
## End:
|