From eacfb8fe53b4bb6fab15e2fd8c34acc350214a8c Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 16 Mar 2012 15:16:51 -0500 Subject: Capture SIGTERM and Shut down python services cleanly. This is the first step in clean shut downs. Does not yet support eventlet threads. Change-Id: Ibcd26ed61cf56947a8bdbe291d87cb211fc1ccd8 --- nova/service.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nova/service.py b/nova/service.py index 1da10e697..c77419432 100644 --- a/nova/service.py +++ b/nova/service.py @@ -21,6 +21,7 @@ import inspect import os +import signal import eventlet import greenlet @@ -126,6 +127,15 @@ class Launcher(object): :returns: None """ + def sigterm(sig, frame): + LOG.audit(_("SIGTERM received")) + # NOTE(jk0): Raise a ^C which is caught by the caller and cleanly + # shuts down the service. This does not yet handle eventlet + # threads. + raise KeyboardInterrupt + + signal.signal(signal.SIGTERM, sigterm) + for service in self._services: try: service.wait() -- cgit