Skip to content

Instantly share code, notes, and snippets.

@bittner
Last active March 17, 2017 16:47
Show Gist options
  • Save bittner/5b3d23bc19d7836c8639ad2c1962070a to your computer and use it in GitHub Desktop.
Save bittner/5b3d23bc19d7836c8639ad2c1962070a to your computer and use it in GitHub Desktop.
DjangoEurope: Celery + RabbitMQ
#!/bin/bash
#
# RabbitMQ setup for DjangoEurope
# (c) 2017 Peter Bittner <django@bittner.it>
# based on instruction provided by DjangoEurope
# MIT license
RABBITMQ_HOME=$HOME/rabbitmq
RABBITMQ_ENV=$HOME/.rabbitmq_env
RABBITMQ_NODE_PORT=62024
RABBITMQ_MGMT_PORT=62025
RABBITMQ_EPMD_PORT=62026
UNPACK_DIR=/tmp/$USER
RABBITMQ_PRODUCT=rabbitmq-server
RABBITMQ_VERSION=3.6.7
RABBITMQ_PACKAGE=$RABBITMQ_PRODUCT-generic-unix-$RABBITMQ_VERSION
RABBITMQ_FOLDER=rabbitmq_server-$RABBITMQ_VERSION
RABBITMQ_ARCHIVE=$RABBITMQ_PACKAGE.tar.xz
RABBITMQ_DOWNLOAD=https://www.rabbitmq.com/releases/$RABBITMQ_PRODUCT/v$RABBITMQ_VERSION/$RABBITMQ_ARCHIVE
mkdir -p $UNPACK_DIR && \
cd $UNPACK_DIR && \
wget $RABBITMQ_DOWNLOAD && \
tar xfJ $RABBITMQ_ARCHIVE && \
rm -rf $RABBITMQ_HOME && mv $UNPACK_DIR/$RABBITMQ_FOLDER $RABBITMQ_HOME && \
mkdir $RABBITMQ_HOME/{log,run} && \
echo "RabbitMQ successfully installed in $RABBITMQ_HOME"
echo "Cleaning up ..."
rm -v $UNPACK_DIR/$RABBITMQ_ARCHIVE*
rmdir $UNPACK_DIR
echo "Preparing local configuration ..."
touch $RABBITMQ_HOME/etc/rabbitmq/rabbitmq-env.conf
touch $RABBITMQ_HOME/etc/rabbitmq/rabbitmq.config
echo "Assuming 3 local ports were created in the control panel for RabbitMQ: $RABBITMQ_NODE_PORT, $RABBITMQ_MGMT_PORT, $RABBITMQ_EPMD_PORT"
echo "NOTE: If port numbers don't match edit them in the head of this script. $0"
echo "export PATH=$RABBITMQ_HOME/sbin:\$PATH" > $RABBITMQ_ENV
echo "export RABBITMQ_NODENAME=$USER@localhost" >> $RABBITMQ_ENV
echo "export RABBITMQ_NODE_IP_ADDRESS=127.0.0.1" >> $RABBITMQ_ENV
echo "export RABBITMQ_NODE_PORT=$RABBITMQ_NODE_PORT" >> $RABBITMQ_ENV
echo "export RABBITMQ_CONFIG_FILE=$HOME/rabbitmq/etc/rabbitmq.config" >> $RABBITMQ_ENV
echo "export RABBITMQ_MNESIA_BASE=$HOME/rabbitmq/mnesia" >> $RABBITMQ_ENV
echo "export RABBITMQ_PID_FILE=$HOME/rabbitmq/run/pid" >> $RABBITMQ_ENV
echo "export RABBITMQ_LOG_BASE=$HOME/rabbitmq/log" >> $RABBITMQ_ENV
echo 'export RABBITMQ_SERVER_START_ARGS="' >> $RABBITMQ_ENV
echo ' -rabbitmq_management listener [{port,'$RABBITMQ_MGMT_PORT'},{ip, 127.0.0.1}]' >> $RABBITMQ_ENV
echo ' -kernel inet_dist_use_interface {127,0,0,1}' >> $RABBITMQ_ENV
echo ' -kernel inet_dist_listen_min '$RABBITMQ_MGMT_PORT >> $RABBITMQ_ENV
echo ' -kernel inet_dist_listen_max '$RABBITMQ_MGMT_PORT >> $RABBITMQ_ENV
echo ' +K true +A 1 +S 1:1 +sct L0-0c0-0 -smp disable' >> $RABBITMQ_ENV
echo '"' >> $RABBITMQ_ENV
echo "export ERL_EPMD_ADDRESS=127.0.0.1" >> $RABBITMQ_ENV
echo "export ERL_EPMD_PORT=$RABBITMQ_EPMD_PORT" >> $RABBITMQ_ENV
echo "export CELERYD_CONCURRENCY=1" >> $RABBITMQ_ENV
echo "export CELERYD_PREFETCH_MULTIPLIE=1" >> $RABBITMQ_ENV
echo "Environment file $RABBITMQ_ENV created."
RABBITMQ_INIT=~/init/rabbitmq-server
wget https://templates.wservices.ch/rabbitmq-server -O $RABBITMQ_INIT
chmod 755 $RABBITMQ_INIT
echo "Init script $RABBITMQ_INIT created."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment