Skip to content

Instantly share code, notes, and snippets.

@heytrav
Last active September 24, 2015 05:33
Show Gist options
  • Select an option

  • Save heytrav/367ad0fcafef1aa0bfc5 to your computer and use it in GitHub Desktop.

Select an option

Save heytrav/367ad0fcafef1aa0bfc5 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Note that the environment variables RABBITMQ_USER, RABBITMQ_PASS, RABBITMQ_VHOST need to
# be initialised somewhere. These can be passed in via the
# ReplicationController spec
# If we need to allow for more complex permissions, this
# env var naming scheme (and the rest of the script) may need to be more
# complex
if [ -n "$SSH_PASSWORD" ]; then
echo "Configuring ssh: setting root password to ${SSH_PASSWORD}"
echo "root:$SSH_PASSWORD" | chpasswd
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
/usr/sbin/sshd
# Append Docker environment variables, otherwise they are not accessable to ssh users
# in any way
env | grep _ >> /etc/environment
fi
# The mnesia is in a docker volume for persistance between container starts, so
# make sure it has the right permissions (this is needed the first time the
# container runs)
chown rabbitmq:rabbitmq /var/lib/rabbitmq/mnesia
# Start the rabbitmq server and record it's PID
rabbitmq-server &
RABBIT_PID=$!
# We need to wait until the server is ready to respond to rabbitmqctl instead
# of just reporting it can't connect. Might be a quicker way by looping on
# a readonly rabbitmqctl command until it succeeds...
sleep 5
# Set up the vhost and user/pass permissions in a super basic way.
# This might need to be checked against the current production setup
# for rabbbitmq.
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD
rabbitmqctl add_vhost $RABBITMQ_VHOST
rabbitmqctl set_permissions -p $RABBITMQ_VHOST $RABBITMQ_USER ".*" ".*" ".*"
rabbitmqctl set_permissions $RABBITMQ_USER ".*" ".*" ".*"
rabbitmqctl list_permissions -p $RABBITMQ_VHOST
rabbitmqctl set_user_tags $RABBITMQ_USER administrator
# Need to wait as backgrounded processes do not stop a docker container from
# exiting.
wait ${RABBIT_PID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment