diff options
author | J.A. Nache <nache.nache@gmail.com> | 2014-09-19 10:44:38 +0200 |
---|---|---|
committer | J.A. Nache <nache.nache@gmail.com> | 2014-09-19 10:44:38 +0200 |
commit | d64e036eeafed4e8c8ba6b105408d62f405c64c3 (patch) | |
tree | 0dbbf9f655e358d1308bb762d2d7697535161a30 /GitAutoDeploy.py | |
parent | 3384c64b59117dc8032cca99884ad6e5cb20dd36 (diff) | |
download | Git-Auto-Deploy-d64e036eeafed4e8c8ba6b105408d62f405c64c3.zip Git-Auto-Deploy-d64e036eeafed4e8c8ba6b105408d62f405c64c3.tar.gz Git-Auto-Deploy-d64e036eeafed4e8c8ba6b105408d62f405c64c3.tar.bz2 |
Implement signal handler for kill -HUP and more later
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index 7917672..00b852e 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import json, urlparse, sys, os +import json, urlparse, sys, os, signal from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from subprocess import call @@ -89,16 +89,18 @@ class GitAutoDeploy(BaseHTTPRequestHandler): call(['cd "' + path + '" && ' + repository['deploy']], shell=True) break -def main(): - try: - server = None + +class GitAutoDeployMain: + + server = None + + def run(self): for arg in sys.argv: if(arg == '-d' or arg == '--daemon-mode'): GitAutoDeploy.daemon = True GitAutoDeploy.quiet = True if(arg == '-q' or arg == '--quiet'): GitAutoDeploy.quiet = True - if(GitAutoDeploy.daemon): pid = os.fork() if(pid != 0): @@ -110,17 +112,21 @@ def main(): else: print 'Github & Gitlab Autodeploy Service v 0.1 started in daemon mode' - server = HTTPServer(('', GitAutoDeploy.getConfig()['port']), GitAutoDeploy) - server.serve_forever() - except (KeyboardInterrupt, SystemExit) as e: - if(e): # wtf, why is this creating a new line? - print >> sys.stderr, e - - if(server is not None): - server.socket.close() + self.server = HTTPServer(('', GitAutoDeploy.getConfig()['port']), GitAutoDeploy) + self.server.serve_forever() + def close(self, signum, frame): if(not GitAutoDeploy.quiet): - print 'Goodbye' + print '\nGoodbye' + + if(self.server is not None): + self.server.socket.close() + sys.exit() if __name__ == '__main__': - main() + gadm = GitAutoDeployMain() + + signal.signal(signal.SIGHUP, gadm.close) + signal.signal(signal.SIGINT, gadm.close) + + gadm.run() |