feat: add the SIGINT signal in signals.go to subscribe the user input ctrl+c to exit the application operation (#3611)

master
#Suyghur 1 year ago committed by GitHub
parent d71c0da7b7
commit 95b7a3d3ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,7 +20,7 @@ func init() {
// https://golang.org/pkg/os/signal/#Notify // https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1) signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM) signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
for { for {
v := <-signals v := <-signals
@ -34,14 +34,13 @@ func init() {
profiler.Stop() profiler.Stop()
profiler = nil profiler = nil
} }
case syscall.SIGTERM: case syscall.SIGTERM, syscall.SIGINT:
select { select {
case <-done: case <-done:
// already closed // already closed
default: default:
close(done) close(done)
} }
gracefulStop(signals) gracefulStop(signals)
default: default:
logx.Error("Got unregistered signal:", v) logx.Error("Got unregistered signal:", v)

Loading…
Cancel
Save