summaryrefslogtreecommitdiffstats
path: root/GitAutoDeploy.py
diff options
context:
space:
mode:
authorJ.A. Nache <nache.nache@gmail.com>2014-09-19 17:15:22 +0200
committerJ.A. Nache <nache.nache@gmail.com>2014-09-19 17:15:22 +0200
commit6a7d7fd69e166e7dafa70433d9dff57cb37d8690 (patch)
treece96f8b65ac1629aa1e1e191aef982211bb4a5a6 /GitAutoDeploy.py
parent0e23c2a45f69cacdf51562135ae0bece1e73e725 (diff)
downloadGit-Auto-Deploy-6a7d7fd69e166e7dafa70433d9dff57cb37d8690.zip
Git-Auto-Deploy-6a7d7fd69e166e7dafa70433d9dff57cb37d8690.tar.gz
Git-Auto-Deploy-6a7d7fd69e166e7dafa70433d9dff57cb37d8690.tar.bz2
Debug code, detect process running at configured port
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-xGitAutoDeploy.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py
index 72d2956..21a8dcd 100755
--- a/GitAutoDeploy.py
+++ b/GitAutoDeploy.py
@@ -133,6 +133,7 @@ class GitAutoDeployMain:
self.server.serve_forever()
except socket.error, e:
print "Error on socket: %s" % e
+ self.debug_diagnosis()
sys.exit(1)
def create_pidfile(self):
@@ -141,9 +142,49 @@ class GitAutoDeployMain:
f.write(str(mainpid))
f.close()
+ def read_pidfile(self):
+ f = open(GitAutoDeploy.getConfig()['pidfilepath'],'r')
+ pid = f.readlines();
+ return pid;
+
def remove_pidfile(self):
os.remove(GitAutoDeploy.getConfig()['pidfilepath'])
+ def debug_diagnosis(self):
+ if(GitAutoDeploy.getConfig()['debug'] == "True" ):
+ f = open("/proc/net/tcp",'r')
+ filecontent = f.readlines()
+ f.close()
+ filecontent.pop(0)
+
+ pids = [int(x) for x in os.listdir('/proc') if x.isdigit()]
+ for line in filecontent:
+ a_line = " ".join(line.split()).split(" ")
+ hexport = a_line[1].split(':')[1]
+ decport = str(int(hexport,16))
+ inode = a_line[9]
+
+ if(decport == str(GitAutoDeploy.getConfig()['port'])):
+ mpid = False
+ for pid in pids:
+ try:
+ for fd in os.listdir("/proc/%s/fd" % pid):
+ cinode = os.readlink("/proc/%s/fd/%s" % (pid, fd))
+ try:
+ minode = cinode.split("[")[1].split("]")[0]
+ if(minode == inode):
+ mpid = pid
+ except IndexError:
+ continue
+
+ except OSError:
+ continue
+ if(mpid != False):
+ print 'Process with pid number', mpid, 'is using port', decport
+ f = open("/proc/%s/cmdline" % mpid)
+ cmdline = f.readlines();
+ print 'cmdline ->', cmdline
+
def stop(self):
if(self.server is not None):
self.server.socket.close()
@@ -154,7 +195,7 @@ class GitAutoDeployMain:
self.remove_pidfile()
sys.exit(0)
- def signal_handle(self, signum, frame):
+ def signal_handler(self, signum, frame):
if(signum == 1):
self.stop()
self.run()
@@ -169,7 +210,7 @@ class GitAutoDeployMain:
if __name__ == '__main__':
gadm = GitAutoDeployMain()
- signal.signal(signal.SIGHUP, gadm.signal_handle)
- signal.signal(signal.SIGINT, gadm.signal_handle)
+ signal.signal(signal.SIGHUP, gadm.signal_handler)
+ signal.signal(signal.SIGINT, gadm.signal_handler)
gadm.run()