"".format(pidfile)) with open(pidfile, "r") as f: pid = int(f.read().strip()) except IOError: pid = None except ValueError: pid = None # Test pid presence if not pid: parser.error("Can not read pid from pidfile.") if opt.pidfile and not opt.daemon: parser.error("The option --daemon is required when using --pidfile.") # Purge log file of old data if opt.log_file is not None and not purge_log(opt.log_file, opt.log_age): parser.error("Error purging log file.") # Setup log file try: logging.basicConfig(filename=opt.log_file, level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", datefmt=DATE_FORMAT) except IOError: _, e, _ = sys.exc_info() parser.error("Error opening log file: {0}".format(str(e.args[1]))) # Create dictionary of options options = { "verbosity": opt.verbosity,
'max_delay' : opt.max_delay, 'discover' : opt.discover, 'timeout' : opt.timeout, 'demote' : opt.demote, 'quiet' : opt.quiet, 'logging' : opt.log_file is not None, 'log_file' : opt.log_file, 'no_health' : opt.no_health, } # If command = HEALTH, turn on --force if command == 'health' or command == 'gtid': options['force'] = True # Purge log file of old data if opt.log_file is not None and not purge_log(opt.log_file, opt.log_age): parser.error("Error purging log file.") # Setup log file logging.basicConfig(filename=opt.log_file, level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt=_DATE_FORMAT) try: rpl_cmds = RplCommands(master_val, slaves_val, options) rpl_cmds.execute_command(command) except UtilError, e: print "ERROR:", e.errmsg exit(1) exit(0)