mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
centralized TERM signal handling
This commit is contained in:
parent
1b8dec9c88
commit
5a88478ccc
3 changed files with 9 additions and 15 deletions
|
@ -27,6 +27,7 @@ import time
|
|||
import yaml
|
||||
import re
|
||||
import getpass
|
||||
import signal
|
||||
import subprocess
|
||||
|
||||
from ansible import __version__
|
||||
|
@ -77,6 +78,11 @@ 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.
|
||||
|
@ -109,6 +115,9 @@ 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 '''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue