builder/extra/tools/ruby-tpm/configure/commands/start_command.rb
# Start services and bring the replicator online from a specific event ID. 
Start services and bring the replicator online from a specific event ID.
Start services and bring the replicator online from a specific event ID .
def start_services_from_event
    dynamic_props = @config.getProperty(REPL_SVC_DYNAMIC_CONFIG)
    from_event = get_additional_property(StartCommand::FROM_EVENT)
    from_master_backup_event = get_additional_property(StartCommand::FROM_MASTER_BACKUP_EVENT)
    debug "dynamic_props: #{dynamic_props}"
    debug "Option from_event: #{from_event}"
    debug "Option from_master_backup_event: #{from_master_backup_event}"
    if from_master_backup_event == "xtrabackup"
      info "Seeking MySQL event ID from restored Xtrabackup dump"
      xtrabackup_binlog_info = @config.getProperty(REPL_MYSQL_DATADIR) + "/xtrabackup_binlog_info"
      if ! File.exists?(xtrabackup_binlog_info)
        error "Unable to find binlog position from Xtrabackup: #{xtrabackup_binlog_info}"
      end
      binlog_info = `cat #{xtrabackup_binlog_info}`
      debug "xtrabackup_binlog_info: #{binlog_info}"
      if binlog_info =~ /\.([0-9]+)\s*([0-9]+)\s*$/
        from_event = $1 + ":" + $2
      else
        error "Unable to locate binlog file name and offset: #{binlog_info}"
      end
      info "Located binlog event ID from Xtrabackup: #{from_event}"
    elsif from_master_backup_event == "mysqldump"
      info "Seeking MySQL event ID from restored mysqldump" 
      master_info = @config.getProperty(REPL_MYSQL_DATADIR) + "/master.info" 
      if ! File.exists?(master_info) 
        error "Unable to find binlog position from master_info: #{master_info}" 
      end 
      binlog_info = `cat #{master_info} | head -3 | tail -2 | tr '\n' ' '` 
      debug "master_info: #{binlog_info}" 
      if binlog_info =~ /\.([0-9]+)\s*([0-9]+)\s*$/ 
        from_event = $1 + ":" + $2 
      else 
        error "Unable to locate binlog file name and offset: #{binlog_info}" 
      end 
      info "Located binlog event ID from Master_info: #{from_event}" 
    elsif from_master_backup_event == "snapshot"
      info "Seeking MySQL event ID from restored file system snapshot"
      errorLogVar = mysql("show variables like 'log_error'")
      if errorLogVar =~ /log_error\s+(\/.*)$/
        errorLog = $1
      end
      debug "Error log output: spec=#{errorLog} query output=#{errorLogVar}"
      if File.exists?(errorLog)
        debug "Error log found"
      else
        error "Unable to find MySQL error log; check permissions: #{errorLog}"
      end
      if @config.getProperty(ROOT_PREFIX) == "true"
        sudo = "sudo -n"
      else
        sudo = ""
      end
      binlog_notice = cmd_result("#{sudo} grep 'Last MySQL binlog file position' #{errorLog}|tail -1")
      if binlog_notice =~ /position\s+[0-9]+\s+([0-9]+), file name.*\.([0-9]+)/
        from_event = $2 + ":" + $1
      else
        error "Unable to locate binlog file name and offset: #{binlog_notice}"
      end
      info "Located last binlog event ID from MySQL log: #{from_event}"
    end
    if from_event != nil
      configure_dynamic_props(dynamic_props, "false")
    end
    if from_event != nil
      info("Starting the replicator")
      info(cmd_result("#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/replicator start"))
      info("Bringing replicator online from event ID: #{from_event}")
      trepctl = "#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/trepctl"
      begin
        Timeout.timeout(30) {
          while true
            begin
              cmd_result("#{trepctl} services")
              break
            rescue CommandError
            end
          end
        }
      rescue Timeout::Error
        cmd_result("#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/replicator stop")
        raise "Unable to connect to the replicator to confirm successful start"
      end
      begin
        info(cmd_result("#{trepctl} online -from-event #{from_event}"))
      rescue CommandError
        raise "Unable to bring the replicator online at #{from_event}"
      end
      auto_enable = @config.getProperty(REPL_AUTOENABLE)
      debug "auto_enable: #{auto_enable}"
      if auto_enable == "true"
        configure_dynamic_props(dynamic_props, "true")
      end
    end
    info("Starting all services")
    info(cmd_result("#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/cluster-home/bin/startall", true))
  end
