//go:build !windows // +build !windows package hpds_node import ( "fmt" "os" "os/signal" "runtime" "syscall" "git.hpds.cc/Component/network/log" ) // initialize when mq running as server. support inspection: // - `kill -SIGUSR1 ` inspect state() // - `kill -SIGTERM ` graceful shutdown // - `kill -SIGUSR2 ` inspect golang GC func (z *messageQueue) init() { go func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM, syscall.SIGUSR2, syscall.SIGUSR1, syscall.SIGINT) log.Infof("%sListening SIGUSR1, SIGUSR2, SIGTERM/SIGINT...", mqLogPrefix) for p1 := range c { log.Infof("Received signal: %s", p1) if p1 == syscall.SIGTERM || p1 == syscall.SIGINT { log.Infof("graceful shutting down ... %s", p1) _ = z.Close() os.Exit(0) } else if p1 == syscall.SIGUSR2 { var m runtime.MemStats runtime.ReadMemStats(&m) fmt.Printf("\tNumGC = %v\n", m.NumGC) } else if p1 == syscall.SIGUSR1 { log.Infof("print MessageQueue stats(): %d", z.Stats()) } } }() }