trapSignalsCrossPlatform captures SIGINT or interrupt (depending on the OS), which initiates a graceful shutdown. A second SIGINT or interrupt will forcefully exit the process immediately.
()
| 35 | // on the OS), which initiates a graceful shutdown. A second SIGINT |
| 36 | // or interrupt will forcefully exit the process immediately. |
| 37 | func trapSignalsCrossPlatform() { |
| 38 | go func() { |
| 39 | shutdown := make(chan os.Signal, 1) |
| 40 | signal.Notify(shutdown, os.Interrupt) |
| 41 | |
| 42 | for i := 0; true; i++ { |
| 43 | <-shutdown |
| 44 | |
| 45 | if i > 0 { |
| 46 | Log().Warn("force quit", zap.String("signal", "SIGINT")) |
| 47 | os.Exit(ExitCodeForceQuit) |
| 48 | } |
| 49 | |
| 50 | Log().Info("shutting down", zap.String("signal", "SIGINT")) |
| 51 | go exitProcessFromSignal("SIGINT") |
| 52 | } |
| 53 | }() |
| 54 | } |
| 55 | |
| 56 | // exitProcessFromSignal exits the process from a system signal. |
| 57 | func exitProcessFromSignal(sigName string) { |
no test coverage detected