flydata 0.0.1.2011102602 → 0.0.1.2011102901
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/flydata.gemspec +2 -2
- data/lib/flydata/cli.rb +9 -0
- data/lib/flydata/command/base.rb +6 -1
- data/lib/flydata/command/routine.rb +1 -0
- data/lib/flydata/command/sender.rb +46 -29
- data/lib/flydata/command/setlogdel.rb +15 -6
- data/lib/flydata/command/setup.rb +21 -7
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.1.
|
1
|
+
0.0.1.2011102901
|
data/flydata.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "flydata"
|
8
|
-
s.version = "0.0.1.
|
8
|
+
s.version = "0.0.1.2011102901"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Koichi Fujikawa"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-29"
|
13
13
|
s.description = "FlyData Command Line Interface"
|
14
14
|
s.email = "sysadmin@flydata.co"
|
15
15
|
s.executables = ["flydata"]
|
data/lib/flydata/cli.rb
CHANGED
@@ -35,6 +35,15 @@ Usage: flydata COMMAND
|
|
35
35
|
stop # stop flydata process
|
36
36
|
restart # restart flydata process
|
37
37
|
setlogdel # show and change log deletion settting
|
38
|
+
|
39
|
+
If you encountered login or any other errors during setup,
|
40
|
+
please setup flydata again by following commands.
|
41
|
+
source ~/.bashrc
|
42
|
+
flydata setup
|
43
|
+
|
44
|
+
You can check the logs of sender(flydata) process.
|
45
|
+
Log path: ~/.flydata/flydata.log
|
46
|
+
|
38
47
|
EOM
|
39
48
|
end
|
40
49
|
end
|
data/lib/flydata/command/base.rb
CHANGED
@@ -6,7 +6,6 @@ module Flydata
|
|
6
6
|
end
|
7
7
|
def flydata; @api_client end
|
8
8
|
|
9
|
-
# retrieve models on servers
|
10
9
|
def retrieve_data_entries
|
11
10
|
data_entries = flydata.get('/data_entries')
|
12
11
|
unless flydata.response.code == 200
|
@@ -14,6 +13,12 @@ module Flydata
|
|
14
13
|
end
|
15
14
|
data_entries
|
16
15
|
end
|
16
|
+
def register_crontab
|
17
|
+
data_entries = retrieve_data_entries
|
18
|
+
if data_entries.any?{|e| e['log_deletion']}
|
19
|
+
Flydata::Command::Crontab.new.run
|
20
|
+
end
|
21
|
+
end
|
17
22
|
|
18
23
|
# print console
|
19
24
|
def newline; puts end
|
@@ -3,43 +3,24 @@ module Flydata
|
|
3
3
|
class Sender < Base
|
4
4
|
FLYDATA_HOME=Flydata::HOME_DIR
|
5
5
|
def start
|
6
|
+
# Check if process exist
|
6
7
|
if process_exist?
|
7
8
|
say("Process exist. Please stop process first.")
|
8
9
|
return
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
1.upto(retry_count) do |i|
|
13
|
-
break if server_ready?
|
14
|
-
say("Waiting server side active... (#{i}/#{retry_count})")
|
15
|
-
sleep 30
|
16
|
-
end
|
12
|
+
wait_until_server_ready
|
17
13
|
|
14
|
+
# Start sender(fluentd) process
|
18
15
|
say('Starting sender process.')
|
19
16
|
Dir.chdir(FLYDATA_HOME){
|
20
17
|
system("fluentd -d #{FLYDATA_HOME}/flydata.pid -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf")
|
21
18
|
}
|
22
|
-
|
23
19
|
sleep 5
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
retry_count = 10
|
29
|
-
ready = false
|
30
|
-
1.upto(retry_count) do |i|
|
31
|
-
ready ||= client_ready?
|
32
|
-
if ready and uploaded_successfully?(data_port_id)
|
33
|
-
say('Done.')
|
34
|
-
say("Go to your Dashboard! http://#{Flydata::FLYDATA_API_HOST}")
|
35
|
-
return true
|
36
|
-
end
|
37
|
-
say("Waiting client side active... (#{i}/#{retry_count})")
|
38
|
-
sleep 30
|
39
|
-
end
|
40
|
-
|
41
|
-
say('Something wrong..')
|
42
|
-
false
|
21
|
+
wait_until_client_ready
|
22
|
+
wait_until_logs_uploaded
|
23
|
+
say("Go to your Dashboard! http://#{Flydata::FLYDATA_API_HOST}")
|
43
24
|
end
|
44
25
|
def stop
|
45
26
|
unless process_exist?
|
@@ -51,10 +32,8 @@ module Flydata
|
|
51
32
|
if system("kill `cat #{FLYDATA_HOME}/flydata.pid`")
|
52
33
|
say('Done.')
|
53
34
|
return true
|
54
|
-
else
|
55
|
-
say('Something wrong..')
|
56
35
|
end
|
57
|
-
|
36
|
+
raise 'Something wrong..'
|
58
37
|
end
|
59
38
|
def restart
|
60
39
|
if process_exist?
|
@@ -63,7 +42,7 @@ module Flydata
|
|
63
42
|
say('Done.')
|
64
43
|
return true
|
65
44
|
else
|
66
|
-
|
45
|
+
raise 'Something wrong..'
|
67
46
|
end
|
68
47
|
else
|
69
48
|
say("Process doesn't exist.")
|
@@ -72,6 +51,44 @@ module Flydata
|
|
72
51
|
end
|
73
52
|
|
74
53
|
private
|
54
|
+
def wait_until_server_ready
|
55
|
+
retry_count = 10
|
56
|
+
1.upto(retry_count) do |i|
|
57
|
+
return true if server_ready?
|
58
|
+
say("Waiting server side active... (#{i}/#{retry_count})")
|
59
|
+
sleep 30
|
60
|
+
end
|
61
|
+
false
|
62
|
+
end
|
63
|
+
def wait_until_client_ready
|
64
|
+
retry_count = 10
|
65
|
+
1.upto(retry_count) do |i|
|
66
|
+
if client_ready?
|
67
|
+
say("Done! Client is ready now.")
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
say("Waiting client side active... (#{i}/#{retry_count})")
|
71
|
+
sleep 30
|
72
|
+
end
|
73
|
+
raise "Somthing wrong... Please try setup command again."
|
74
|
+
end
|
75
|
+
def wait_until_logs_uploaded
|
76
|
+
say('Starting to check uploading from your server.')
|
77
|
+
data_port = flydata.data_port.get
|
78
|
+
data_port_id = data_port['id']
|
79
|
+
|
80
|
+
retry_count = 10
|
81
|
+
1.upto(retry_count) do |i|
|
82
|
+
if uploaded_successfully?(data_port_id)
|
83
|
+
say("Uploading your logs correctly.")
|
84
|
+
return true
|
85
|
+
end
|
86
|
+
say("Waiting logs uploading... (#{i}/#{retry_count})")
|
87
|
+
sleep 30
|
88
|
+
end
|
89
|
+
raise 'Cannot confirm your logs on flydata server. Something wrong..'
|
90
|
+
end
|
91
|
+
|
75
92
|
def server_ready?
|
76
93
|
data_port = flydata.data_port.get
|
77
94
|
data_port['server_status'] == 'active'
|
@@ -7,9 +7,8 @@ module Flydata
|
|
7
7
|
data_entry = choose_data_entry
|
8
8
|
return unless data_entry
|
9
9
|
# Confirm and update
|
10
|
-
if confirm_setting data_entry
|
11
|
-
|
12
|
-
end
|
10
|
+
set_log_deletion data_entry if confirm_setting data_entry
|
11
|
+
register_crontab
|
13
12
|
end
|
14
13
|
|
15
14
|
private
|
@@ -21,7 +20,8 @@ module Flydata
|
|
21
20
|
return nil
|
22
21
|
end
|
23
22
|
choices = data_entries.map {|e|
|
24
|
-
|
23
|
+
file_attr = File.writable?(e['log_path']) ? "" : "(read only)"
|
24
|
+
"#{e['display_name']}\t#{e['log_path']}\t -- Log deletion:#{boolToOnOff e['log_deletion']} #{file_attr}"
|
25
25
|
}
|
26
26
|
choices << "Cancel"
|
27
27
|
|
@@ -35,7 +35,17 @@ module Flydata
|
|
35
35
|
menu.choices(*choices) {|item| choice = item.split(' ')[0]}
|
36
36
|
end
|
37
37
|
newline
|
38
|
-
|
38
|
+
|
39
|
+
data_entry = data_entries.select{|e| e['display_name'] == choice}.first
|
40
|
+
return nil unless data_entry
|
41
|
+
|
42
|
+
if not data_entry['log_deletion'] and not File.writable?(data_entry['log_path'])
|
43
|
+
say("Failed to change setting...")
|
44
|
+
say(" This path is readonly for current user.")
|
45
|
+
say(" Change user or permission, if you want to set log deletion option.")
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
data_entry
|
39
49
|
end
|
40
50
|
def confirm_setting(data_entry)
|
41
51
|
cur_flag = data_entry['log_deletion']
|
@@ -65,7 +75,6 @@ module Flydata
|
|
65
75
|
url = "/data_entries/#{data_entry['id']}"
|
66
76
|
ret = flydata.put(url, param)
|
67
77
|
raise 'Failed to update the log deletion setting.' unless ret['success']
|
68
|
-
Flydata::Command::Crontab.new.run if !data_entry['log_deletion']
|
69
78
|
puts "Update succeeded!"
|
70
79
|
end
|
71
80
|
end
|
@@ -26,12 +26,15 @@ module Flydata
|
|
26
26
|
path = choose_log_path_from_examples
|
27
27
|
case path
|
28
28
|
when OTHER; ask_log_path
|
29
|
-
else; create_log_entry(path, ask_log_deletion)
|
29
|
+
else; create_log_entry(path, ask_log_deletion(path))
|
30
30
|
end
|
31
31
|
newline
|
32
32
|
end while more_entry?
|
33
33
|
end
|
34
34
|
|
35
|
+
# register cron if registered log deletion
|
36
|
+
register_crontab
|
37
|
+
|
35
38
|
# start client process
|
36
39
|
Flydata::Command::Sender.new.restart
|
37
40
|
end
|
@@ -43,7 +46,7 @@ module Flydata
|
|
43
46
|
if data_entries and data_entries.size > 0
|
44
47
|
puts('Registered entries. ')
|
45
48
|
data_entries.each { |data_entry|
|
46
|
-
say(" - #{data_entry['
|
49
|
+
say(" - #{data_entry['display_name']}\t#{data_entry['log_path']}")
|
47
50
|
}
|
48
51
|
true
|
49
52
|
else
|
@@ -75,13 +78,25 @@ module Flydata
|
|
75
78
|
loop do
|
76
79
|
path = Readline.readline("Enter the absolute path of your log (return to cancel): ")
|
77
80
|
return if path.empty?
|
78
|
-
|
79
|
-
|
81
|
+
if not (FileTest.file?(path) and FileTest.readable?(path))
|
82
|
+
say(" ! #{path} is not a readable file!")
|
83
|
+
elsif @last_fetched_entries and @last_fetched_entries.any?{|e| e['log_path'] == path}
|
84
|
+
say(" ! #{path} has been registered already.")
|
85
|
+
else
|
86
|
+
break
|
87
|
+
end
|
80
88
|
newline
|
81
89
|
end
|
82
|
-
create_log_entry(path, ask_log_deletion)
|
90
|
+
create_log_entry(path, ask_log_deletion(path))
|
83
91
|
end
|
84
|
-
def ask_log_deletion
|
92
|
+
def ask_log_deletion(path)
|
93
|
+
unless File.writable?(path)
|
94
|
+
say("Skip log deletion setting...")
|
95
|
+
say(" This path is readonly for current user.")
|
96
|
+
say(" Change user or permission, if you want to set log deletion option.")
|
97
|
+
newline
|
98
|
+
return
|
99
|
+
end
|
85
100
|
say("** Log deletion setting **")
|
86
101
|
say("Flydata has a log deletion feature that flydata will delete old log archives uploaded by flydata automatically.")
|
87
102
|
say("Flydata will delete logs whose last modified timestamp is 7 days ago.")
|
@@ -90,7 +105,6 @@ module Flydata
|
|
90
105
|
def create_log_entry(path, log_deletion)
|
91
106
|
data_port = flydata.data_port.get
|
92
107
|
flydata.data_entry.create(data_port_id: data_port['id'], log_path: path, log_deletion: log_deletion)
|
93
|
-
Flydata::Command::Crontab.new.run if log_deletion
|
94
108
|
say("Process successfuly!") if flydata.response.code == 200
|
95
109
|
end
|
96
110
|
def more_entry?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flydata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.2011102901
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -275,7 +275,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
275
|
version: '0'
|
276
276
|
segments:
|
277
277
|
- 0
|
278
|
-
hash:
|
278
|
+
hash: -2910616954756998492
|
279
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
280
|
none: false
|
281
281
|
requirements:
|