RabbitMQ 3.0 syntax fixes, clustering fixes.
This commit is contained in:
parent
5bf7673c24
commit
eb70369283
|
@ -18,7 +18,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -ue
|
||||
set -e
|
||||
|
||||
RABBIT_CTL='rabbitmqctl'
|
||||
|
||||
|
@ -42,17 +42,25 @@ function create_vhost {
|
|||
}
|
||||
|
||||
function user_create {
|
||||
juju-log "rabbitmq: Creating user $1."
|
||||
$RABBIT_CTL add_user "$1" "$3" || return 1
|
||||
local user="$1"
|
||||
local passwd="$2"
|
||||
local vhost="$3"
|
||||
local admin="$4"
|
||||
juju-log "rabbitmq: Creating user $1 (vhost: $3"
|
||||
$RABBIT_CTL add_user "$user" "$passwd" || return 1
|
||||
|
||||
# grant the user all permissions on the default vhost /
|
||||
# TODO: investigate sane permissions
|
||||
juju-log "rabbitmq: Granting permission to $1 on vhost /"
|
||||
$RABBIT_CTL set_permissions -p $VHOST $1 ".*" ".*" ".*"
|
||||
$RABBIT_CTL set_permissions -p "$vhost" "$user" ".*" ".*" ".*"
|
||||
|
||||
if [[ "$2" == 'admin' ]] ; then
|
||||
user_is_admin "$1" && return 0
|
||||
juju-log "rabbitmq: Granting user $1 admin access"
|
||||
$RABBIT_CTL set_user_tags "$1" administrator || return 1
|
||||
if [[ "$admin" == "admin" ]] ; then
|
||||
user_is_admin "$user" && return 0
|
||||
juju-log "rabbitmq: Granting user $user admin access"
|
||||
$RABBIT_CTL set_user_tags "$user" administrator || return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function rabbit_version {
|
||||
echo "$(dpkg -l | grep rabbitmq-server | awk '{ print $3 }')"
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -ue
|
||||
set -e
|
||||
|
||||
CHARM_DIR=$(dirname $0)
|
||||
ARG0=${0##*/}
|
||||
|
@ -47,6 +47,21 @@ function amqp_changed() {
|
|||
# In reponse, we generate a password for new users,
|
||||
# grant the user access on the default vhost "/",
|
||||
# and tell it where to reach us.
|
||||
|
||||
# Skip managing rabbit queue config unless we are the
|
||||
# highest numbered unit in the service cluster.
|
||||
local local_unit_id=$(echo $JUJU_UNIT_NAME | cut -d/ -f2)
|
||||
local remote_unit_id=""
|
||||
for relid in $(relation-ids cluster) ; do
|
||||
for unit in $(relation-list -r "$relid") ; do
|
||||
remote_unit_id="$(echo $unit | cut -d/ -f2)"
|
||||
if [[ "$remote_unit_id" -gt "$local_unit_id" ]]; then
|
||||
juju-log "amqp_changed(): Deferring amqp_changed to leader."
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
local rabbit_user=`relation-get username`
|
||||
local vhost=`relation-get vhost`
|
||||
if [[ -z "$rabbit_user" ]] || [[ -z "$vhost" ]] ; then
|
||||
|
@ -68,7 +83,7 @@ function amqp_changed() {
|
|||
fi
|
||||
if ! user_exists "$rabbit_user" ; then
|
||||
juju-log "rabbitmq-server: Creating user $rabbit_user"
|
||||
user_create $rabbit_user admin || exit 1
|
||||
user_create "$rabbit_user" "$password" "$vhost" admin || exit 1
|
||||
else
|
||||
juju-log "rabbitmq-server: user $rabbit_user already exists."
|
||||
fi
|
||||
|
@ -109,9 +124,19 @@ function cluster_changed {
|
|||
# Configure clustering.
|
||||
# rabbitmq apparently does not like FQDNs.
|
||||
local short_host=$(echo $remote_host | sed -e 's/\./ /g' | awk '{ print $1 }')
|
||||
local cur_vers=$(rabbit_version)
|
||||
local cluster_cmd="cluster"
|
||||
if dpkg --compare-versions "$cur_vers" ge "3.0.1-1" ; then
|
||||
cluster_cmd="join_cluster"
|
||||
fi
|
||||
if ! rabbitmqctl cluster_status | grep -q "rabbit@$short_host" ; then
|
||||
juju-log "Clustering with new rabbitmq peer @ $short_host."
|
||||
rabbitmqctl stop_app
|
||||
rabbitmqctl cluster rabbit@$short_host
|
||||
rabbitmqctl $cluster_cmd rabbit@$short_host
|
||||
rabbitmqctl start_app
|
||||
else
|
||||
juju-log "Already clustered with rabbitmq peer @ $short_host."
|
||||
fi
|
||||
}
|
||||
|
||||
case $ARG0 in
|
||||
|
|
Loading…
Reference in New Issue