diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi index 29280f82ed927ccc49ce55516f39aed240eb4a66..817088a01af8fde1649bf8648bef339f8aa51617 100755 --- a/daemons/ganeti-rapi +++ b/daemons/ganeti-rapi @@ -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: