test-adv/start-jboss.ps1
Gaetano Savo cc13f6eac1 pulizia
2025-04-08 17:06:22 +02:00

105 lines
3.7 KiB
PowerShell

# PowerShell script to start JBoss EAP 7.4
# Load configuration from JSON file
$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json
# Configuration variables from JSON
$JBOSS_HOME = $config.jbossHome
$JAVA_HOME = $config.javaHome
# Function to check if JBoss is already running
function Test-JBossRunning {
$jbossProcess = Get-CimInstance Win32_Process -Filter "Name = 'java.exe'" |
Where-Object { $_.CommandLine -like "*jboss.home.dir=$JBOSS_HOME*" }
return $null -ne $jbossProcess
}
# Check if Java exists
if (-not (Test-Path $JAVA_HOME)) {
Write-Host "Error: Java 8 not found at $JAVA_HOME" -ForegroundColor Red
exit 1
}
# Check if JBoss directory exists
if (-not (Test-Path $JBOSS_HOME)) {
Write-Host "Error: JBoss directory not found at $JBOSS_HOME" -ForegroundColor Red
exit 1
}
# Set environment variables
$env:JAVA_HOME = $JAVA_HOME
$env:JBOSS_HOME = $JBOSS_HOME
$env:PATH = "$JAVA_HOME\bin;$env:PATH"
$env:NOPAUSE = "true"
# Remove this as it might affect logging
# $env:LAUNCH_JBOSS_IN_BACKGROUND = "true"
# Set configuration file
$configFile = "standalone-ADVC-full.xml"
# Copy configuration file from local config directory
$sourceConfig = "$PSScriptRoot\config\$configFile"
$targetConfig = "$JBOSS_HOME\standalone\configuration\$configFile"
if (Test-Path $sourceConfig) {
Write-Host "Copying configuration file from $sourceConfig to $targetConfig" -ForegroundColor Yellow
Copy-Item -Path $sourceConfig -Destination $targetConfig -Force
}
# Check if JBoss is already running
if (Test-JBossRunning) {
Write-Host "JBoss is already running!" -ForegroundColor Yellow
exit 0
}
Write-Host "Starting JBoss EAP 7.4..." -ForegroundColor Green
Write-Host "Using Java from: $JAVA_HOME" -ForegroundColor Yellow
Write-Host "JBoss Home: $JBOSS_HOME" -ForegroundColor Yellow
Write-Host "Using configuration: $configFile" -ForegroundColor Yellow
# Set JVM options
$jvmOpts = @(
"-DIDServer=GS",
"-Dbtf.PathToParse=C:\Dev2012\advc0\in",
"-Djava.awt.headless=true",
"-DFilOptimize=true",
"-DMTH_VALID_JB=internal",
"-DskQueueElab=GS",
"-DskQueueWrite=GS",
"-DmtSession=GS",
"-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
)
Write-Host "Starting JBoss with custom JVM options..." -ForegroundColor Yellow
Write-Host "JVM Options: $($jvmOpts -join ' ')" -ForegroundColor Gray
# Create the command line arguments
$cmdArgs = "-c $configFile --debug -b 0.0.0.0 -bmanagement 0.0.0.0"
# Start JBoss - Modified to use Start-Process with RedirectStandardOutput
$logFile = Join-Path $JBOSS_HOME "standalone\log\server.log"
$processStartInfo = @{
FilePath = Join-Path $JBOSS_HOME "bin\standalone.bat"
ArgumentList = $cmdArgs
RedirectStandardOutput = $logFile
RedirectStandardError = Join-Path $JBOSS_HOME "standalone\log\server_error.log"
WorkingDirectory = Join-Path $JBOSS_HOME "bin"
NoNewWindow = $true
PassThru = $true
}
Write-Host "Remote debugging enabled on port 8787" -ForegroundColor Yellow
Write-Host "Starting JBoss and redirecting output to $logFile" -ForegroundColor Yellow
$jbossProcess = Start-Process @processStartInfo
# Wait a few seconds to check if the process started successfully
Start-Sleep -Seconds 10
if (Test-JBossRunning) {
Write-Host "JBoss started successfully!" -ForegroundColor Green
Write-Host "Admin console will be available at: http://localhost:9990" -ForegroundColor Yellow
Write-Host "Remote debugging is enabled on port 8787" -ForegroundColor Cyan
Write-Host "Check JBoss logs at: $logFile" -ForegroundColor Yellow
} else {
Write-Host "Error: JBoss failed to start. Check the logs at: $logFile" -ForegroundColor Red
}