mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Merge pull request #453 from matburt/fix_proot_cp_issue
Fix proot controlpersist cleanup issue
This commit is contained in:
@@ -37,7 +37,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import urlparse
|
import urlparse
|
||||||
import time
|
|
||||||
|
|
||||||
# Requests
|
# Requests
|
||||||
import requests
|
import requests
|
||||||
@@ -45,12 +44,7 @@ import requests
|
|||||||
# ZeroMQ
|
# ZeroMQ
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
# PSUtil
|
import psutil
|
||||||
try:
|
|
||||||
import psutil
|
|
||||||
except ImportError:
|
|
||||||
psutil = None
|
|
||||||
|
|
||||||
|
|
||||||
class TokenAuth(requests.auth.AuthBase):
|
class TokenAuth(requests.auth.AuthBase):
|
||||||
|
|
||||||
@@ -249,19 +243,14 @@ class BaseCallbackModule(object):
|
|||||||
if not cp_files:
|
if not cp_files:
|
||||||
return
|
return
|
||||||
|
|
||||||
# HACK: If psutil isn't available, sleep and allow the control master
|
|
||||||
# processes to timeout and die.
|
|
||||||
if not psutil:
|
|
||||||
time.sleep(60)
|
|
||||||
|
|
||||||
# Attempt to find any running control master processes.
|
# Attempt to find any running control master processes.
|
||||||
username = pwd.getpwuid(os.getuid())[0]
|
username = pwd.getpwuid(os.getuid())[0]
|
||||||
ssh_cm_procs = []
|
ssh_cm_procs = []
|
||||||
for proc in psutil.process_iter():
|
for proc in psutil.process_iter():
|
||||||
try:
|
try:
|
||||||
pname = proc.name
|
pname = proc.name()
|
||||||
pcmdline = proc.cmdline
|
pcmdline = proc.cmdline()
|
||||||
pusername = proc.username
|
pusername = proc.username()
|
||||||
except psutil.NoSuchProcess:
|
except psutil.NoSuchProcess:
|
||||||
continue
|
continue
|
||||||
if pusername != username:
|
if pusername != username:
|
||||||
@@ -277,19 +266,7 @@ class BaseCallbackModule(object):
|
|||||||
# version of psutil that may not have wait_procs implemented.
|
# version of psutil that may not have wait_procs implemented.
|
||||||
for proc in ssh_cm_procs:
|
for proc in ssh_cm_procs:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
if hasattr(psutil, 'wait_procs'):
|
procs_gone, procs_alive = psutil.wait_procs(ssh_cm_procs, timeout=5)
|
||||||
procs_gone, procs_alive = psutil.wait_procs(ssh_cm_procs, timeout=5)
|
|
||||||
else:
|
|
||||||
procs_gone = []
|
|
||||||
procs_alive = ssh_cm_procs[:]
|
|
||||||
for x in xrange(5):
|
|
||||||
for proc in procs_alive[:]:
|
|
||||||
if not proc.is_running():
|
|
||||||
procs_alive.remove(proc)
|
|
||||||
procs_gone.append(proc)
|
|
||||||
if not procs_alive:
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
for proc in procs_alive:
|
for proc in procs_alive:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user