Class: Flydata::Command::Sender
- Inherits:
-
Base
- Object
- Base
- Flydata::Command::Sender
show all
- Defined in:
- lib/flydata/command/sender.rb
Instance Attribute Summary
Attributes inherited from Base
#opts
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#ask_input_table_name, #ask_yes_no, #choose_one, #flydata, #initialize, #newline, #register_crontab, #retrieve_data_entries, #separator
Class Method Details
.slop_start ⇒ Object
4
5
6
7
8
|
# File 'lib/flydata/command/sender.rb', line 4
def self.slop_start
Slop.new do
on 'n', 'no-daemon', 'Start FlyData agent as a regular program'
end
end
|
Instance Method Details
#flush_client_buffer(options = {}) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/flydata/command/sender.rb', line 54
def flush_client_buffer(options = {})
unless process_exist?
return true if client_buffer_empty?
say("Process doesn't exist. But, the client buffer is not empty!!") unless options[:quiet]
start(options)
end
say('Stopping input plugins and flushing the client buffer.') unless options[:quiet]
Kernel.system("kill -USR1 `cat #{FLYDATA_HOME}/flydata.pid`")
retry_count = 12
1.upto(retry_count) do |i|
return true if client_buffer_empty?
say("Waiting for the buffer to get empty... (#{i}/#{retry_count})") unless options[:quiet]
Kernel.sleep 5
end
raise 'Something is wrong! Unable to flush client buffer'
end
|
#kill_all(optiosn = {}) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/flydata/command/sender.rb', line 98
def kill_all(optiosn = {})
if Kernel.system("ps ax | grep 'flydata' | grep -v grep | awk '{print \"kill \" $1}' | sh")
say("Done.") unless options[:quiet]
return true
else
raise 'Something has gone wrong...'
end
end
|
#process_exist? ⇒ Boolean
94
95
96
97
|
# File 'lib/flydata/command/sender.rb', line 94
def process_exist?
`[ -f #{FLYDATA_HOME}/flydata.pid ] && pgrep -P \`cat #{FLYDATA_HOME}/flydata.pid\``.to_i > 0
end
|
#restart(options = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/flydata/command/sender.rb', line 73
def restart(options = {})
if process_exist?
say('Restarting sender process.') unless options[:quiet]
if Kernel.system("kill -HUP `cat #{FLYDATA_HOME}/flydata.pid`")
say('Done.') unless options[:quiet]
return true
else
raise 'Something has gone wrong..'
end
else
say("Process doesn't exist.") unless options[:quiet]
start(options)
end
end
|
#start(options_or_show_final_message = {show_final_message: true}) ⇒ Object
For backward compatibility. Use only as options going forward
9
10
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
|
# File 'lib/flydata/command/sender.rb', line 9
def start(options_or_show_final_message = {show_final_message: true}) 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
if process_exist?
say("Process is still running. Please stop process first.") unless options[:quiet]
return
end
wait_until_server_ready(options)
say('Starting sender process.') unless options[:quiet]
Dir.chdir(FLYDATA_HOME){
daemon_option = opts.no_daemon? ? "" : "-d #{FLYDATA_HOME}/flydata.pid"
Kernel.system("fluentd #{daemon_option} -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf -p #{File.dirname(__FILE__)}/../fluent-plugins")
}
Kernel.sleep 5
wait_until_client_ready(options)
if options[:show_final_message] && !options[:quiet]
data_port = flydata.data_port.get
say("Go to your Dashboard! #{flydata.flydata_api_host}/data_ports/#{data_port['id']}")
say <<EOF
Please Note: Records and Total Size are updated every 10-20 minutes.
EOF
end
end
|
#status ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/flydata/command/sender.rb', line 87
def status
if process_exist?
say("Process is running.")
else
say("Process is not running.")
end
end
|
#stop(options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/flydata/command/sender.rb', line 41
def stop(options = {})
unless process_exist?
say("Process doesn't exist.") unless options[:quiet]
return true
end
say('Stopping sender process.') unless options[:quiet]
if Kernel.system("kill `cat #{FLYDATA_HOME}/flydata.pid`") and wait_until_client_stop(options)
say('Done.') unless options[:quiet]
return true
end
raise 'Something has gone wrong..'
end
|