From c28a998d3df9880fa00d6af2365dc03cefd0a6c2 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 8 May 2018 11:47:55 +0200 Subject: [PATCH] [IMP] server: intercept SIGXCPU and shutdown gracefully When the runbot spawns an Odoo instance, a CPU TIME limit is set. When this limit is reached, the kernel kills the Odoo instance and no message appears in the logs leaving the dev in a deep smoke cloud. With this commit, the signal sent by the kernel when the soft limit is reached (SIGXCPU), is intercepeted and Odoo shutdown gracefully with a nice message for the dev. --- odoo/service/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/service/server.py b/odoo/service/server.py index b435475b937..83bb4d81f47 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -207,6 +207,9 @@ class ThreadedServer(CommonServer): os._exit(0) # interrupt run() to start shutdown raise KeyboardInterrupt() + elif sig == signal.SIGXCPU: + sys.stderr.write("CPU time limit exceeded! Shutting down immediately\n") + os._exit(0) elif sig == signal.SIGHUP: # restart on kill -HUP odoo.phoenix = True @@ -266,6 +269,7 @@ class ThreadedServer(CommonServer): signal.signal(signal.SIGTERM, self.signal_handler) signal.signal(signal.SIGCHLD, self.signal_handler) signal.signal(signal.SIGHUP, self.signal_handler) + signal.signal(signal.SIGXCPU, self.signal_handler) signal.signal(signal.SIGQUIT, dumpstacks) signal.signal(signal.SIGUSR1, log_ormcache_stats) elif os.name == 'nt': @@ -373,7 +377,7 @@ class GeventServer(CommonServer): signal.signal(signal.SIGQUIT, dumpstacks) signal.signal(signal.SIGUSR1, log_ormcache_stats) gevent.spawn(self.watchdog) - + self.httpd = WSGIServer((self.interface, self.port), self.app) _logger.info('Evented Service (longpolling) running on %s:%s', self.interface, self.port) try: