Skip to content

Instantly share code, notes, and snippets.

@jspw
Last active January 1, 2024 08:41
Show Gist options
  • Select an option

  • Save jspw/532731d1c3fc54aba9aa71a2814bdbb7 to your computer and use it in GitHub Desktop.

Select an option

Save jspw/532731d1c3fc54aba9aa71a2814bdbb7 to your computer and use it in GitHub Desktop.
Automate installing and configuration for Apache Message Queue using a bash script in Linux based machines. Just run `sudo ./install_apache_active_mq_5.17.1.sh`.
#!/bin/bash
# whoami -> MH Shifat | https://github.com/jspw
# date -> Mon 30 May 2022 11:06:52 PM +06
GREETINGS="Welcome to the Active MQ installer\n\n\n"
ACTIVE_MQ_DOWNLOAD_URL="http://archive.apache.org/dist/activemq/5.17.1/apache-activemq-5.17.1-bin.tar.gz"
echo $GREETINGS
printf "Downloading Active MQ...\n\n\n"
wget $ACTIVE_MQ_DOWNLOAD_URL
# split filename from url
ACTIVE_MQ_DOWNLOAD_FILENAME=$(basename $ACTIVE_MQ_DOWNLOAD_URL) # apache-activemq-5.17.1-bin.tar.gz
echo "Extracting $ACTIVE_MQ_DOWNLOAD_FILENAME"
sudo tar -xvzf $ACTIVE_MQ_DOWNLOAD_FILENAME
DIRECTORY_FOR_A_MQ="/opt/activemq"
echo "Creating directory for ActiveMQ : "$DIRECTORY_FOR_A_MQ
sudo mkdir $DIRECTORY_FOR_A_MQ
# split file extract directory name
ACTIVE_MQ_DIRECTORY_NAME=$(basename $ACTIVE_MQ_DOWNLOAD_FILENAME -bin.tar.gz) # apache-activemq-5.17.1
printf "Moving $ACTIVE_MQ_DIRECTORY_NAME to $DIRECTORY_FOR_A_MQ"
FULL_DIR=$ACTIVE_MQ_DIRECTORY_NAME/*
sudo mv $FULL_DIR $DIRECTORY_FOR_A_MQ
printf "Create a group account activemq to run Apache ActiveMQ...\n\n\n"
sudo addgroup --quiet --system
printf "Create a user for the group...\n\n\n"
sudo adduser --quiet --system --ingroup activemq --no-create-home --disabled-password activemq
printf "Change the permissions of the /opt/activemq directory...\n\n\n"
sudo chown -R activemq:activemq /opt/activemq
CODE="
[Unit]\n
Description=Apache ActiveMQ\n
After=network.target\n
[Service]\n
Type=forking\n
User=activemq\n
Group=activemq\n
ExecStart=/opt/activemq/bin/activemq start\n
ExecStop=/opt/activemq/bin/activemq stop\n
[Install]\n
WantedBy=multi-user.target\n
"
printf "Creating a service file for Apache ActiveMQ...\n\n\n"
sudo echo -e "$CODE" > /etc/systemd/system/activemq.service
# replace `<property name="host" value="0.0.0.0"/>` with `<property name="host" value="127.0.0.1"/>`
printf "Configuring Apache ActiveMQ on host '0.0.0.0' ...\n\n\n"
sed -i 's+<property name="host" value="127.0.0.1"/>+<property name="host" value="0.0.0.0"/>+g' /opt/activemq/conf/jetty.xml
printf "Starting Apache ActiveMQ...\n\n\n"
sudo systemctl daemon-reload
sudo systemctl start activemq
sudo systemctl enable activemq
sudo systemctl status activemq
sudo systemctl restart activemq
printf "ActiveMQ is installed successfully\n\n\n"
printf "Goto http://localhost:8161/admin/ to check with username:admin & password:admin\n\n\n"
#!/bin/bash
# whoami -> MH Shifat | https://github.com/jspw
# date -> Mon 30 May 2022 11:06:52 PM +06
sudo systemctl daemon-reload
sudo systemctl start activemq
sudo systemctl enable activemq
sudo systemctl status activemq
sudo systemctl restart activemq
sudo rm -rf /opt/activemq
sudo rm -rf /etc/systemd/system/activemq.service
@jspw
Copy link
Author

jspw commented Jan 1, 2024

actual commands:

  1. wget http://archive.apache.org/dist/activemq/5.16.3/apache-activemq-5.16.3-bin.tar.gz
  2. sudo tar -xvzf apache-activemq-5.16.3-bin.tar.gz
  3. sudo mkdir /opt/activemq && sudo mv apache-activemq-5.16.3/* /opt/activemq
  4. sudo addgroup --quiet --system activemq
  5. sudo adduser --quiet --system --ingroup activemq --no-create-home --disabled-password activemq
  6. sudo chown -R activemq:activemq /opt/activemq
  7. sudo nano /etc/systemd/system/activemq.service
          [Unit]
          Description=Apache ActiveMQ
          After=network.target
          
          [Service]
          Type=forking
          User=activemq
          Group=activemq
          ExecStart=/opt/activemq/bin/activemq start
          ExecStop=/opt/activemq/bin/activemq stop
          
          [Install]
          WantedBy=multi-user.target
    
  8. sudo systemctl daemon-reload
  9. sudo systemctl start activemq
  10. sudo systemctl enable activemq
  11. sudo systemctl status activemq
    ● activemq.service - Apache ActiveMQ
         Loaded: loaded (/etc/systemd/system/activemq.service; enabled; vendor preset: enabled)
         Active: active (running) since Mon 2024-01-01 07:08:10 UTC; 39min ago
       Main PID: 1551593 (java)
          Tasks: 57 (limit: 38375)
         Memory: 212.3M
            CPU: 10.539s
         CGroup: /system.slice/activemq.service
                 └─1551593 /usr/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/opt/activemq//conf/login.config -Dcom.sun.management.jmxremote >
    
    Jan 01 07:08:10 ca-infopub-st-01 systemd[1]: Starting Apache ActiveMQ...
    Jan 01 07:08:10 ca-infopub-st-01 activemq[1551535]: INFO: Loading '/opt/activemq//bin/env'
    Jan 01 07:08:10 ca-infopub-st-01 activemq[1551535]: INFO: Using java '/usr/bin/java'
    Jan 01 07:08:10 ca-infopub-st-01 activemq[1551535]: INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
    Jan 01 07:08:10 ca-infopub-st-01 activemq[1551592]: INFO: pidfile created : '/opt/activemq//data/activemq.pid' (pid '1551593')
    Jan 01 07:08:10 ca-infopub-st-01 systemd[1]: Started Apache ActiveMQ.
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment