Registering a server with Anypoint Runtime Manager is an arduous task if you do it anymore than once or twice. Here’s a script you can execute from a CI tool like Jenkins to register a server with ARM.

It takes two inputs. The ARM registration key, you get this from the “Add Server” button on ARM. And the name you want to give the server

We had two options for the mule installation directory depending on our Chef cookbook used, mule-gateway, and mule-esb, so look out for that.

#Inputs: 1 is ARM key 2 is server name to register

sudo service $2 stop
#Inputs: 1 is ARM key 2 is server name to register

sudo service $2 stop
cd /usr/local
#waits for mule to stop entirely [m]ule is a trick to not get the grep
#command to show up in results
while ps -eaf | grep -q "[m]ule " ; do
echo "Waiting for Mule To stop"
sleep .5
tail logs/mule_ee.log

if [ -d "mule-esb" ]; then
cd mule-esb
elif [ -d "mule-gateway" ]; then
cd mule-gateway
cd mule

#if the server is registered, delete the registration
if [ -f conf/mule-agent.yml ]; then
sudo rm conf/mule-agent.yml

#Check to see if the domains directory exists, will cause error if it doesn't
if [ -d "domains/default" ]; then
echo "default exists"
sudo -u mule mkdir domains/default

#download and install mule Agent
cd bin
sudo -u mule wget ""
sudo -u mule unzip -o
sudo -u mule ./amc_setup -U

#Do the registration 1 is key 2 is server name
sudo -u mule ./amc_setup -H $1 $2
if [ $? -ne 0 ]; then
echo "error with amcsetup"
sleep 10s
sudo service $2 start