feat: add Windows hbc client with PyInstaller spec and NSSM install script
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
|||||||
|
# PyInstaller spec for hbc_windows.exe
|
||||||
|
# Build with: pyinstaller hbc_windows.spec
|
||||||
|
#
|
||||||
|
# Requirements (on Windows):
|
||||||
|
# pip install pyinstaller
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['hbc_windows.py'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=[],
|
||||||
|
datas=[],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=['tkinter', 'unittest', 'email', 'html', 'http', 'urllib', 'xml'],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher,
|
||||||
|
noarchive=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
pyz = PYZ(a.pure, a.zlib_archive, cipher=block_cipher)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='hbc_windows',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=False,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
icon=None,
|
||||||
|
version=None,
|
||||||
|
)
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
#Requires -RunAsAdministrator
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Install hbc_windows.exe as a Windows Service using NSSM.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Installs the HeartBeat Client as a Windows Service that starts automatically.
|
||||||
|
Requires NSSM (Non-Sucking Service Manager) in PATH or alongside this script.
|
||||||
|
Requires hbc_windows.exe built via: pyinstaller hbc_windows.spec
|
||||||
|
|
||||||
|
.PARAMETER Server
|
||||||
|
HBD server hostname or IP address (required).
|
||||||
|
|
||||||
|
.PARAMETER ExePath
|
||||||
|
Path to hbc_windows.exe. Defaults to the directory containing this script.
|
||||||
|
|
||||||
|
.PARAMETER ServiceName
|
||||||
|
Windows service name. Default: heartbeat-client
|
||||||
|
|
||||||
|
.PARAMETER ConfigFile
|
||||||
|
Path to hbc.json config file. Optional.
|
||||||
|
|
||||||
|
.PARAMETER LogFile
|
||||||
|
Path to log file. Default: C:\ProgramData\heartbeat\hbc.log
|
||||||
|
|
||||||
|
.PARAMETER Interval
|
||||||
|
Heartbeat interval in seconds. Default: 10
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\install_hbc_windows.ps1 -Server hbd.example.com
|
||||||
|
.\install_hbc_windows.ps1 -Server hbd.example.com -ConfigFile C:\ProgramData\heartbeat\hbc.json
|
||||||
|
#>
|
||||||
|
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Server,
|
||||||
|
|
||||||
|
[string]$ExePath = "",
|
||||||
|
[string]$ServiceName = "heartbeat-client",
|
||||||
|
[string]$ConfigFile = "",
|
||||||
|
[string]$LogFile = "C:\ProgramData\heartbeat\hbc.log",
|
||||||
|
[int]$Interval = 10
|
||||||
|
)
|
||||||
|
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Locate hbc_windows.exe
|
||||||
|
if ($ExePath -eq "") {
|
||||||
|
$ExePath = Join-Path $PSScriptRoot "hbc_windows.exe"
|
||||||
|
}
|
||||||
|
if (-not (Test-Path $ExePath)) {
|
||||||
|
Write-Error "hbc_windows.exe not found at: $ExePath`nBuild it first with: pyinstaller hbc_windows.spec"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Locate NSSM
|
||||||
|
$nssm = Get-Command nssm -ErrorAction SilentlyContinue
|
||||||
|
if (-not $nssm) {
|
||||||
|
$nssmLocal = Join-Path $PSScriptRoot "nssm.exe"
|
||||||
|
if (Test-Path $nssmLocal) {
|
||||||
|
$nssm = $nssmLocal
|
||||||
|
} else {
|
||||||
|
Write-Error "nssm.exe not found in PATH or alongside this script.`nDownload from https://nssm.cc/download"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$nssm = $nssm.Source
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build argument list
|
||||||
|
$args_list = "--daemon $Server"
|
||||||
|
if ($ConfigFile -ne "") {
|
||||||
|
$args_list = "--daemon -c `"$ConfigFile`" $Server"
|
||||||
|
}
|
||||||
|
if ($LogFile -ne "") {
|
||||||
|
$args_list = "$args_list --log-file `"$LogFile`""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create data directory
|
||||||
|
$dataDir = "C:\ProgramData\heartbeat"
|
||||||
|
if (-not (Test-Path $dataDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $dataDir | Out-Null
|
||||||
|
Write-Host "Created $dataDir"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove existing service if present
|
||||||
|
$existing = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if ($existing) {
|
||||||
|
Write-Host "Removing existing service '$ServiceName'..."
|
||||||
|
& $nssm stop $ServiceName 2>$null
|
||||||
|
& $nssm remove $ServiceName confirm
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install service
|
||||||
|
Write-Host "Installing service '$ServiceName'..."
|
||||||
|
& $nssm install $ServiceName $ExePath $args_list
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Error "nssm install failed (exit $LASTEXITCODE)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Configure service
|
||||||
|
& $nssm set $ServiceName DisplayName "HeartBeat Client"
|
||||||
|
& $nssm set $ServiceName Description "Sends heartbeat and plugin metrics to the HBD monitoring server."
|
||||||
|
& $nssm set $ServiceName Start SERVICE_AUTO_START
|
||||||
|
& $nssm set $ServiceName AppStdout (Join-Path $dataDir "nssm_stdout.log")
|
||||||
|
& $nssm set $ServiceName AppStderr (Join-Path $dataDir "nssm_stderr.log")
|
||||||
|
& $nssm set $ServiceName AppRotateFiles 1
|
||||||
|
& $nssm set $ServiceName AppRotateBytes 5242880
|
||||||
|
|
||||||
|
# Start service
|
||||||
|
Write-Host "Starting service '$ServiceName'..."
|
||||||
|
& $nssm start $ServiceName
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Warning "Service installed but failed to start — check logs in $dataDir"
|
||||||
|
} else {
|
||||||
|
Write-Host "Service '$ServiceName' started successfully."
|
||||||
|
Write-Host "Log file: $LogFile"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Useful commands:"
|
||||||
|
Write-Host " nssm status $ServiceName"
|
||||||
|
Write-Host " nssm stop $ServiceName"
|
||||||
|
Write-Host " nssm restart $ServiceName"
|
||||||
|
Write-Host " nssm remove $ServiceName confirm"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user