Last active
December 14, 2015 11:38
-
-
Save inhies/5080024 to your computer and use it in GitHub Desktop.
Snippet showing how to catch common interrupts and use the HUP signal to reload your config on the fly. Note that you can not catch SIGKILL so we don't even try.
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
c := make(chan os.Signal, 1) | |
signal.Notify(c) | |
go func() { | |
for sig := range c { | |
switch sig { | |
case syscall.SIGHUP: | |
fmt.Println("Reloading config") | |
if err := parseConfig(); err != nil { | |
fmt.Println("Error parsing config") | |
fmt.Println(err) | |
} | |
case syscall.SIGTERM: | |
os.Exit(1) // Error becuase we were killed | |
case syscall.SIGINT: | |
// Do stuff and gracefully shutdown | |
os.Exit(0) | |
} | |
} | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment