diff options
author | Tobias Henkel <tobias.henkel@bmw.de> | 2017-12-18 08:10:43 +0100 |
---|---|---|
committer | Tobias Henkel <tobias.henkel@bmw.de> | 2017-12-18 08:41:47 +0100 |
commit | fd7101b3b5065d009d3241470fca7069f6ec52f6 (patch) | |
tree | 801e4ea663d325cfab5fea68b2d4bb68bec38704 | |
parent | 6abc1fb9d61374147fcd763c7299b2d5e90c0a0a (diff) | |
download | zuul-fd7101b3b5065d009d3241470fca7069f6ec52f6.tar.gz |
Handle sigterm in nodaemon mode
When running zuul within a container it normally runs in nodaemon mode
as pid 1. Currently in this mode zuul just ignores SIGTERM which is
used normally to stop containers. Thus when running within OpenShift
it waits for a timeout until it gets killed forcefully.
Fix this by handling SIGINT and SIGTERM equally.
Change-Id: I24bd8c953e734fdb9545714126d77cbcdc161bbd
-rwxr-xr-x | zuul/cmd/executor.py | 7 | ||||
-rwxr-xr-x | zuul/cmd/merger.py | 7 | ||||
-rwxr-xr-x | zuul/cmd/scheduler.py | 7 |
3 files changed, 12 insertions, 9 deletions
diff --git a/zuul/cmd/executor.py b/zuul/cmd/executor.py index ade9715c2..c82deb748 100755 --- a/zuul/cmd/executor.py +++ b/zuul/cmd/executor.py @@ -51,9 +51,10 @@ class Executor(zuul.cmd.ZuulDaemonApp): if self.args.command: self.args.nodaemon = True - def exit_handler(self): + def exit_handler(self, signum, frame): self.executor.stop() self.executor.join() + sys.exit(0) def start_log_streamer(self): pipe_read, pipe_write = os.pipe() @@ -132,13 +133,13 @@ class Executor(zuul.cmd.ZuulDaemonApp): signal.signal(signal.SIGUSR2, zuul.cmd.stack_dump_handler) if self.args.nodaemon: + signal.signal(signal.SIGTERM, self.exit_handler) while True: try: signal.pause() except KeyboardInterrupt: print("Ctrl + C: asking executor to exit nicely...\n") - self.exit_handler() - sys.exit(0) + self.exit_handler(signal.SIGINT, None) else: self.executor.join() diff --git a/zuul/cmd/merger.py b/zuul/cmd/merger.py index 7db1beeaf..2916a0b3c 100755 --- a/zuul/cmd/merger.py +++ b/zuul/cmd/merger.py @@ -42,9 +42,10 @@ class Merger(zuul.cmd.ZuulDaemonApp): if self.args.command: self.args.nodaemon = True - def exit_handler(self): + def exit_handler(self, signum, frame): self.merger.stop() self.merger.join() + sys.exit(0) def run(self): # See comment at top of file about zuul imports @@ -64,13 +65,13 @@ class Merger(zuul.cmd.ZuulDaemonApp): signal.signal(signal.SIGUSR2, zuul.cmd.stack_dump_handler) if self.args.nodaemon: + signal.signal(signal.SIGTERM, self.exit_handler) while True: try: signal.pause() except KeyboardInterrupt: print("Ctrl + C: asking merger to exit nicely...\n") - self.exit_handler() - sys.exit(0) + self.exit_handler(signal.SIGINT, None) else: self.merger.join() diff --git a/zuul/cmd/scheduler.py b/zuul/cmd/scheduler.py index 7722d6e9c..c3bfa5d86 100755 --- a/zuul/cmd/scheduler.py +++ b/zuul/cmd/scheduler.py @@ -61,10 +61,11 @@ class Scheduler(zuul.cmd.ZuulDaemonApp): self.log.exception("Reconfiguration failed:") signal.signal(signal.SIGHUP, self.reconfigure_handler) - def exit_handler(self): + def exit_handler(self, signum, frame): self.sched.exit() self.sched.join() self.stop_gear_server() + sys.exit(0) def term_handler(self, signum, frame): self.stop_gear_server() @@ -180,13 +181,13 @@ class Scheduler(zuul.cmd.ZuulDaemonApp): signal.signal(signal.SIGHUP, self.reconfigure_handler) if self.args.nodaemon: + signal.signal(signal.SIGTERM, self.exit_handler) while True: try: signal.pause() except KeyboardInterrupt: print("Ctrl + C: asking scheduler to exit nicely...\n") - self.exit_handler() - sys.exit(0) + self.exit_handler(signal.SIGINT, None) else: self.sched.join() |