-
-
Save luohua13/7652fa6c4bb5ba0f20b63f506215fb42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var onlyOneSignalHandler = make(chan struct{}) | |
| // SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned | |
| // which is closed on one of these signals. If a second signal is caught, the program | |
| // is terminated with exit code 1. | |
| func SetupSignalHandler() <-chan struct{} { | |
| close(onlyOneSignalHandler) // panics when called twice | |
| stop := make(chan struct{}) | |
| c := make(chan os.Signal, 2) | |
| signal.Notify(c, shutdownSignals...) | |
| go func() { | |
| <-c | |
| close(stop) | |
| <-c | |
| os.Exit(1) // second signal. Exit directly. | |
| }() | |
| return stop | |
| } | |
| command := app.NewAPIServerCommand(server.SetupSignalHandler()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment