Context
There is an app running inside docker container. When docker stop %container_id%
is sent the container receives SIGTERM
. This signal is handled inside golang application via executing cleanup code before exiting. In this case code is a single log statement before exiting.
Questions
- Is it guaranteed that container won't cease to exist before this statement is executed?
- If yes does it apply to other signals?
- If no are there signals to which this do apply?
func main() {
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintln(rw, "chirtkem mudila")
})
go func() {
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}()
interupt := make(chan os.Signal, 1)
signal.Notify(interupt, syscall.SIGTERM, syscall.SIGINT)
<-interupt
log.Println("graceful shutdown") // is it guaranteed to execute before container ceases to exist?
}