#!/bin/bash

# Load environment variables from .env file
if [ -f .env ]; then
    source .env
else
    echo ".env file not found. Please create one with JBOSS_HOME and JAVA_HOME variables."
    exit 1
fi

# Check if required environment variables are set
if [ -z "$JBOSS_HOME" ] || [ -z "$JAVA_HOME" ]; then
    echo "JBOSS_HOME or JAVA_HOME is not set. Please check your .env file."
    exit 1
fi

# Imposta la variabile di ambiente per Java
export PATH="$JAVA_HOME/bin:$PATH"

echo JAVA_HOME = $JAVA_HOME
echo JBOSS_HOME = $JBOSS_HOME

# Controlla se JBoss è già in esecuzione
if grep -f "$JBOSS_HOME" > /dev/null; then
    echo "JBoss è già in esecuzione"
else
    echo "Avvio di JBoss con standalone-full-stub.xml"
    nohup "$JBOSS_HOME/bin/standalone.sh" -c ../../stub-war/standalone/standalone-full.xml > /dev/null 2>&1 &
fi
