From: Fredrik Tolf Date: Mon, 3 Aug 2015 01:51:20 +0000 (+0200) Subject: python: Try to shut ashd-wsgi down more nicely upon signal receipt. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=fd0303c3260c6397b33912312af67e7a99523926;p=ashd.git python: Try to shut ashd-wsgi down more nicely upon signal receipt. --- diff --git a/python/ashd-wsgi b/python/ashd-wsgi index b671059..d5438fa 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, os, getopt, socket, logging, time +import sys, os, getopt, socket, logging, time, signal import ashd.util, ashd.serve try: import pdm.srv @@ -191,6 +191,11 @@ except ValueError as exc: sys.stderr.write("ashd-wsgi: %s\n" % exc) sys.exit(1) +def sigterm(sig, frame): + socket.fromfd(0, socket.AF_UNIX, socket.SOCK_SEQPACKET).shutdown(socket.SHUT_RDWR) # :P +for signum in [signal.SIGINT, signal.SIGTERM]: + signal.signal(signum, sigterm) + reqhandler = hclass(**hargs) try: ashd.util.serveloop(handle) diff --git a/python3/ashd-wsgi3 b/python3/ashd-wsgi3 index fbb8d38..a63362d 100755 --- a/python3/ashd-wsgi3 +++ b/python3/ashd-wsgi3 @@ -1,6 +1,6 @@ #!/usr/bin/python3 -import sys, os, getopt, socket, logging, time, locale, collections +import sys, os, getopt, socket, logging, time, locale, collections, signal import ashd.util, ashd.serve try: import pdm.srv @@ -197,6 +197,11 @@ except ValueError as exc: sys.stderr.write("ashd-wsgi3: %s\n" % exc) sys.exit(1) +def sigterm(sig, frame): + socket.fromfd(0, socket.AF_UNIX, socket.SOCK_SEQPACKET).shutdown(socket.SHUT_RDWR) # :P +for signum in [signal.SIGINT, signal.SIGTERM]: + signal.signal(signum, sigterm) + reqhandler = hclass(**hargs) try: ashd.util.serveloop(handle)