configure-rabbitmq: Allow running as root.

This makes it possible to run this in production without access to
sudo.
This commit is contained in:
Tim Abbott 2019-03-14 17:08:55 -07:00
parent 4c3c669b41
commit 042893a448
1 changed files with 13 additions and 6 deletions

View File

@ -11,9 +11,16 @@ if [ -n "$RABBITMQ_NODE" ]; then
fi
RABBITMQ_USERNAME=$("$(dirname "$0")/../get-django-setting" RABBITMQ_USERNAME)
RABBITMQ_PASSWORD=$("$(dirname "$0")/../get-django-setting" RABBITMQ_PASSWORD)
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" delete_user "$RABBITMQ_USERNAME" || true
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" delete_user zulip || true
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" delete_user guest || true
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" add_user "$RABBITMQ_USERNAME" "$RABBITMQ_PASSWORD"
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" set_user_tags "$RABBITMQ_USERNAME" administrator
sudo rabbitmqctl "${RABBITMQ_FLAGS[@]}" set_permissions -p / "$RABBITMQ_USERNAME" '.*' '.*' '.*'
if [ "$EUID" -eq 0 ]; then
RABBITMQCTL_COMMAND="rabbitmqctl"
else
RABBITMQCTL_COMMAND="sudo rabbitmqctl"
fi
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" delete_user "$RABBITMQ_USERNAME" || true
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" delete_user zulip || true
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" delete_user guest || true
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" add_user "$RABBITMQ_USERNAME" "$RABBITMQ_PASSWORD"
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" set_user_tags "$RABBITMQ_USERNAME" administrator
$RABBITMQCTL_COMMAND "${RABBITMQ_FLAGS[@]}" set_permissions -p / "$RABBITMQ_USERNAME" '.*' '.*' '.*'