From d9dcb2a427f4041f121950668c4ae40b0042c0d6 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 10 Feb 2016 09:48:22 -0500 Subject: [PATCH] Revert "centralized TERM signal handling" This reverts commit 5a88478ccca44c1b0d531a35e91e88f834db9210. is WIP, not ready for use yet --- lib/ansible/cli/__init__.py | 9 --------- lib/ansible/cli/adhoc.py | 8 ++++++++ lib/ansible/executor/playbook_executor.py | 7 +++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index bfe4f81b9f..ed4a2dd5db 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -27,7 +27,6 @@ import time import yaml import re import getpass -import signal import subprocess from ansible import __version__ @@ -78,11 +77,6 @@ class CLI(object): self.action = None self.callback = callback - def _terminate(self, signum=None, framenum=None): - if signum is not None: - display.debug("Termination signal detected, shutting down gracefully: %d" % os.getpid() ) - raise SystemExit - def set_action(self): """ Get the action the user wants to execute from the sys argv list. @@ -115,9 +109,6 @@ class CLI(object): else: display.display(u"No config file found; using defaults") - # Manage user interruptions - signal.signal(signal.SIGTERM, self._terminate) - @staticmethod def ask_vault_passwords(ask_new_vault_pass=False, rekey=False): ''' prompt for vault password and/or password change ''' diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index cbd0ca09d8..4cba2be16c 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -21,6 +21,7 @@ __metaclass__ = type ######################################################## import os +import signal from ansible import constants as C from ansible.cli import CLI @@ -88,6 +89,10 @@ class AdHocCLI(CLI): tasks = [ dict(action=dict(module=self.options.module_name, args=parse_kv(self.options.module_args)), async=async, poll=poll) ] ) + def _terminate(self, signum=None, framenum=None): + if signum is not None: + display.debug("Termination signal detected, shutting down gracefully") + raise SystemExit def run(self): ''' use Runner lib to do SSH things ''' @@ -171,6 +176,9 @@ class AdHocCLI(CLI): # now create a task queue manager to execute the play self._tqm = None try: + # Manage user interruptions + signal.signal(signal.SIGTERM, self._terminate) + self._tqm = TaskQueueManager( inventory=inventory, variable_manager=variable_manager, diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 19efe19f29..83449f1435 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -22,6 +22,7 @@ __metaclass__ = type import getpass import locale import os +import signal import sys from ansible.compat.six import string_types @@ -68,6 +69,8 @@ class PlaybookExecutor: may limit the runs to serialized groups, etc. ''' + signal.signal(signal.SIGTERM, self._terminate) + result = 0 entrylist = [] entry = {} @@ -204,6 +207,10 @@ class PlaybookExecutor: return result + def _terminate(self, signum=None, framenum=None): + display.debug("Termination signal detected, shutting down gracefully") + raise SystemExit + def _get_serialized_batches(self, play): ''' Returns a list of hosts, subdivided into batches based on