Beispiel #1
0
                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.")

    # Log MySQL Utilities version string
    if opt.log_file:
        logging.info(
            MSG_UTILITIES_VERSION.format(utility=program,
                                         version=VERSION_STRING))
    try:
        rpl_cmds = RplCommands(master_val, slaves_val, options)
        if opt.daemon:
            rpl_cmds.auto_failover_as_daemon()
        else:
            rpl_cmds.auto_failover(opt.interval)
    except UtilError:
        _, e, _ = sys.exc_info()
        # log the error in case it was an usual exception
        logging.log(logging.CRITICAL, e.errmsg.strip(' '))
        print("ERROR: %s" % e.errmsg)
        sys.exit(1)
    except KeyboardInterrupt:
        sys.exit(0)

    sys.exit(0)
Beispiel #2
0
    '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)


    if opt.log_file is not None and not purge_log(opt.log_file, opt.log_age):
        parser.error("Error purging log file.")

    # Warn user about script threshold checking.
    if opt.script_threshold:
        print(SCRIPT_THRESHOLD_WARNING)

    # 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: %s" % str(e.args[1]))

    # Log MySQL Utilities version string
    if opt.log_file:
        logging.info(MSG_UTILITIES_VERSION.format(utility=program,
                                                  version=VERSION_STRING))

    try:
        rpl_cmds = RplCommands(master_val, slaves_val, options)
        rpl_cmds.execute_command(command, options)
    except UtilError:
        _, e, _ = sys.exc_info()
        print("ERROR: {0}".format(e.errmsg))
        sys.exit(1)

    sys.exit(0)
Beispiel #4
0
    'max_position'  : opt.max_position,
    'max_delay'     : opt.max_delay,
    'discover'      : opt.discover,
    'timeout'       : opt.timeout,
    'interval'      : opt.interval,
    'failover_mode' : opt.failover_mode,
    'logging'       : opt.log_file is not None,
    'log_file'      : opt.log_file,
    'force'         : opt.force,
    'post_fail'     : opt.exec_post_fail,
}

# 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.auto_failover(opt.interval)
except UtilError, e:
    print "ERROR:", e.errmsg
    exit(1)
    
exit(0)

                    pid = None
                # Test pid presence
                # 如果pid没有定义 则报告失败
                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.")

    # Log MySQL Utilities version string
    # 如果配置了日志文件则记录下版本信息
    if opt.log_file:
        logging.info(MSG_UTILITIES_VERSION.format(utility=program,
                                                  version=VERSION_STRING))
    try:
        rpl_cmds = RplCommands(master_val, slaves_val, options)
        if opt.daemon:
            rpl_cmds.auto_failover_as_daemon()
        else:
            rpl_cmds.auto_failover(opt.interval)
    except UtilError:
        _, e, _ = sys.exc_info()
        # log the error in case it was an usual exception
        logging.log(logging.CRITICAL, e.errmsg.strip(' '))
        print("ERROR: %s" % e.errmsg)
        sys.exit(1)
    except KeyboardInterrupt:
        sys.exit(0)

    sys.exit(0)