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.

#!/bin/bash
#Inputs: 1 is ARM key 2 is server name to register

sudo service $2 stop
!/bin/bash
#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
done
tail logs/mule_ee.log

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

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

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

#download and install mule Agent
cd bin
sudo -u mule wget "http://mule-agent.s3.amazonaws.com/1.6.1/agent-setup-1.6.1.zip"
sudo -u mule unzip -o agent-setup-1.6.1.zip
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"
else
sleep 10s
sudo service $2 start
fi