github.com/decred/politeia@v1.4.0/politeiawww/cmd/politeiavoter/stats_unix.go (about)

     1  // Copyright (c) 2020 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  //
     5  //go:build !windows
     6  // +build !windows
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"os"
    13  	"os/signal"
    14  	"syscall"
    15  )
    16  
    17  func (p *piv) statsHandler() {
    18  	// Launch signal handler
    19  	signalsChan := make(chan os.Signal, 1)
    20  	signalsDone := make(chan struct{}, 1)
    21  	signal.Notify(signalsChan, []os.Signal{syscall.SIGUSR1}...)
    22  
    23  	for {
    24  		select {
    25  		case <-p.ctx.Done():
    26  			// Shut down signal handler
    27  			signal.Stop(signalsChan)
    28  			close(signalsDone)
    29  			return
    30  		case <-signalsChan:
    31  			fmt.Printf("----- politeiavoter status -----\n")
    32  			p.dumpTogo()
    33  			p.dumpComplete()
    34  			p.dumpQueue()
    35  		}
    36  	}
    37  }