Revision 7dfb83c2

b/daemons/ganeti-watcher
39 39
from ganeti import errors
40 40
from ganeti import opcodes
41 41
from ganeti import cli
42
from ganeti import luxi
42 43

  
43 44

  
44 45
MAXTRIES = 5
......
69 70
  return "%s%s\n" % (prefix, ('\n' + prefix).join(s.splitlines()))
70 71

  
71 72

  
73
def StartMaster():
74
  """Try to start the master daemon.
75

  
76
  """
77
  result = utils.RunCmd(['ganeti-masterd'])
78
  if result.failed:
79
    logging.error("Can't start the master daemon: output '%s'", result.output)
80
  return not result.failed
81

  
82

  
72 83
class WatcherState(object):
73 84
  """Interface to a state file recording restart attempts.
74 85

  
......
441 452
  utils.SetupLogging(constants.LOG_WATCHER, debug=options.debug,
442 453
                     stderr_logging=options.debug)
443 454

  
455
  update_file = True
444 456
  try:
445 457
    notepad = WatcherState()
446 458
    try:
......
448 460
        client = cli.GetClient()
449 461
      except errors.OpPrereqError:
450 462
        # this is, from cli.GetClient, a not-master case
463
        logging.debug("Not on master, exiting")
451 464
        sys.exit(constants.EXIT_SUCCESS)
465
      except luxi.NoMasterError, err:
466
        logging.warning("Master seems to be down (%s), trying to restart",
467
                        str(err))
468
        if not StartMaster():
469
          logging.critical("Can't start the master, exiting")
470
          update_file = False
471
          sys.exit(constants.EXIT_FAILURE)
472
        # else retry the connection
473
        client = cli.GetClient()
452 474

  
453 475
      try:
454 476
        watcher = Watcher(options, notepad)
......
458 480

  
459 481
      watcher.Run()
460 482
    finally:
461
      notepad.Save()
483
      if update_file:
484
        notepad.Save()
485
      else:
486
        logging.debug("Not updating status file due to failure")
462 487
  except SystemExit:
463 488
    raise
464 489
  except NotMasterError:

Also available in: Unified diff