cloudblocks 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/quartz +15 -14
- data/lib/plugins/redis.rb +91 -0
- metadata +37 -14
data/bin/quartz
CHANGED
@@ -5,9 +5,11 @@ require File.expand_path("../../lib/cloud-quartz", __FILE__)
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'socket'
|
7
7
|
require 'logger'
|
8
|
+
require 'highline/import'
|
8
9
|
begin
|
9
10
|
gem 'eventmachine', '~>1.0.0.beta.4'
|
10
11
|
gem 'faye', '~>0.8.0'
|
12
|
+
gem 'highline', '~>1.6.11'
|
11
13
|
|
12
14
|
require 'eventmachine'
|
13
15
|
require 'faye'
|
@@ -138,8 +140,7 @@ def load_plugins
|
|
138
140
|
else
|
139
141
|
@log.error "Invalid plugin found #{clazz}"
|
140
142
|
end
|
141
|
-
rescue
|
142
|
-
@log.error "Error during loading plugin #{classname} due to #{exc}"
|
143
|
+
rescue
|
143
144
|
end
|
144
145
|
end
|
145
146
|
end
|
@@ -177,8 +178,9 @@ def get_job
|
|
177
178
|
EM.defer(operation)
|
178
179
|
else
|
179
180
|
@log.error "No plugin found with uid #{guid}"
|
180
|
-
|
181
|
-
|
181
|
+
job_id = message['job_id']
|
182
|
+
data = { :run_start => Time.now.utc.to_i, :run_end => Time.now.utc.to_i, :agent_uid => @agent_id, :ok => false, :fail_reason => "Requested plugin not found. Does this agent support this job type?" }
|
183
|
+
@quartz.post_results(job_id, data)
|
182
184
|
end
|
183
185
|
end
|
184
186
|
else
|
@@ -234,9 +236,9 @@ def run
|
|
234
236
|
Signal.trap('TERM'){ stop }
|
235
237
|
|
236
238
|
if @realtime
|
237
|
-
@log.info "Listening to realtime nofitifications from /quartz/
|
239
|
+
@log.info "Listening to realtime nofitifications from /quartz/agents/#{@agent_id} on #{@faye_url}"
|
238
240
|
client = Faye::Client.new(@faye_url)
|
239
|
-
client.subscribe("/quartz/
|
241
|
+
client.subscribe("/quartz/agents/#{@agent_id}") do |message|
|
240
242
|
@log.info "Got realtime notice for a new job #{message}"
|
241
243
|
get_job
|
242
244
|
end
|
@@ -269,13 +271,13 @@ str_version = "0.0.#{@version}"
|
|
269
271
|
config_file = 'cloudblocks.yaml'
|
270
272
|
@pid_file = 'quartz.pid'
|
271
273
|
@log_file = 'quartz.log'
|
272
|
-
@config_dir = File.join(
|
274
|
+
@config_dir = File.join(File.expand_path('~'), '.cloudblocks')
|
273
275
|
@config_full = File.join(@config_dir, config_file)
|
274
276
|
@pid_full = File.join('/tmp', @pid_file)
|
275
277
|
@log_full = File.join('/tmp', @log_file)
|
276
278
|
|
277
279
|
@api_key = ''
|
278
|
-
@faye_url = 'https://socket.thecloudblocks.com:8443/'
|
280
|
+
@faye_url = 'https://socket.thecloudblocks.com:8443/push/'
|
279
281
|
commands = %w[register unregister start stop]
|
280
282
|
|
281
283
|
@plugins = {}
|
@@ -368,8 +370,7 @@ end
|
|
368
370
|
# still no api key, we need to get it
|
369
371
|
if @api_key.empty?
|
370
372
|
puts 'CloudBlocks CloudQuartz'
|
371
|
-
|
372
|
-
@api_key = gets.chomp
|
373
|
+
@api_key = ask('Please enter your API key. (you can find it at https://www.thecloudblocks.com/me): ')
|
373
374
|
if @api_key.length != 32
|
374
375
|
puts 'Invalid API key'
|
375
376
|
exit -1
|
@@ -381,13 +382,13 @@ end
|
|
381
382
|
|
382
383
|
# no agent id?
|
383
384
|
if @agent_id.empty?
|
384
|
-
|
385
|
-
if
|
385
|
+
q = ask("Register the agent? ") { |q| q.default = "Y" }
|
386
|
+
if q.chomp.downcase != 'n'
|
386
387
|
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url)
|
387
388
|
register
|
388
389
|
|
389
|
-
|
390
|
-
if
|
390
|
+
q = ask("Start the agent as daemon? ") { |q| q.default = "Y" }
|
391
|
+
if q.chomp.downcase != 'n'
|
391
392
|
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id)
|
392
393
|
start
|
393
394
|
else
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Redis < QuartzPlugin
|
5
|
+
|
6
|
+
def info
|
7
|
+
{ :uid => "6342c1ef0d8bb2a47ab1362a6b02c058", :name => "Redis Backup", :version => "0.0.0" }
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(message)
|
11
|
+
pl = payload(message)
|
12
|
+
|
13
|
+
@job_name = pl['job_name'].gsub(/[^\w\s_-]+/, '').gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2').gsub(/\s/, '_')
|
14
|
+
@redisdump_utility = pl['redis client'] || '/usr/bin/redis-cli'
|
15
|
+
@name = pl['db name'] || 'dump'
|
16
|
+
@password = pl['password']
|
17
|
+
@socket = pl['socket']
|
18
|
+
@host = pl['host'] || '127.0.0.1'
|
19
|
+
@port = pl['port'] || 6379
|
20
|
+
@additional_options = pl['additional options'] || []
|
21
|
+
@path = pl['db path']
|
22
|
+
@dump_path = pl['backup folder']
|
23
|
+
|
24
|
+
@name = 'dump' if @name.empty?
|
25
|
+
@host = '127.0.0.1' if @host.empty?
|
26
|
+
@port = 6379 if @port.empty?
|
27
|
+
@additional_options = [] if @additional_options.empty?
|
28
|
+
@redisdump_utility = '/usr/bin/redis-cli' if @redisdump_utility.empty?
|
29
|
+
|
30
|
+
save_result = invoke_save
|
31
|
+
return save_result unless save_result.nil?
|
32
|
+
|
33
|
+
result = copy
|
34
|
+
if result[:ok]
|
35
|
+
run_result(true, "Redis Backup finished successfully")
|
36
|
+
else
|
37
|
+
run_result(false, result[:message])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
## based on Backup Gem with minor modifications
|
44
|
+
|
45
|
+
def database
|
46
|
+
"#{@name}.rdb"
|
47
|
+
end
|
48
|
+
|
49
|
+
def credential_options
|
50
|
+
@password.to_s.empty? ? '' : "-a '#{@password}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
def connectivity_options
|
54
|
+
%w[host port socket].map do |option|
|
55
|
+
value = instance_variable_get("@#{option}")
|
56
|
+
next if value.to_s.empty?
|
57
|
+
"-#{option[0,1]} '#{value}'"
|
58
|
+
end.compact.join(' ')
|
59
|
+
end
|
60
|
+
|
61
|
+
def user_options
|
62
|
+
@additional_options.join(' ')
|
63
|
+
end
|
64
|
+
|
65
|
+
def invoke_save
|
66
|
+
command = "#{@redisdump_utility} #{credential_options} #{connectivity_options} #{user_options} SAVE"
|
67
|
+
@log.debug "Running #{command}"
|
68
|
+
response = run_shell(command)
|
69
|
+
@log.debug "redis-cli run result: #{response}"
|
70
|
+
unless response[:ok]
|
71
|
+
run_result(false, "Failed to save from server '#{response[:message]}'")
|
72
|
+
else
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def copy
|
78
|
+
src_path = File.join(@path, database)
|
79
|
+
unless File.exist?(src_path)
|
80
|
+
raise "Redis database dump not found at #{src_path}"
|
81
|
+
end
|
82
|
+
|
83
|
+
FileUtils.mkdir_p(@dump_path)
|
84
|
+
|
85
|
+
dst_path = File.join(@dump_path, database)
|
86
|
+
dump_cmd = "gzip -c #{src_path} > #{dst_path}.gz"
|
87
|
+
@log.debug "Running #{dump_cmd}"
|
88
|
+
run_shell dump_cmd
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudblocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70213937662760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.8.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70213937662760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70213937659840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.6.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70213937659840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: eventmachine
|
38
|
-
requirement: &
|
38
|
+
requirement: &70213937658000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,21 @@ dependencies:
|
|
43
43
|
version: 0.12.10
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70213937658000
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: eventmachine
|
49
|
+
requirement: &70213937651580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0.beta.4
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70213937651580
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: faye
|
49
|
-
requirement: &
|
60
|
+
requirement: &70213937650380 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: 0.8.0
|
55
66
|
type: :runtime
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70213937650380
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: open4
|
60
|
-
requirement: &
|
71
|
+
requirement: &70213937649300 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.3.0
|
66
77
|
type: :runtime
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70213937649300
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: fog
|
71
|
-
requirement: &
|
82
|
+
requirement: &70213937648440 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,7 +87,18 @@ dependencies:
|
|
76
87
|
version: 1.1.2
|
77
88
|
type: :runtime
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70213937648440
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: highline
|
93
|
+
requirement: &70213937647060 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.6.11
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70213937647060
|
80
102
|
description: See http://www.thecloudblocks.com for more info
|
81
103
|
email: khash@thecloudblocks.com
|
82
104
|
executables:
|
@@ -92,6 +114,7 @@ files:
|
|
92
114
|
- lib/plugins/mysql.rb
|
93
115
|
- lib/plugins/quartz_plugin.rb
|
94
116
|
- lib/plugins/rake.rb
|
117
|
+
- lib/plugins/redis.rb
|
95
118
|
- lib/plugins/rotater.rb
|
96
119
|
- lib/plugins/s3backup.rb
|
97
120
|
- lib/plugins/shell.rb
|