Python: What is the default handling of SIGTERM?

Building on the answer of Thomas Wouters, python does not register a handler for the SIGTERM signal. We can see this by doing: In[23]: signal.SIG_DFL == signal.signal(signal.SIGTERM,signal.SIG_DFL) Out[23]: True That means that the system will take the default action. On linux, the default action (according to the signal man page) for a SIGTERM is to … Read more

Apache server keeps crashing, “caught SIGTERM, shutting down”

SIGTERM is used to restart Apache (provided that it’s setup in init to auto-restart): http://httpd.apache.org/docs/2.2/stopping.html The entries you see in the logs are almost certainly there because your provider used SIGTERM for that purpose. If it’s truly crashing, not even serving static content, then that sounds like some sort of a thread/connection exhaustion issue. Perhaps … Read more

In what order should I send signals to gracefully shutdown processes?

SIGTERM tells an application to terminate. The other signals tell the application other things which are unrelated to shutdown but may sometimes have the same result. Don’t use those. If you want an application to shut down, tell it to. Don’t give it misleading signals. Some people believe the smart standard way of terminating a … Read more

Is it possible to capture a Ctrl+C signal (SIGINT) and run a cleanup function, in a “defer” fashion?

You can use the os/signal package to handle incoming signals. Ctrl+C is SIGINT, so you can use this to trap os.Interrupt. c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func(){ for sig := range c { // sig is a ^C, handle it } }() The manner in which you cause your program to terminate … Read more