You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
//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 <pid>` inspect state() |
|
// - `kill -SIGTERM <pid>` graceful shutdown |
|
// - `kill -SIGUSR2 <pid>` 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()) |
|
} |
|
} |
|
}() |
|
}
|
|
|