Method: Flydata::Command::Sender#start

Defined in:
lib/flydata/command/sender.rb

#start(options_or_show_final_message = {show_final_message: true}) ⇒ Object

For backward compatibility. Use only as options going forward



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/flydata/command/sender.rb', line 17

def start(options_or_show_final_message = {show_final_message: true}) # For backward compatibility. Use only as options going forward
  if options_or_show_final_message.kind_of? Hash
    options = options_or_show_final_message
  else
    options = {show_final_message: options_or_show_final_message}
  end

  # Check if process exist
  if process_exist?
    log_info_stdout("Process is still running. Please stop process first.") unless options[:quiet]
    return
  end

  dp = flydata.data_port.get
  if dp['paused']
    raise "This application has been stopped. Process cannot be started."
  end

  if agent_locked?
    log_info_stdout("Agent was not shut down properly.  Agent will check the status and fix itself if necessary.")
    repair_opts = Flydata::Command::Sync.slop_repair
    repair_opts.parse!(["-y"])
    sync = Flydata::Command::Sync.new(repair_opts)
    sync.send(:_repair) # call internal method to bypass command lock
    if agent_locked?
      raise "Agent was not able to recover from the previous unexpected shutdown.  Please contact [email protected] to resolve the issue."
    end
  end

  # Ends orphan_proceses if there is any
  orphan_processes.each do |pid|
    Process.kill(:TERM, pid)
  end

  wait_until_server_ready(options)

  AgentCompatibilityCheck.new(dp).check

  fluentd_started = false
  start_fluentd = Proc.new do
    # Start sender(fluentd) process
    log_info_stdout("Starting FlyData Agent sender process.") unless options[:quiet]
    raw_start(options)

    wait_until_client_ready(options)
    #wait_until_logs_uploaded
    fluentd_started = true
  end

  quiet_option = options[:quiet]
  # surpress messages if fluentd is started in #try_initial_sync
  options[:quiet] = true
  Flydata::Command::Sync.new.try_initial_sync(
    source_pos_ready_callback: start_fluentd,
    no_email: opts.no_email?,
    auto_create: options[:auto_create] || opts.auto_create?,
    slop_opts: opts,
  )
  options[:quiet] = quiet_option
  start_fluentd.call unless fluentd_started
  if options[:show_final_message] && !options[:quiet]
    data_port = flydata.data_port.get
    log_info_stdout("Go to your Dashboard! #{flydata.flydata_api_host}/dashboard")
    log_info_stdout "Please Note: Records and Total Size are updated every 10-20 minutes.\n"
  end
end