Kill ckpool on bitcoind failure so miners can failover
When bitcoind is unreachable for 3+ consecutive polls and no block submission is pending, SIGTERM the ckpool process so miners disconnect and failover to backup pools. Adds a red dashboard banner when Bitcoin Core is down.
This commit is contained in:
@@ -66,6 +66,7 @@ func main() {
|
||||
agg.Store = blockStore
|
||||
agg.MempoolBaseURL = cfg.MempoolBaseURL
|
||||
agg.LogFilePath = cfg.CKPoolLogFile
|
||||
agg.KillCKPool = killCKPool(log)
|
||||
|
||||
// Transaction accelerator (prioritisetransaction).
|
||||
var accSvc *accelerator.Service
|
||||
@@ -164,3 +165,38 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// killCKPool returns a function that finds the ckpool process by name
|
||||
// and sends it SIGTERM. Used by the aggregator to disconnect miners
|
||||
// when bitcoind is unreachable so they can failover to other pools.
|
||||
func killCKPool(log *slog.Logger) func() error {
|
||||
return func() error {
|
||||
entries, err := os.ReadDir("/proc")
|
||||
if err != nil {
|
||||
return fmt.Errorf("read /proc: %w", err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() {
|
||||
continue
|
||||
}
|
||||
pid, err := strconv.Atoi(e.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// ckpool's cmdline is NUL-separated; the first arg is the binary path.
|
||||
if strings.Contains(string(cmdline), "ckpool") {
|
||||
log.Info("sending SIGTERM to ckpool", "pid", pid)
|
||||
proc, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("find process %d: %w", pid, err)
|
||||
}
|
||||
return proc.Signal(syscall.SIGTERM)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("ckpool process not found")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user