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



11
12
13
14
15
16
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
# File 'lib/flydata/command/sender.rb', line 11

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

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

  wait_until_server_ready(options)

  dp = flydata.data_port.get
  AgentCompatibilityCheck.new(dp).check

  # Start sender(fluentd) process
  log_info_stdout("Starting sender process.") unless options[:quiet]
  Dir.chdir(FLYDATA_HOME){
    Kernel.system("bash #{FLYDATA_SERVERINFO}", :out => [FLYDATA_LOG,'a'], :err => [FLYDATA_LOG,'a'])
    daemon_opt = opts.no_daemon? ? "" : daemon_option
    Kernel.system("ruby `which fluentd` #{daemon_opt} -l #{FLYDATA_LOG} -c #{FLYDATA_CONF} -p #{FLYDATA_FLUENT_PLUGIN_DIR}")
  }
  Kernel.sleep 5

  wait_until_client_ready(options)
  #wait_until_logs_uploaded
  if options[:show_final_message] && !options[:quiet]
    data_port = flydata.data_port.get
    log_info_stdout("Go to your Dashboard! #{flydata.flydata_api_host}/data_ports/#{data_port['id']}")
    log_info_stdout <<EOF
Please Note: Records and Total Size are updated every 10-20 minutes.
EOF
  end
end