Skip to content

Instantly share code, notes, and snippets.

@karthik20522
Created May 24, 2019 08:18
Show Gist options
  • Save karthik20522/fe2152b8115f601d5a1d59c8fc2d1c19 to your computer and use it in GitHub Desktop.
Save karthik20522/fe2152b8115f601d5a1d59c8fc2d1c19 to your computer and use it in GitHub Desktop.
Trivial bash script for upgrading RabbitMQ service
function check_rmq_version {
rmq_version=$(sudo rabbitmqctl status | grep "rabbit," | cut -d',' -f3 | cut -d'}' -f1 | tr -d '"')
echo && echo " Version = $rmq_version" && echo
}
function stop_rmq {
echo "Stopping RabbitMQ..."
sudo service rabbitmq-server stop
}
function kill_erlang {
echo "Killing stray RMQ/erlang processes..."
#pids=$(ps -fe | grep erlang | grep rabbitmq | awk '{ print $2 }')
#echo $pids
pgrep -u rabbitmq -x beam | xargs kill -9 || echo && echo " RabbitMQ already stopped"
echo
}
function upgrade_rmq_version {
echo "Changing directory to /tmp..."
cd /tmp
echo
echo "wgetting RabbitMQ .rpm file from official website..."
url="http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.3/rabbitmq-server-3.4.3-1.noarch.rpm"
wget $url
echo
echo "Validating signature..."
url="http://www.rabbitmq.com/rabbitmq-signing-key-public.asc"
sudo rpm --import $url
echo
echo "Upgrading RabbitMQ version..."
file="rabbitmq-server-3.4.3-1.noarch.rpm"
sudo yum install $file
echo
}
function start_rmq {
echo "Starting RabbitMQ"
sudo service rabbitmq-server start
}
function main {
check_rmq_version # Checking the current version of RabbitMQ
stop_rmq # Stopping the rabbitmq-server service
kill_erlang # Killing erlang to ensure RMQ is stopped
upgrade_rmq_version # Upgrading RabbitMQ
start_rmq # Starting the rabbitmq-server service
check_rmq_version # Checking the current version of RabbitMQ
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment