chore: add Windows build and service scripts
This commit is contained in:
31
scripts/build.ps1
Normal file
31
scripts/build.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
param(
|
||||
[string]$OutputDir = "dist",
|
||||
[string]$BinaryName = "lingma-ipc-proxy.exe",
|
||||
[switch]$Clean
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$distDir = Join-Path $repoRoot $OutputDir
|
||||
$binaryPath = Join-Path $distDir $BinaryName
|
||||
|
||||
if ($Clean -and (Test-Path $distDir)) {
|
||||
Remove-Item -Recurse -Force $distDir
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force $distDir | Out-Null
|
||||
|
||||
Push-Location $repoRoot
|
||||
try {
|
||||
$env:CGO_ENABLED = "0"
|
||||
$env:GOOS = "windows"
|
||||
$env:GOARCH = "amd64"
|
||||
|
||||
Write-Host "Building $binaryPath"
|
||||
go build -trimpath -ldflags "-s -w" -o $binaryPath .\cmd\lingma-ipc-proxy
|
||||
Write-Host "Build completed: $binaryPath"
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
32
scripts/install-nssm-service.ps1
Normal file
32
scripts/install-nssm-service.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
param(
|
||||
[string]$ServiceName = "LingmaIpcProxy",
|
||||
[string]$BinaryPath = "",
|
||||
[string]$Arguments = "--host 127.0.0.1 --port 8095 --session-mode auto",
|
||||
[string]$WorkingDirectory = "",
|
||||
[string]$NssmPath = "nssm.exe",
|
||||
[string]$Description = "Lingma IPC proxy service"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($BinaryPath)) {
|
||||
$BinaryPath = Join-Path $repoRoot "dist\lingma-ipc-proxy.exe"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($WorkingDirectory)) {
|
||||
$WorkingDirectory = $repoRoot
|
||||
}
|
||||
|
||||
if (!(Test-Path $BinaryPath)) {
|
||||
throw "Binary not found: $BinaryPath"
|
||||
}
|
||||
|
||||
Write-Host "Installing NSSM service: $ServiceName"
|
||||
& $NssmPath install $ServiceName $BinaryPath $Arguments
|
||||
& $NssmPath set $ServiceName AppDirectory $WorkingDirectory
|
||||
& $NssmPath set $ServiceName Description $Description
|
||||
& $NssmPath set $ServiceName Start SERVICE_AUTO_START
|
||||
|
||||
Write-Host "Service installed. Start with:"
|
||||
Write-Host " $NssmPath start $ServiceName"
|
||||
59
scripts/install-winsw-service.ps1
Normal file
59
scripts/install-winsw-service.ps1
Normal file
@@ -0,0 +1,59 @@
|
||||
param(
|
||||
[string]$ServiceName = "LingmaIpcProxy",
|
||||
[string]$BinaryPath = "",
|
||||
[string]$Arguments = "--host 127.0.0.1 --port 8095 --session-mode auto",
|
||||
[string]$WorkingDirectory = "",
|
||||
[string]$WinSWExePath = "",
|
||||
[string]$TemplatePath = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($BinaryPath)) {
|
||||
$BinaryPath = Join-Path $repoRoot "dist\lingma-ipc-proxy.exe"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($WorkingDirectory)) {
|
||||
$WorkingDirectory = $repoRoot
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($WinSWExePath)) {
|
||||
$WinSWExePath = Join-Path $repoRoot "dist\WinSW-x64.exe"
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($TemplatePath)) {
|
||||
$TemplatePath = Join-Path $PSScriptRoot "lingma-ipc-proxy.xml.template"
|
||||
}
|
||||
|
||||
if (!(Test-Path $BinaryPath)) {
|
||||
throw "Binary not found: $BinaryPath"
|
||||
}
|
||||
if (!(Test-Path $WinSWExePath)) {
|
||||
throw "WinSW executable not found: $WinSWExePath"
|
||||
}
|
||||
if (!(Test-Path $TemplatePath)) {
|
||||
throw "WinSW template not found: $TemplatePath"
|
||||
}
|
||||
|
||||
$serviceExePath = Join-Path $repoRoot "$ServiceName.exe"
|
||||
$serviceXmlPath = Join-Path $repoRoot "$ServiceName.xml"
|
||||
|
||||
$xml = Get-Content -Raw $TemplatePath
|
||||
$xml = $xml.Replace("__SERVICE_ID__", $ServiceName)
|
||||
$xml = $xml.Replace("__SERVICE_NAME__", $ServiceName)
|
||||
$xml = $xml.Replace("__SERVICE_DESCRIPTION__", "Lingma IPC proxy service")
|
||||
$xml = $xml.Replace("__EXECUTABLE__", $BinaryPath)
|
||||
$xml = $xml.Replace("__ARGUMENTS__", $Arguments)
|
||||
$xml = $xml.Replace("__WORKDIR__", $WorkingDirectory)
|
||||
$xml = $xml.Replace("__LOGDIR__", (Join-Path $repoRoot "logs"))
|
||||
|
||||
Copy-Item -Force $WinSWExePath $serviceExePath
|
||||
Set-Content -Path $serviceXmlPath -Value $xml
|
||||
|
||||
Write-Host "Prepared WinSW service wrapper:"
|
||||
Write-Host " $serviceExePath"
|
||||
Write-Host " $serviceXmlPath"
|
||||
Write-Host ""
|
||||
Write-Host "Install with:"
|
||||
Write-Host " & `"$serviceExePath`" install"
|
||||
Write-Host "Start with:"
|
||||
Write-Host " & `"$serviceExePath`" start"
|
||||
15
scripts/lingma-ipc-proxy.xml.template
Normal file
15
scripts/lingma-ipc-proxy.xml.template
Normal file
@@ -0,0 +1,15 @@
|
||||
<service>
|
||||
<id>__SERVICE_ID__</id>
|
||||
<name>__SERVICE_NAME__</name>
|
||||
<description>__SERVICE_DESCRIPTION__</description>
|
||||
<executable>__EXECUTABLE__</executable>
|
||||
<arguments>__ARGUMENTS__</arguments>
|
||||
<workingdirectory>__WORKDIR__</workingdirectory>
|
||||
<logpath>__LOGDIR__</logpath>
|
||||
<log mode="roll-by-size">
|
||||
<sizeThreshold>10485760</sizeThreshold>
|
||||
<keepFiles>5</keepFiles>
|
||||
</log>
|
||||
<startmode>Automatic</startmode>
|
||||
<stoptimeout>15sec</stoptimeout>
|
||||
</service>
|
||||
Reference in New Issue
Block a user