Skip to content

Instantly share code, notes, and snippets.

@epochcoder
Created September 6, 2017 12:54
Show Gist options
  • Save epochcoder/889b16ccbb1f65deaf58f926000736cf to your computer and use it in GitHub Desktop.
Save epochcoder/889b16ccbb1f65deaf58f926000736cf to your computer and use it in GitHub Desktop.
Installs ActiveMQ as a service on an Ubuntu system
#!/usr/bin/env bash
function downloadCacheCopy() {
local name="$1"
local file_dir="$2"
local url="$3"
local location="$4"
local is_tar="$5"
echo "Preparing $name"
if [ ! -f "/tmp/$file_dir" ] && [ ! -d "/tmp/$file_dir" ]; then
echo " -> Downloading $name"
if [ -z "${is_tar}" ]; then
pushd /tmp && curl --silent -O -L "$url" && popd
else
wget -qO- "$url" | sudo tar -xz -C "/tmp"
fi
fi
sudo cp -a "/tmp/$file_dir" "$location"
echo " -> Copied $file_dir to $location"
}
ACTIVE_MQ_VERSION=5.13.3
ACTIVE_MQ_LOCATION=/opt/activemq
echo "Creating ActiveMQ ${ACTIVE_MQ_VERSION} Server @ ${ACTIVE_MQ_LOCATION}"
# download and extract
DL_ACTIVE_MQ="https://archive.apache.org/dist/activemq/${ACTIVE_MQ_VERSION}/apache-activemq-${ACTIVE_MQ_VERSION}-bin.tar.gz"
downloadCacheCopy "ActiveMQ" "apache-activemq-${ACTIVE_MQ_VERSION}" "${DL_ACTIVE_MQ}" "$ACTIVE_MQ_LOCATION" "tar"
# copy custom config
if [ -d templates/activemq/conf/ ]; then
echo "Copying custom ActiveMQ configuration to ${ACTIVE_MQ_LOCATION}/conf"
sudo cp -R templates/activemq/conf/. "${ACTIVE_MQ_LOCATION}/conf/"
fi
# add user for activemq
sudo adduser --system activemq --ingroup users
sudo chown -R activemq:users "${ACTIVE_MQ_LOCATION}"
# default config
sudo cp "${ACTIVE_MQ_LOCATION}/bin/env" /etc/default/activemq
sudo sed -i 's/^ACTIVEMQ_USER=""/ACTIVEMQ_USER="activemq"/' /etc/default/activemq
sudo chmod 644 /etc/default/activemq
# link & install service
sudo ln -snf "${ACTIVE_MQ_LOCATION}/bin/activemq" /etc/init.d/activemq
sudo update-rc.d activemq defaults
# start service
sudo systemctl start activemq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment