summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2017-11-22 10:30:06 -0500
committerJohn R Barker <john@johnrbarker.com>2017-11-22 15:30:06 +0000
commit69575e25d0630a6eb6aa771bc528f701737f12f4 (patch)
treeceadc7aa7f4a4d98d046273cba15b3ee698b8c4e /bin
parent9d56ffa4ed6690bd859822a33229439fb0f98943 (diff)
downloadansible-69575e25d0630a6eb6aa771bc528f701737f12f4.tar.gz
shuts down persistent connections at end of play run (#32825)
This change will now track any created persistent connection and shut it down at the end of the play run. This change also includes an update to properly honor the reset_connection meta handler.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ansible-connection36
1 files changed, 17 insertions, 19 deletions
diff --git a/bin/ansible-connection b/bin/ansible-connection
index e97408ea52..5a1221715f 100755
--- a/bin/ansible-connection
+++ b/bin/ansible-connection
@@ -51,6 +51,8 @@ class ConnectionProcess(object):
self.srv = JsonRpcServer()
self.sock = None
+ self.connection = None
+
def start(self):
try:
messages = list()
@@ -67,6 +69,7 @@ class ConnectionProcess(object):
self.connection = connection_loader.get(self.play_context.connection, self.play_context, '/dev/null')
self.connection.set_options()
self.connection._connect()
+ self.connection._socket_path = self.socket_path
self.srv.register(self.connection)
messages.append('connection to remote device started successfully')
@@ -84,7 +87,7 @@ class ConnectionProcess(object):
def run(self):
try:
- while True:
+ while self.connection.connected:
signal.signal(signal.SIGALRM, self.connect_timeout)
signal.signal(signal.SIGTERM, self.handler)
signal.alarm(C.PERSISTENT_CONNECT_TIMEOUT)
@@ -135,24 +138,19 @@ class ConnectionProcess(object):
def shutdown(self):
""" Shuts down the local domain socket
"""
- if not os.path.exists(self.socket_path):
- return
-
- try:
- if self.sock:
- self.sock.close()
- if self.connection:
- self.connection.close()
-
- except Exception:
- pass
-
- finally:
- if os.path.exists(self.socket_path):
- os.remove(self.socket_path)
- setattr(self.connection, '_socket_path', None)
- setattr(self.connection, '_connected', False)
-
+ if os.path.exists(self.socket_path):
+ try:
+ if self.sock:
+ self.sock.close()
+ if self.connection:
+ self.connection.close()
+ except:
+ pass
+ finally:
+ if os.path.exists(self.socket_path):
+ os.remove(self.socket_path)
+ setattr(self.connection, '_socket_path', None)
+ setattr(self.connection, '_connected', False)
display.display('shutdown complete', log_only=True)
def do_EXEC(self, data):