From 85963af348c902ad5d61632fbc2c8c463f8b99b5 Mon Sep 17 00:00:00 2001 From: RoshanAssistanz Date: Fri, 3 Mar 2023 12:48:02 +0530 Subject: [PATCH] activemq-22-04 --- activemq-22-04/activemq.sh | 9 ++ activemq-22-04/activemq.yaml | 108 ++++++++++++++++++ .../etc/systemd/system/activemq.service | 17 +++ .../opt/cloudstack/activemq-cleanup.sh | 38 ++++++ 4 files changed, 172 insertions(+) create mode 100644 activemq-22-04/activemq.sh create mode 100644 activemq-22-04/activemq.yaml create mode 100644 common-files/etc/systemd/system/activemq.service create mode 100644 common-files/opt/cloudstack/activemq-cleanup.sh diff --git a/activemq-22-04/activemq.sh b/activemq-22-04/activemq.sh new file mode 100644 index 0000000..93fcec0 --- /dev/null +++ b/activemq-22-04/activemq.sh @@ -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 diff --git a/activemq-22-04/activemq.yaml b/activemq-22-04/activemq.yaml new file mode 100644 index 0000000..eefdbcb --- /dev/null +++ b/activemq-22-04/activemq.yaml @@ -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" \ No newline at end of file diff --git a/common-files/etc/systemd/system/activemq.service b/common-files/etc/systemd/system/activemq.service new file mode 100644 index 0000000..b3994cb --- /dev/null +++ b/common-files/etc/systemd/system/activemq.service @@ -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 \ No newline at end of file diff --git a/common-files/opt/cloudstack/activemq-cleanup.sh b/common-files/opt/cloudstack/activemq-cleanup.sh new file mode 100644 index 0000000..61a9cd7 --- /dev/null +++ b/common-files/opt/cloudstack/activemq-cleanup.sh @@ -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 \ No newline at end of file