chenyc
2026-04-21 8632fbd73fdb15f22fae9cd36b9ed3e0635360f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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"