Skip to content

Commit

Permalink
activemq-22-04
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshanAssistanz committed Mar 3, 2023
1 parent bc1a4ce commit 85963af
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
9 changes: 9 additions & 0 deletions activemq-22-04/activemq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

mkdir -p {/usr/local/src/activemq-22-04/etc/systemd/system/,/usr/local/src/activemq-22-04/opt/cloudstack/,/usr/local/src/activemq-22-04/}

cd /usr/local/src/activemq-22-04/etc/systemd/system/ && wget https://raw.githubusercontent.com/stackbill/marketplace/main/common-files/etc/systemd/system/activemq.service

cd /usr/local/src/activemq-22-04/opt/cloudstack/ && wget https://raw.githubusercontent.com/stackbill/marketplace/main/common-files/opt/cloudstack/activemq-cleanup.sh

cd /usr/local/src/activemq-22-04/ && wget https://raw.githubusercontent.com/stackbill/marketplace/main/activemq-22-04/activemq.yaml
108 changes: 108 additions & 0 deletions activemq-22-04/activemq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
- name: ActiveMQ Setup
hosts: localhost
tasks:
- name: Restarting sshd
shell: "sed -i 's/#Match User anoncvs/ForceCommand echo Please wait until the installation is completed..../g' /etc/ssh/sshd_config && systemctl restart sshd"

- name: Updating Packages
ansible.builtin.apt:
update_cache: yes

- name: Installing Java
apt:
name: default-jdk
state: latest

- name: Creating a group for activemq
group:
name: activemq
state: present
system: yes

- name: Creating a user for activemq
ansible.builtin.user:
name: activemq
shell: /usr/sbin/nologin
groups: activemq
create_home: no
system: yes

- name: Download activemq files
ansible.builtin.unarchive:
src: https://dlcdn.apache.org/activemq/5.17.4/apache-activemq-5.17.4-bin.tar.gz
dest: /opt/
remote_src: yes

- name: Change ownership of a directory
ansible.builtin.file:
path: /opt/apache-activemq-5.17.4
state: directory
recurse: yes
owner: activemq
group: activemq

- name: Generating activemq password
shell: openssl rand -hex 24
register: activemqadminpassword

- debug:
var: activemqadminpassword.stdout

- name: Storing activemq password
copy:
dest: "/root/.activemq_admin_password"
content: |
activemq_user = admin
activemq_pass = "{{ activemqadminpassword.stdout }}"
- name: Replacing localhost in the configuration file
shell: "{{ item }}"
with_items:
- "sed -i 's/127.0.0.1/0.0.0.0/g' /opt/apache-activemq-5.17.4/conf/jetty.xml"
- "sed -i 's/admin: admin, admin/admin: {{ activemqadminpassword.stdout }}, admin/g' /opt/apache-activemq-5.17.4/conf/jetty-realm.properties"
- "sed -i 's/user: user, user//g' /opt/apache-activemq-5.17.4/conf/jetty-realm.properties"

- name: Copy files for shell script
copy:
src: "{{ item.confsrc }}"
dest: "{{ item.confdest }}"
with_items:
- { confsrc: '/usr/local/src/activemq-22-04/etc/systemd/system/activemq.service', confdest: '/etc/systemd/system/'}

- name: Reload Daemon
ansible.builtin.systemd:
daemon_reload: true

- name: Enable activemq
ansible.builtin.systemd:
name: activemq.service
state: started
enabled: true

- name: Getting the status of the service
shell: systemctl status activemq.service | grep 'since'
register: status

- debug:
var: status.stdout

- name: Creating a directory for shell script
ansible.builtin.file:
path: /opt/cloudstack
state: directory

- name: Copy files for shell script
copy:
src: "{{ item.confsrc }}"
dest: "{{ item.confdest }}"
with_items:
- { confsrc: '/usr/local/src/activemq-22-04/opt/cloudstack/activemq-cleanup.sh', confdest: '/opt/cloudstack/'}

- name: Adding a line for shell script
lineinfile:
path: /root/.bashrc
line: "chmod +x /opt/cloudstack/activemq-cleanup.sh && /opt/cloudstack/activemq-cleanup.sh"
state: present

- name: Restarting sshd
shell: "sed -i 's/ForceCommand echo Please wait until the installation is completed..../#Match User anoncvs/g' /etc/ssh/sshd_config && systemctl restart sshd"
17 changes: 17 additions & 0 deletions common-files/etc/systemd/system/activemq.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Apache ActiveMQ Message Broker
After=network-online.target

[Service]
Type=forking

User=activemq
Group=activemq

WorkingDirectory=/opt/apache-activemq-5.17.4/bin
ExecStart=/opt/apache-activemq-5.17.4/bin/activemq start
ExecStop=/opt/apache-activemq-5.17.4/bin/activemq stop
Restart=on-abort

[Install]
WantedBy=multi-user.target
38 changes: 38 additions & 0 deletions common-files/opt/cloudstack/activemq-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

RED='\033[1;31m'
NC='\033[0m'

echo -e "${RED}
################################################################################################################
# Your MarketPlace App has been deployed successfully! #
# Passwords are stored under /root/ #
################################################################################################################
${NC}"

echo
echo -e "${RED}This message will be removed in the next login!${NC}"
echo
echo
echo -e "${RED}Refer to the ActiveMQ Admin Credentials${NC}"
echo
cat /root/.activemq_admin_password
echo


#Cleanup script
rm -rf /usr/local/src/
mkdir -p /usr/local/src/
rm -rf /var/lib/cloud/instances/*
rm -rf /var/lib/cloud/data/*
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \; >/dev/null 2>&1
rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp
apt-get -y autoremove >/dev/null 2>&1
apt-get -y autoclean >/dev/null 2>&1
history -c
cat /dev/null > /root/.bash_history
unset HISTFILE

rm -rf /root/.bashrc
cp /etc/skel/.bashrc /root

0 comments on commit 85963af

Please sign in to comment.