param(
|
[string]$ServiceName = "JhmGatewayService",
|
[string]$NssmPath = "nssm"
|
)
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$RootDir = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
$ExePath = Join-Path $RootDir "jhm-service.exe"
|
$ConfigPath = Join-Path $RootDir "runtime\\config.json"
|
$LogsDir = Join-Path $RootDir "logs"
|
|
if (-not (Test-Path $ExePath)) {
|
throw "Executable not found: $ExePath"
|
}
|
|
if (-not (Test-Path $ConfigPath)) {
|
throw "Config file not found: $ConfigPath"
|
}
|
|
New-Item -ItemType Directory -Force -Path $LogsDir | Out-Null
|
|
& $NssmPath install $ServiceName $ExePath "--config" $ConfigPath
|
if ($LASTEXITCODE -ne 0) {
|
throw "Failed to install service via NSSM."
|
}
|
|
& $NssmPath set $ServiceName AppDirectory $RootDir
|
& $NssmPath set $ServiceName AppStdout (Join-Path $LogsDir "service-stdout.log")
|
& $NssmPath set $ServiceName AppStderr (Join-Path $LogsDir "service-stderr.log")
|
& $NssmPath set $ServiceName AppRotateFiles 1
|
& $NssmPath set $ServiceName AppRotateOnline 1
|
& $NssmPath set $ServiceName AppRotateBytes 10485760
|
& $NssmPath start $ServiceName
|
|
Write-Host "Service installed and started: $ServiceName"
|