Revert "Register term_handler for all zuul apps"

This reverts commit 00d7ea51fd. It
intended to refactor common code paths for signal handling. However in
our dockerized deployment this seems to completely break signal
handling. Thus it needs to be reverted.

Change-Id: Id5731557ff9a363c7a3d9438a8efcd476e38380c
This commit is contained in:
Tobias Henkel 2018-01-22 15:15:19 +01:00
parent 495a52d2ae
commit b3cab1d779
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
6 changed files with 58 additions and 17 deletions

View File

@ -170,14 +170,6 @@ class ZuulDaemonApp(ZuulApp, metaclass=abc.ABCMeta):
expand_user=True)
return pid_fn
@abc.abstractmethod
def exit_handler(self, signum, frame):
"""
This is a signal handler which is called on SIGINT and SIGTERM and must
take care of stopping the application.
"""
pass
@abc.abstractmethod
def run(self):
"""
@ -197,8 +189,6 @@ class ZuulDaemonApp(ZuulApp, metaclass=abc.ABCMeta):
signal.signal(signal.SIGUSR2, stack_dump_handler)
if self.args.nodaemon:
signal.signal(signal.SIGTERM, self.exit_handler)
signal.signal(signal.SIGINT, self.exit_handler)
self.run()
else:
# Exercise the pidfile before we do anything else (including

View File

@ -17,6 +17,7 @@
import logging
import os
import sys
import signal
import tempfile
import zuul.cmd
@ -50,6 +51,8 @@ class Executor(zuul.cmd.ZuulDaemonApp):
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()
@ -106,7 +109,16 @@ class Executor(zuul.cmd.ZuulDaemonApp):
log_streaming_port=self.finger_port)
self.executor.start()
self.executor.join()
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(signal.SIGINT, None)
else:
self.executor.join()
def main():

View File

@ -14,6 +14,7 @@
# under the License.
import logging
import signal
import sys
import zuul.cmd
@ -46,9 +47,6 @@ class FingerGatewayApp(zuul.cmd.ZuulDaemonApp):
if self.args.command:
self.args.nodaemon = True
def exit_handler(self, signum, frame):
self.stop()
def run(self):
'''
Main entry point for the FingerGatewayApp.
@ -86,7 +84,19 @@ class FingerGatewayApp(zuul.cmd.ZuulDaemonApp):
self.log.info('Starting Zuul finger gateway app')
self.gateway.start()
self.gateway.wait()
if self.args.nodaemon:
# NOTE(Shrews): When running in non-daemon mode, although sending
# the 'stop' command via the command socket will shutdown the
# gateway, it's still necessary to Ctrl+C to stop the app.
while True:
try:
signal.pause()
except KeyboardInterrupt:
print("Ctrl + C: asking gateway to exit nicely...\n")
self.stop()
break
else:
self.gateway.wait()
self.log.info('Stopped Zuul finger gateway app')

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import signal
import sys
import zuul.cmd
@ -43,6 +44,8 @@ class Merger(zuul.cmd.ZuulDaemonApp):
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
@ -59,7 +62,16 @@ class Merger(zuul.cmd.ZuulDaemonApp):
self.connections)
self.merger.start()
self.merger.join()
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(signal.SIGINT, None)
else:
self.merger.join()
def main():

View File

@ -63,7 +63,9 @@ class Scheduler(zuul.cmd.ZuulDaemonApp):
def exit_handler(self, signum, frame):
self.sched.exit()
self.sched.join()
self.stop_gear_server()
sys.exit(0)
def start_gear_server(self):
pipe_read, pipe_write = os.pipe()
@ -173,7 +175,16 @@ class Scheduler(zuul.cmd.ZuulDaemonApp):
signal.signal(signal.SIGHUP, self.reconfigure_handler)
self.sched.join()
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(signal.SIGINT, None)
else:
self.sched.join()
def main():

View File

@ -89,6 +89,12 @@ class WebServer(zuul.cmd.ZuulDaemonApp):
name='web')
self.thread.start()
try:
signal.pause()
except KeyboardInterrupt:
print("Ctrl + C: asking web server to exit nicely...\n")
self.exit_handler(signal.SIGINT, None)
self.thread.join()
loop.stop()
loop.close()