Revision 81198f6e daemons/ganeti-noded

b/daemons/ganeti-noded
52 52
queue_lock = None
53 53

  
54 54

  
55
def _PrepareQueueLock():
56
  """Try to prepare the queue lock.
57

  
58
  @return: None for success, otherwise an exception object
59

  
60
  """
61
  global queue_lock # pylint: disable-msg=W0603
62

  
63
  if queue_lock is not None:
64
    return None
65

  
66
  # Prepare job queue
67
  try:
68
    queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
69
    return None
70
  except EnvironmentError, err:
71
    return err
72

  
73

  
55 74
def _RequireJobQueueLock(fn):
56 75
  """Decorator for job queue manipulating functions.
57 76

  
......
61 80
  def wrapper(*args, **kwargs):
62 81
    # Locking in exclusive, blocking mode because there could be several
63 82
    # children running at the same time. Waiting up to 10 seconds.
83
    if _PrepareQueueLock() is not None:
84
      raise errors.JobQueueError("Job queue failed initialization,"
85
                                 " cannot update jobs")
64 86
    queue_lock.Exclusive(blocking=True, timeout=QUEUE_LOCK_TIMEOUT)
65 87
    try:
66 88
      return fn(*args, **kwargs)
......
803 825
  """Main node daemon function, executed with the PID file held.
804 826

  
805 827
  """
806
  global queue_lock # pylint: disable-msg=W0603
807

  
808 828
  # Read SSL certificate
809 829
  if options.ssl:
810 830
    ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key,
......
812 832
  else:
813 833
    ssl_params = None
814 834

  
815
  # Prepare job queue
816
  queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
835
  err = _PrepareQueueLock()
836
  if err is not None:
837
    # this might be some kind of file-system/permission error; while
838
    # this breaks the job queue functionality, we shouldn't prevent
839
    # startup of the whole node daemon because of this
840
    logging.critical("Can't init/verify the queue, proceeding anyway: %s", err)
817 841

  
818 842
  mainloop = daemon.Mainloop()
819 843
  server = NodeHttpServer(mainloop, options.bind_address, options.port,

Also available in: Unified diff