- Client: Go-based Windows hardware monitoring (CPU, GPU, memory, disk, network, power) - Server: Go + Gin + SQLite backend with REST API - Frontend: Vue 3 + Element Plus dashboard - Docker deployment support - Windows service installation script
88 lines
3.1 KiB
PowerShell
88 lines
3.1 KiB
PowerShell
# PC Monitor Client Installation Script
|
|
# Run as Administrator
|
|
|
|
param(
|
|
[string]$ServerUrl = "http://your-server:8080",
|
|
[string]$InstallDir = "C:\Program Files\PCMonitor"
|
|
)
|
|
|
|
# Check if running as Administrator
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
if (-not $isAdmin) {
|
|
Write-Error "Please run this script as Administrator"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Installing PC Monitor Client..." -ForegroundColor Green
|
|
|
|
# Create installation directory
|
|
if (-not (Test-Path $InstallDir)) {
|
|
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
|
|
}
|
|
|
|
# Copy executable
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$exePath = Join-Path $scriptDir "pc-monitor-client.exe"
|
|
|
|
if (-not (Test-Path $exePath)) {
|
|
Write-Error "pc-monitor-client.exe not found in script directory"
|
|
exit 1
|
|
}
|
|
|
|
Copy-Item $exePath -Destination $InstallDir -Force
|
|
|
|
# Create config file
|
|
$configPath = Join-Path $InstallDir "config.yaml"
|
|
@"
|
|
server:
|
|
url: "$ServerUrl"
|
|
token: ""
|
|
collect:
|
|
interval: 30s
|
|
report:
|
|
interval: 60s
|
|
"@ | Out-File -FilePath $configPath -Encoding UTF8
|
|
|
|
# Create Windows Service using NSSM
|
|
$nssmPath = Join-Path $InstallDir "nssm.exe"
|
|
if (-not (Test-Path $nssmPath)) {
|
|
Write-Host "Downloading NSSM..." -ForegroundColor Yellow
|
|
$nssmUrl = "https://nssm.cc/release/nssm-2.24.zip"
|
|
$zipPath = Join-Path $InstallDir "nssm.zip"
|
|
Invoke-WebRequest -Uri $nssmUrl -OutFile $zipPath
|
|
Expand-Archive -Path $zipPath -DestinationPath $InstallDir -Force
|
|
$nssmExe = Get-ChildItem -Path $InstallDir -Recurse -Filter "nssm.exe" | Where-Object { $_.FullName -match "win64" } | Select-Object -First 1
|
|
if ($nssmExe) {
|
|
Copy-Item $nssmExe.FullName -Destination $nssmPath -Force
|
|
}
|
|
Remove-Item $zipPath -Force
|
|
}
|
|
|
|
# Install service
|
|
$serviceName = "PCMonitor"
|
|
$clientExe = Join-Path $InstallDir "pc-monitor-client.exe"
|
|
|
|
& $nssmPath install $serviceName $clientExe
|
|
& $nssmPath set $serviceName AppDirectory $InstallDir
|
|
& $nssmPath set $serviceName DisplayName "PC Monitor Client"
|
|
& $nssmPath set $serviceName Description "Monitors PC hardware metrics and reports to server"
|
|
& $nssmPath set $serviceName Start SERVICE_AUTO_START
|
|
& $nssmPath set $serviceName AppStdout (Join-Path $InstallDir "stdout.log")
|
|
& $nssmPath set $serviceName AppStderr (Join-Path $InstallDir "stderr.log")
|
|
|
|
# Start service
|
|
Start-Service $serviceName
|
|
|
|
Write-Host ""
|
|
Write-Host "Installation complete!" -ForegroundColor Green
|
|
Write-Host "Service '$serviceName' installed and started." -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Configuration file: $configPath" -ForegroundColor Cyan
|
|
Write-Host "Please edit the config file to set your server URL and token." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Useful commands:" -ForegroundColor Yellow
|
|
Write-Host " Start service: Start-Service $serviceName"
|
|
Write-Host " Stop service: Stop-Service $serviceName"
|
|
Write-Host " Service status: Get-Service $serviceName"
|
|
Write-Host " View logs: Get-Content (Join-Path $InstallDir 'stdout.log') -Tail 50"
|