From 042893a4488445b31c9fd783e66a160804933592 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 14 Mar 2019 17:08:55 -0700 Subject: [PATCH] configure-rabbitmq: Allow running as root. This makes it possible to run this in production without access to sudo. --- scripts/setup/configure-rabbitmq | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/setup/configure-rabbitmq b/scripts/setup/configure-rabbitmq index e2685fa9f8..26d4f3d9a9 100755 --- a/scripts/setup/configure-rabbitmq +++ b/scripts/setup/configure-rabbitmq @@ -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" '.*' '.*' '.*'