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
#before_logging, #log_error_stderr, #log_info_stdout, #log_warn_stderr
Class Method Details
.slop_start ⇒ Object
6
7
8
9
10
|
# File 'lib/flydata/command/sender.rb', line 6
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/flydata/command/sender.rb', line 65
def flush_client_buffer(options = {})
unless process_exist?
return true if client_buffer_empty?
log_info_stdout("Process doesn't exist. But, the client buffer is not empty!!") unless options[:quiet]
start(options)
end
log_info_stdout('Stopping input plugins and flushing the client buffer.') unless options[:quiet]
Kernel.system("kill -USR1 `cat #{pid_file}`")
retry_count = 12
1.upto(retry_count) do |i|
return true if client_buffer_empty?
log_info_stdout("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
109
110
111
112
113
114
115
116
|
# File 'lib/flydata/command/sender.rb', line 109
def kill_all(optiosn = {})
if Kernel.system("ps ax | grep 'flydata' | grep -v grep | awk '{print \"kill \" $1}' | sh")
log_info_stdout("Done.") unless options[:quiet]
return true
else
raise 'Something has gone wrong...'
end
end
|
#process_exist? ⇒ Boolean
105
106
107
108
|
# File 'lib/flydata/command/sender.rb', line 105
def process_exist?
`[ -f #{pid_file} ] && pgrep -P \`cat #{pid_file}\``.to_i > 0
end
|
#restart(options = {}) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/flydata/command/sender.rb', line 84
def restart(options = {})
if process_exist?
log_info_stdout('Restarting sender process.') unless options[:quiet]
if Kernel.system("kill -HUP `cat #{pid_file}`")
log_info_stdout('Done.') unless options[:quiet]
return true
else
raise 'Something has gone wrong..'
end
else
log_info_stdout("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
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}) 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?
log_info_stdout("Process is still running. Please stop process first.") unless options[:quiet]
return
end
orphan_processes.each do |pid|
Process.kill(:TERM, pid)
end
wait_until_server_ready(options)
dp = flydata.data_port.get
AgentCompatibilityCheck.new(dp).check
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)
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
|
#status ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/flydata/command/sender.rb', line 98
def status
if process_exist?
log_info_stdout("Process is running.")
else
log_info_stdout("Process is not running.")
end
end
|
#stop(options = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/flydata/command/sender.rb', line 52
def stop(options = {})
unless process_exist?
log_info_stdout("Process doesn't exist.") unless options[:quiet]
return true
end
log_info_stdout('Stopping sender process.') unless options[:quiet]
if Kernel.system("kill `cat #{pid_file}`") and wait_until_client_stop(options)
log_info_stdout('Done.') unless options[:quiet]
return true
end
raise 'Something has gone wrong..'
end
|