Files
script-runner/nssm.txt
2025-10-07 19:31:41 +02:00

54 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ======= Einstellungen anpassen =======
$SvcName = "ScriptRunner"
$Display = "Script Runner"
$InstallDir = "C:\apps\script-runner" # Ordner mit EXE & tasks.json
$ExePath = "$InstallDir\script-runner.exe"
$LogsDir = "$InstallDir\logs"
$NSSM = "C:\tools\nssm\nssm.exe" # Pfad zu nssm.exe
$AutoStart = "SERVICE_AUTO_START" # oder SERVICE_DEMAND_START
$Port = 8080 # nur für Firewall-Beispiel
# (optional) Dienstkonto statt LocalSystem nutzen empfohlen:
# Einmalig Benutzer anlegen (lokal):
# $SvcUser = "$env:COMPUTERNAME\svc-scriptrunner"
# $SvcPwd = Read-Host -AsSecureString "Passwort für $SvcUser"
# New-LocalUser -Name "svc-scriptrunner" -Password $SvcPwd -NoPasswordExpiration -AccountNeverExpires
# $PlainPwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($SvcPwd))
# ======= Ordner/Logs anlegen =======
New-Item -Type Directory -Force $InstallDir | Out-Null
New-Item -Type Directory -Force $LogsDir | Out-Null
# ======= Dienst installieren =======
& $NSSM install $SvcName $ExePath
& $NSSM set $SvcName AppDirectory $InstallDir
& $NSSM set $SvcName DisplayName $Display
& $NSSM set $SvcName Start $AutoStart
# (optional) Dienstkonto setzen:
# & $NSSM set $SvcName ObjectName $SvcUser $PlainPwd
# ======= Logs & Rotation =======
& $NSSM set $SvcName AppStdout "$LogsDir\out.log"
& $NSSM set $SvcName AppStderr "$LogsDir\err.log"
& $NSSM set $SvcName AppRotateFiles 1
& $NSSM set $SvcName AppRotateOnline 1
& $NSSM set $SvcName AppRotateBytes 10485760 # 10 MB
& $NSSM set $SvcName AppRotateSeconds 86400 # 1 Tag
# ======= Sauberes Stop/Restart-Verhalten =======
& $NSSM set $SvcName AppStopMethodConsole 1500 # CTRL+C nach 1,5s
& $NSSM set $SvcName AppStopMethodSkip 0
& $NSSM set $SvcName AppKillProcessTree 1
& $NSSM set $SvcName AppExit Default Restart # bei Fehler neu starten
# ======= (optional) Firewallregel nur nötig, wenn NICHT auf 127.0.0.1 gebunden =======
# New-NetFirewallRule -DisplayName "Script Runner $Port" -Direction Inbound -Action Allow -Protocol TCP -LocalPort $Port
# ======= Start & Check =======
Start-Service $SvcName
Start-Sleep 1
Get-Service $SvcName | Format-Table -Auto
Write-Host "Logs: $LogsDir"