Automating JBoss Installation on AWS EC2 Instance with User Data Script

 


This script automates the installation and configuration of JBoss EAP on an AWS EC2 instance, ensuring that all necessary components are installed, configured, and managed as a service. By using this script as user data when launching an EC2 instance, you can streamline the deployment of JBoss EAP in your environment

The Script

Here's the complete script:


#!/bin/bash

# Create directory for JBoss packages

sudo mkdir -p /opt/jboss/package


# Sync JBoss package from S3

aws s3 sync s3://jboss-package /opt/jboss/package


# Ensure that your Yum repository metadata is up to date

sudo yum clean all

sudo yum makecache


# Install JAVA 1.8 (Amazon Corretto)

sudo yum -y install java-1.8.0-amazon-corretto.x86_64


# Update the system

sudo yum -y update


# Change to the JBoss package directory

cd /opt/jboss/package


# Verify that the installer and XML configuration files exist

if [ -f "/opt/jboss/package/jboss-eap-7.4.0-installer.jar" ] && [ -f "/opt/jboss/package/auto.xml" ]; then

    echo "Installer and configuration files found. Starting the JBoss installation..."

else

    echo "Installer or configuration file not found. Exiting..."

    exit 1

fi


# Ensure installer is executable

sudo chmod +x /opt/jboss/package/jboss-eap-7.4.0-installer.jar


# Run the JBoss installer with the provided XML configuration and log output

sudo java -jar /opt/jboss/package/jboss-eap-7.4.0-installer.jar /opt/jboss/package/auto.xml > /var/log/jboss-install.log 2>&1


# Check if JBoss installation was successful

if grep -q "JBoss EAP installation complete" /var/log/jboss-install.log; then

    echo "JBoss EAP installation was successful."

else

    echo "JBoss EAP installation failed. Check /var/log/jboss-install.log for details."

    exit 1

fi


# Optional: Set up JBoss as a service and start it

sudo bash -c 'cat <<EOF > /etc/systemd/system/jboss.service

[Unit]

Description=JBoss EAP

After=network.target


[Service]

Type=simple

User=root

ExecStart=/opt/jboss/jboss-eap-7.4/bin/standalone.sh

Restart=on-failure


[Install]

WantedBy=multi-user.target

EOF'


# Reload systemd to apply the new service

sudo systemctl daemon-reload


# Enable and start the JBoss service

sudo systemctl enable jboss.service

sudo systemctl start jboss.service



Script Breakdown

Let's go through the script step by step:

  1. Creating Directory for JBoss Packages:

    sudo mkdir -p /opt/jboss/package

    This command creates the directory /opt/jboss/package where the JBoss installer and related files will be stored.

  2. Syncing JBoss Package from S3:

    aws s3 sync s3://jboss-package /opt/jboss/package

    This command syncs the contents of the specified S3 bucket (s3://jboss-package) to the local directory /opt/jboss/package.

  3. Updating Yum Repository Metadata:

    sudo yum clean all
    sudo yum makecache

    These commands ensure that the Yum package manager's metadata is up to date.

  4. Installing Java 1.8 (Amazon Corretto):

    sudo yum -y install java-1.8.0-amazon-corretto.x86_64

    This command installs Amazon Corretto 1.8, a no-cost, multiplatform, production-ready distribution of the Open Java Development Kit (OpenJDK).

  5. Updating the System:

    sudo yum -y update

    This command updates all installed packages to their latest versions.

  6. Changing to the JBoss Package Directory:

    cd /opt/jboss/package

    This command changes the working directory to /opt/jboss/package.

  7. Verifying the Installer and Configuration Files:

    if [ -f "/opt/jboss/package/jboss-eap-7.4.0-installer.jar" ] && [ -f "/opt/jboss/package/auto.xml" ]; then
    echo "Installer and configuration files found. Starting the JBoss installation..." else echo "Installer or configuration file not found. Exiting..." exit 1 fi

    This block checks if the jboss-eap-7.4.0-installer.jar and auto.xml files exist. If they do, it proceeds with the installation; otherwise, it exits with an error message.

  8. Ensuring the Installer is Executable:

    sudo chmod +x /opt/jboss/package/jboss-eap-7.4.0-installer.jar

    This command makes the JBoss installer executable.

  9. Running the JBoss Installer and Logging Output:

    sudo java -jar /opt/jboss/package/jboss-eap-7.4.0-installer.jar /opt/jboss/package/auto.xml > /var/log/jboss-install.log 2>&1

    This command runs the JBoss installer with the provided XML configuration file and logs the output to /var/log/jboss-install.log.

  10. Checking Installation Success:

    if grep -q "JBoss EAP installation complete" /var/log/jboss-install.log; then
    echo "JBoss EAP installation was successful." else echo "JBoss EAP installation failed. Check /var/log/jboss-install.log for details." exit 1 fi

    This block checks the log file for a success message. If found, it confirms the installation was successful; otherwise, it exits with an error message.

  11. Setting Up JBoss as a System Service:

    sudo bash -c 'cat <<EOF > /etc/systemd/system/jboss.service
    [Unit] Description=JBoss EAP After=network.target [Service] Type=simple User=root ExecStart=/opt/jboss/jboss-eap-7.4/bin/standalone.sh Restart=on-failure [Install] WantedBy=multi-user.target EOF'

    This block creates a systemd service file for JBoss, enabling it to be managed as a service.

  12. Reloading systemd and Starting JBoss Service:

    sudo systemctl daemon-reload sudo systemctl enable jboss.service sudo systemctl start jboss.service

    These commands reload the systemd manager configuration, enable the JBoss service to start on boot, and start the JBoss service.

.

Comments

Popular posts from this blog

SSL certificate in WebSphere Application Server

Tomcat Upgrade Steps on Windows.