aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpkid/rpki/exceptions.py3
-rw-r--r--rpkid/rpki/https.py15
2 files changed, 15 insertions, 3 deletions
diff --git a/rpkid/rpki/exceptions.py b/rpkid/rpki/exceptions.py
index b3db4737..9298ae24 100644
--- a/rpkid/rpki/exceptions.py
+++ b/rpkid/rpki/exceptions.py
@@ -123,3 +123,6 @@ class UnparsableCMSDER(RPKI_Exception):
class CMSCRLNotSet(RPKI_Exception):
"""CMS CRL has not been configured."""
+
+class ServerShuttingDown(RPKI_Exception):
+ """Server is shutting down."""
diff --git a/rpkid/rpki/https.py b/rpkid/rpki/https.py
index c47d22a5..1b5b2344 100644
--- a/rpkid/rpki/https.py
+++ b/rpkid/rpki/https.py
@@ -21,7 +21,7 @@ subversion repository; generalizing it would not be hard, but the more
general version should use SQL anyway.
"""
-import httplib, BaseHTTPServer, tlslite.api, glob, traceback, urlparse, socket
+import httplib, BaseHTTPServer, tlslite.api, glob, traceback, urlparse, socket, signal
import rpki.x509, rpki.exceptions, rpki.log
# This should be wrapped somewhere in rpki.x509 eventually
@@ -263,7 +263,7 @@ class httpsServer(tlslite.api.TLSSocketServerMixIn, BaseHTTPServer.HTTPServer):
rpki.log.warn("TLS handshake failure: " + str(error))
return False
-def server(handlers, server_key, server_cert, port = 4433, host = "", client_ta = None, dynamic_https_trust_anchor = None):
+def server(handlers, server_key, server_cert, port = 4433, host ="", client_ta = None, dynamic_https_trust_anchor = None, catch_signals = (signal.SIGINT, signal.SIGTERM)):
"""Run an HTTPS server and wait (forever) for connections."""
if not isinstance(handlers, (tuple, list)):
@@ -279,4 +279,13 @@ def server(handlers, server_key, server_cert, port = 4433, host = "", client_ta
httpd.rpki_sessionCache = tlslite.api.SessionCache()
httpd.rpki_checker = Checker(trust_anchor = client_ta, dynamic_https_trust_anchor = dynamic_https_trust_anchor)
- httpd.serve_forever()
+ try:
+ def raiseServerShuttingDown(signum, frame):
+ raise rpki.exceptions.ServerShuttingDown
+ old_signal_handlers = tuple((sig, signal.signal(sig, raiseServerShuttingDown)) for sig in catch_signals)
+ httpd.serve_forever()
+ except rpki.exceptions.ServerShuttingDown:
+ rpki.log.info("Exiting server")
+ finally:
+ for sig,handler in old_signal_handlers:
+ signal.signal(sig, handler)