def start_services_from_event dynamic_props = @config . getProperty ( REPL_SVC_DYNAMIC_CONFIG ) from_event = get_additional_property ( StartCommand :: FROM_EVENT ) from_master_backup_event = get_additional_property ( StartCommand :: FROM_MASTER_BACKUP_EVENT ) debug "dynamic_props: #{dynamic_props}" debug "Option from_event: #{from_event}" debug "Option from_master_backup_event: #{from_master_backup_event}" if from_master_backup_event == "xtrabackup" info "Seeking MySQL event ID from restored Xtrabackup dump" xtrabackup_binlog_info = @config . getProperty ( REPL_MYSQL_DATADIR ) + "/xtrabackup_binlog_info" if ! File . exists? ( xtrabackup_binlog_info ) error "Unable to find binlog position from Xtrabackup: #{xtrabackup_binlog_info}" end binlog_info = ` cat  #{ xtrabackup_binlog_info } ` debug "xtrabackup_binlog_info: #{binlog_info}" if binlog_info =~ / \. ([0-9]+) \s *([0-9]+) \s *$ / from_event = $1 + ":" + $2 else error "Unable to locate binlog file name and offset: #{binlog_info}" end info "Located binlog event ID from Xtrabackup: #{from_event}" elsif from_master_backup_event == "mysqldump" info "Seeking MySQL event ID from restored mysqldump" master_info = @config . getProperty ( REPL_MYSQL_DATADIR ) + "/master.info" if ! File . exists? ( master_info ) error "Unable to find binlog position from master_info: #{master_info}" end binlog_info = ` cat  #{ master_info }  | head -3 | tail -2 | tr ' \n ' ' ' ` debug "master_info: #{binlog_info}" if binlog_info =~ / \. ([0-9]+) \s *([0-9]+) \s *$ / from_event = $1 + ":" + $2 else error "Unable to locate binlog file name and offset: #{binlog_info}" end info "Located binlog event ID from Master_info: #{from_event}" elsif from_master_backup_event == "snapshot" info "Seeking MySQL event ID from restored file system snapshot" errorLogVar = mysql ( "show variables like 'log_error'" ) if errorLogVar =~ / log_error \s +( \/ .*)$ / errorLog = $1 end debug "Error log output: spec=#{errorLog} query output=#{errorLogVar}" if File . exists? ( errorLog ) debug "Error log found" else error "Unable to find MySQL error log; check permissions: #{errorLog}" end if @config . getProperty ( ROOT_PREFIX ) == "true" sudo = "sudo -n" else sudo = "" end binlog_notice = cmd_result ( "#{sudo} grep 'Last MySQL binlog file position' #{errorLog}|tail -1" ) if binlog_notice =~ / position \s +[0-9]+ \s +([0-9]+), file name.* \. ([0-9]+) / from_event = $2 + ":" + $1 else error "Unable to locate binlog file name and offset: #{binlog_notice}" end info "Located last binlog event ID from MySQL log: #{from_event}" end if from_event != nil configure_dynamic_props ( dynamic_props , "false" ) end if from_event != nil info ( "Starting the replicator" ) info ( cmd_result ( "#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/replicator start" ) ) info ( "Bringing replicator online from event ID: #{from_event}" ) trepctl = "#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/trepctl" begin Timeout . timeout ( 30 ) { while true begin cmd_result ( "#{trepctl} services" ) break rescue CommandError end end } rescue Timeout :: Error cmd_result ( "#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/tungsten-replicator/bin/replicator stop" ) raise "Unable to connect to the replicator to confirm successful start" end begin info ( cmd_result ( "#{trepctl} online -from-event #{from_event}" ) ) rescue CommandError raise "Unable to bring the replicator online at #{from_event}" end auto_enable = @config . getProperty ( REPL_AUTOENABLE ) debug "auto_enable: #{auto_enable}" if auto_enable == "true" configure_dynamic_props ( dynamic_props , "true" ) end end info ( "Starting all services" ) info ( cmd_result ( "#{@config.getProperty(CURRENT_RELEASE_DIRECTORY)}/cluster-home/bin/startall" , true ) ) end
Start services and bring the replicator online from a specific event ID.
Start services and bring the replicator online from a specific event ID .
# Get information required to configure replicator.  # If we need to seek the event from a master backup, find it now.  # Parse the Xtrabackup file.  ## The binlog position can be obtained from master.info as ## the mysqldump file contained a change master command # Parse the Xtrabackup file.  # Find the error log and ensure it is readable.  # Grep for the last position noted in the log.   # If we now have an event ID, prep the replicator by turning off  # auto_enable.   # If we have an event ID, start the replicator with the event ID.   # Start the replicator.  # Put replicator online.  # Restore dynamic.properties if auto_enable is true.  # Start services. 