- watcher = Watcher()
- except errors.ConfigurationError:
- # Just exit if there's no configuration
- sys.exit(constants.EXIT_SUCCESS)
- watcher.Run()
- watcher.WriteReport(sys.stdout)
+ try:
+ client = cli.GetClient()
+ except errors.OpPrereqError:
+ # this is, from cli.GetClient, a not-master case
+ logging.debug("Not on master, exiting")
+ update_file = True
+ sys.exit(constants.EXIT_SUCCESS)
+ except luxi.NoMasterError, err:
+ logging.warning("Master seems to be down (%s), trying to restart",
+ str(err))
+ if not StartMaster():
+ logging.critical("Can't start the master, exiting")
+ sys.exit(constants.EXIT_FAILURE)
+ # else retry the connection
+ client = cli.GetClient()
+
+ # we are on master now (use _PID but is the same as daemon name)
+ EnsureDaemon(constants.RAPI_PID)
+
+ try:
+ watcher = Watcher(options, notepad)
+ except errors.ConfigurationError:
+ # Just exit if there's no configuration
+ update_file = True
+ sys.exit(constants.EXIT_SUCCESS)
+
+ watcher.Run()
+ update_file = True
+
+ finally:
+ if update_file:
+ notepad.Save()
+ else:
+ logging.debug("Not updating status file due to failure")
+ except SystemExit:
+ raise