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
diff --git a/zuul/cmd/executor.py b/zuul/cmd/executor.py
index ade9715..c82deb7 100755
--- a/zuul/cmd/executor.py
+++ b/zuul/cmd/executor.py
@@ -51,9 +51,10 @@
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 @@
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 7db1bee..2916a0b 100755
--- a/zuul/cmd/merger.py
+++ b/zuul/cmd/merger.py
@@ -42,9 +42,10 @@
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 @@
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 7722d6e..c3bfa5d 100755
--- a/zuul/cmd/scheduler.py
+++ b/zuul/cmd/scheduler.py
@@ -61,10 +61,11 @@
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 @@
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()