Files
go-zero/core/proc/signals.go
Kevin Wan 20f665ede8 implement k8s service discovery (#988)
* implement k8s service discovery

* simplify code

* use default namespace if not provided

* disable codecov bot comment

* ignore adhoc dir

* simplify building target in NewClient

* reformat code

* Fix filepath (#990)

* format code, and reorg imports (#991)

* add more unit test

Co-authored-by: anqiansong <anqiansong@gmail.com>
2021-09-04 10:27:08 +08:00

57 lines
913 B
Go

//go:build linux || darwin
// +build linux darwin
package proc
import (
"os"
"os/signal"
"syscall"
"github.com/tal-tech/go-zero/core/logx"
)
const timeFormat = "0102150405"
var done = make(chan struct{})
func init() {
go func() {
var profiler Stopper
// https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM)
for {
v := <-signals
switch v {
case syscall.SIGUSR1:
dumpGoroutines()
case syscall.SIGUSR2:
if profiler == nil {
profiler = StartProfile()
} else {
profiler.Stop()
profiler = nil
}
case syscall.SIGTERM:
select {
case <-done:
// already closed
default:
close(done)
}
gracefulStop(signals)
default:
logx.Error("Got unregistered signal:", v)
}
}
}()
}
func Done() <-chan struct{} {
return done
}