diff options
author | J.A. Nache <nache.nache@gmail.com> | 2014-09-20 18:14:03 +0200 |
---|---|---|
committer | J.A. Nache <nache.nache@gmail.com> | 2014-09-20 18:14:03 +0200 |
commit | 6b3ed2763484240e65a91e7889724fab9bae0f0f (patch) | |
tree | 702d023dc987454d29047fded3fd685b8b3873dc /GitAutoDeploy.py | |
parent | 1c4c879509efe034446f3dd97455ca2ec1f85b68 (diff) | |
download | Git-Auto-Deploy-6b3ed2763484240e65a91e7889724fab9bae0f0f.zip Git-Auto-Deploy-6b3ed2763484240e65a91e7889724fab9bae0f0f.tar.gz Git-Auto-Deploy-6b3ed2763484240e65a91e7889724fab9bae0f0f.tar.bz2 |
New option to force run when port is used'
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index e04407c..48bcaa7 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -115,6 +115,10 @@ class GitAutoDeployMain: GitAutoDeploy.quiet = True if(arg == '-q' or arg == '--quiet'): GitAutoDeploy.quiet = True + if(arg == '--force'): + print '[KILLER MODE] Warning: The --force option will try to kill any process ' \ + 'using %s port. USE AT YOUR OWN RISK' %GitAutoDeploy.getConfig()['port'] + self.kill_them_all() if(GitAutoDeploy.daemon): pid = os.fork() @@ -133,10 +137,21 @@ class GitAutoDeployMain: self.server = HTTPServer(('', GitAutoDeploy.getConfig()['port']), GitAutoDeploy) self.server.serve_forever() except socket.error, e: - print "Error on socket: %s" % e - self.debug_diagnosis() + if(not GitAutoDeploy.quiet and not GitAutoDeploy.daemon): + print "Error on socket: %s" % e + self.debug_diagnosis() sys.exit(1) + def kill_them_all(self): + pid = self.get_pid_on_port(GitAutoDeploy.getConfig()['port']) + if pid == False: + print '[KILLER MODE] I don\'t know the number of pid that is using my configured port\n ' \ + '[KILLER MODE] Maybe no one? Please, use --force option carefully' + return False + + os.kill(pid, signal.SIGKILL) + return True + def create_pidfile(self): with open(GitAutoDeploy.getConfig()['pidfilepath'], 'w') as f: f.write(str(os.getpid())) @@ -152,6 +167,18 @@ class GitAutoDeployMain: if GitAutoDeploy.debug == False: return + port = GitAutoDeploy.getConfig()['port'] + pid = self.get_pid_on_port(port) + if pid == False: + print 'I don\'t know the number of pid that is using my configured port' + return + + print 'Process with pid number %s is using port %s' % (pid, port) + with open("/proc/%s/cmdline" % pid) as f: + cmdline = f.readlines() + print 'cmdline ->', cmdline[0].replace('\x00', ' ') + + def get_pid_on_port(self,port): with open("/proc/net/tcp",'r') as f: filecontent = f.readlines()[1:] @@ -183,14 +210,9 @@ class GitAutoDeployMain: mpid = pid except Exception as e: pass + return mpid - if(mpid != False): - print 'Process with pid number %s is using port %s' % (mpid, decport) - with open("/proc/%s/cmdline" % mpid) as f: - cmdline = f.readlines() - print 'cmdline ->', cmdline[0].replace('\x00', ' ') - def stop(self): if(self.server is not None): self.server.socket.close() @@ -208,6 +230,8 @@ class GitAutoDeployMain: return elif(signum == 2): print '\nKeyboard Interrupt!!!' + elif(signum == 6): + print 'Requested close by SIGABRT (process abort signal). Code 6.' self.exit() @@ -216,5 +240,6 @@ if __name__ == '__main__': signal.signal(signal.SIGHUP, gadm.signal_handler) signal.signal(signal.SIGINT, gadm.signal_handler) + signal.signal(signal.SIGABRT, gadm.signal_handler) gadm.run() |