Capture sigterm and mark the compose as DOOMED

Merges: https://pagure.io/pungi/pull-request/946
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
Patrick Uiterwijk 2018-05-11 16:49:01 +02:00 committed by Lubomír Sedlář
parent 057751381a
commit ab2faa85b3
2 changed files with 19 additions and 1 deletions

View File

@ -11,6 +11,8 @@ import locale
import datetime
import getpass
import socket
import signal
import traceback
from six.moves import shlex_quote
import json
@ -453,7 +455,23 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
compose.log_info("Compose finished: %s" % compose.topdir)
def sigterm_handler(signum, frame):
if COMPOSE:
COMPOSE.log_error("Compose run failed: signal %s" % signum)
COMPOSE.log_error("Traceback:\n%s"
% '\n'.join(traceback.format_stack(frame)))
COMPOSE.log_critical("Compose failed: %s" % COMPOSE.topdir)
COMPOSE.write_status("TERMINATED")
else:
print("Signal %s captured" % signum)
sys.stdout.flush()
sys.stderr.flush()
sys.exit(1)
if __name__ == "__main__":
signal.signal(signal.SIGTERM, sigterm_handler)
try:
main()
except (Exception, KeyboardInterrupt) as ex:

View File

@ -275,7 +275,7 @@ class Compose(kobo.log.LoggingBase):
f, indent=4)
def write_status(self, stat_msg):
if stat_msg not in ("STARTED", "FINISHED", "DOOMED"):
if stat_msg not in ("STARTED", "FINISHED", "DOOMED", "TERMINATED"):
self.log_warning("Writing nonstandard compose status: %s" % stat_msg)
old_status = self.get_status()
if stat_msg == old_status: