Skip to content
Snippets Groups Projects
Commit cfe3c70f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Implement signal handling in ganeti-rapi

Reviewed-by: iustinp
parent 3cd62121
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ import glob
import optparse
import sys
import os
import signal
from ganeti import constants
from ganeti import errors
......@@ -66,6 +67,17 @@ class RESTRequestHandler(http.HTTPRequestHandler):
return result
class RESTHttpServer(http.HTTPServer):
def serve_forever(self):
"""Handle one request at a time until told to quit."""
sighandler = utils.SignalHandler([signal.SIGINT, signal.SIGTERM])
try:
while not sighandler.called:
self.handle_request()
finally:
sighandler.Reset()
def ParseOptions():
"""Parse the command line options.
......@@ -123,8 +135,8 @@ def main():
log_fd = open(constants.LOG_RAPIACCESS, 'a')
try:
apache_log = http.ApacheLogfile(log_fd)
httpd = http.HTTPServer(("", options.port), RESTRequestHandler,
httplog=apache_log)
httpd = RESTHttpServer(("", options.port), RESTRequestHandler,
httplog=apache_log)
try:
httpd.serve_forever()
finally:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment