Revision 84b58db2 daemons/ganeti-noded

b/daemons/ganeti-noded
30 30
import SocketServer
31 31
import errno
32 32
import logging
33
import signal
33 34

  
34 35
from optparse import OptionParser
35 36

  
36

  
37 37
from ganeti import backend
38 38
from ganeti import logger
39 39
from ganeti import constants
......
43 43
from ganeti import http
44 44
from ganeti import utils
45 45

  
46
_EXIT_GANETI_NODED = False
47

  
48 46

  
49 47
class NodeDaemonRequestHandler(http.HTTPRequestHandler):
50 48
  """The server implementation.
......
56 54
    """Handle a request.
57 55

  
58 56
    """
59
    global _EXIT_GANETI_NODED
60

  
61 57
    if self.command.upper() != "PUT":
62 58
      raise http.HTTPBadRequest()
63 59

  
......
72 68
    try:
73 69
      return method(self.post_data)
74 70
    except errors.QuitGanetiException, err:
75
      _EXIT_GANETI_NODED = True
71
      # Tell parent to quit
72
      os.kill(self.server.noded_pid, signal.SIGTERM)
76 73

  
77 74
  # the new block devices  --------------------------
78 75

  
......
536 533
class NodeDaemonHttpServer(http.HTTPServer):
537 534
  def __init__(self, server_address):
538 535
    http.HTTPServer.__init__(self, server_address, NodeDaemonRequestHandler)
536
    self.noded_pid = os.getpid()
537

  
538
  def serve_forever(self):
539
    """Handle requests until told to quit."""
540
    sighandler = utils.SignalHandler([signal.SIGINT, signal.SIGTERM])
541
    try:
542
      while not sighandler.called:
543
        self.handle_request()
544
      # TODO: There could be children running at this point
545
    finally:
546
      sighandler.Reset()
539 547

  
540 548

  
541 549
class ForkingHTTPServer(SocketServer.ForkingMixIn, NodeDaemonHttpServer):
......
611 619
                     stderr_logging=not options.fork)
612 620
  logging.info("ganeti node daemon startup")
613 621

  
614
  global _EXIT_GANETI_NODED
615

  
616 622
  if options.fork:
617
    httpd = ForkingHTTPServer(('', port))
623
    server = ForkingHTTPServer(('', port))
618 624
  else:
619
    httpd = NodeDaemonHttpServer(('', port))
620

  
621
  # FIXME: updating _EXIT_GANETI_NODED doesn't work when forking
622
  while (not _EXIT_GANETI_NODED):
623
    httpd.handle_request()
625
    server = NodeDaemonHttpServer(('', port))
624 626

  
627
  server.serve_forever()
625 628

  
626 629
if __name__ == '__main__':
627 630
  main()

Also available in: Unified diff