cloudblocks 0.0.11 → 0.0.12a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/chief +4 -4
- data/bin/quartz +59 -34
- data/lib/cloud-quartz.rb +12 -2
- data/lib/config-chief.rb +1 -1
- data/lib/plugins/broken.rb +6 -1
- data/lib/plugins/logrotate.rb +7 -3
- data/lib/plugins/mysql.rb +14 -7
- data/lib/plugins/quartz_plugin.rb +9 -7
- data/lib/plugins/rake.rb +6 -1
- data/lib/plugins/redis.rb +10 -6
- data/lib/plugins/rotater.rb +7 -3
- data/lib/plugins/s3backup.rb +22 -13
- data/lib/plugins/shell.rb +8 -4
- data/lib/plugins/tester.rb +6 -1
- data/lib/plugins/webget.rb +6 -1
- metadata +66 -26
data/bin/chief
CHANGED
@@ -26,7 +26,7 @@ config_dir = File.join(Dir.home, '.cloudblocks')
|
|
26
26
|
config_full = File.join(config_dir, config_file)
|
27
27
|
|
28
28
|
api_key = ''
|
29
|
-
faye_url = '
|
29
|
+
faye_url = 'http://sockets.cloudblocks.co/'
|
30
30
|
|
31
31
|
if File.exists?(config_full)
|
32
32
|
# config file present
|
@@ -35,7 +35,7 @@ if File.exists?(config_full)
|
|
35
35
|
else
|
36
36
|
# no config file
|
37
37
|
puts 'CloudBlocks ConfigChief'
|
38
|
-
puts 'Please enter your API key. (you can find it at https://
|
38
|
+
puts 'Please enter your API key. (you can find it at https://cloudblocks.co/me):'
|
39
39
|
api_key = gets
|
40
40
|
api_key = api_key.chomp
|
41
41
|
if api_key.length != 32
|
@@ -61,7 +61,7 @@ id = nil
|
|
61
61
|
OptionParser.new do |opts|
|
62
62
|
opts.banner = <<-EOF
|
63
63
|
ConfigChief. v#{str_version} (c) 2012 CloudBlocks
|
64
|
-
For more information please visit http://
|
64
|
+
For more information please visit http://cloudblocks.co
|
65
65
|
|
66
66
|
Usage: chief [options]
|
67
67
|
|
@@ -75,7 +75,7 @@ EOF
|
|
75
75
|
opts.on('-u', '--url URL', 'Server URL') do |v|
|
76
76
|
url = v
|
77
77
|
end
|
78
|
-
url = url || 'https://api.
|
78
|
+
url = url || 'https://api.cloudblocks.co'
|
79
79
|
|
80
80
|
opts.on('-k', '--key KEY', 'Config Key') do |v|
|
81
81
|
key = v
|
data/bin/quartz
CHANGED
@@ -25,7 +25,7 @@ def save_config
|
|
25
25
|
if !FileTest::directory?(@config_dir)
|
26
26
|
Dir.mkdir(@config_dir)
|
27
27
|
end
|
28
|
-
File.open(@config_full, 'w+') { |out| YAML::dump({ 'api_key' => @api_key, 'agent_id' => @agent_id }, out) }
|
28
|
+
File.open(@config_full, 'w+') { |out| YAML::dump({ 'api_key' => @api_key, 'agent_id' => @agent_id, 'secret_key' => @secret_key }, out) }
|
29
29
|
end
|
30
30
|
|
31
31
|
public
|
@@ -158,33 +158,37 @@ def plugin_meta_data
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def get_job
|
161
|
-
|
162
|
-
|
163
|
-
if result['
|
164
|
-
|
165
|
-
|
166
|
-
message = JSON.parse(result['message'])
|
167
|
-
guid = message['plugin_uid']
|
168
|
-
name = message['template_name']
|
169
|
-
drt = message['desired_run_time']
|
170
|
-
|
171
|
-
@log.info "Going to run #{name} (uid:#{guid})"
|
172
|
-
|
173
|
-
# get the plugin
|
174
|
-
if @plugins.include?(guid)
|
175
|
-
plugin = @plugins[guid]
|
176
|
-
# run it
|
177
|
-
operation = proc { run_plugin(plugin, message) }
|
178
|
-
EM.defer(operation)
|
161
|
+
begin
|
162
|
+
result = @quartz.get_job
|
163
|
+
if result['ok']
|
164
|
+
if result['empty']
|
165
|
+
@log.debug 'No jobs to run'
|
179
166
|
else
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
167
|
+
message = JSON.parse(result['message'])
|
168
|
+
guid = message['plugin_uid']
|
169
|
+
name = message['template_name']
|
170
|
+
drt = message['desired_run_time']
|
171
|
+
|
172
|
+
@log.info "Going to run #{name} (uid:#{guid})"
|
173
|
+
|
174
|
+
# get the plugin
|
175
|
+
if @plugins.include?(guid)
|
176
|
+
plugin = @plugins[guid]
|
177
|
+
# run it
|
178
|
+
operation = proc { run_plugin(plugin, message) }
|
179
|
+
EM.defer(operation)
|
180
|
+
else
|
181
|
+
@log.error "No plugin found with uid #{guid}"
|
182
|
+
job_id = message['job_id']
|
183
|
+
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?" }
|
184
|
+
@quartz.post_results(job_id, data)
|
185
|
+
end
|
184
186
|
end
|
187
|
+
else
|
188
|
+
@log.error "Failed to retrieve job due to #{result['error']}"
|
185
189
|
end
|
186
|
-
|
187
|
-
@log.error "Failed to retrieve job due to #{
|
190
|
+
rescue => exc
|
191
|
+
@log.error "Failed to retrieve job due to #{exc}"
|
188
192
|
end
|
189
193
|
end
|
190
194
|
|
@@ -222,7 +226,7 @@ def check_version
|
|
222
226
|
result = @quartz.check_version
|
223
227
|
if result['ok']
|
224
228
|
latest = result['latest']
|
225
|
-
@log.warn 'A newer version of CloudQuartz agent is available. Update the cloudblocks gem. See http://help.
|
229
|
+
@log.warn 'A newer version of CloudQuartz agent is available. Update the cloudblocks gem. See http://help.cloudblocks.co for more info' if latest > @version
|
226
230
|
end
|
227
231
|
rescue => exc
|
228
232
|
warn "Cannot connect to the server"
|
@@ -235,6 +239,16 @@ def run
|
|
235
239
|
Signal.trap('INT') { stop }
|
236
240
|
Signal.trap('TERM'){ stop }
|
237
241
|
|
242
|
+
# pulse
|
243
|
+
EM.add_periodic_timer 60 do # 1 minute
|
244
|
+
@log.debug "Pulseate"
|
245
|
+
begin
|
246
|
+
@quartz.pulse
|
247
|
+
rescue => exc
|
248
|
+
@log.error "Failed to pulsate due to #{exc.message}"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
238
252
|
if @realtime
|
239
253
|
@log.info "Listening to realtime nofitifications from /quartz/agents/#{@agent_id} on #{@faye_url}"
|
240
254
|
client = Faye::Client.new(@faye_url)
|
@@ -277,7 +291,7 @@ config_file = 'cloudblocks.yaml'
|
|
277
291
|
@log_full = File.join('/tmp', @log_file)
|
278
292
|
|
279
293
|
@api_key = ''
|
280
|
-
@faye_url = '
|
294
|
+
@faye_url = 'http://sockets.cloudblocks.co/push/'
|
281
295
|
commands = %w[register unregister start stop]
|
282
296
|
|
283
297
|
@plugins = {}
|
@@ -290,7 +304,7 @@ command = nil
|
|
290
304
|
OptionParser.new do |opts|
|
291
305
|
opts.banner = <<-EOF
|
292
306
|
CloudQuartz Agent. v#{str_version} (c) 2012 CloudBlocks
|
293
|
-
For more information please visit http://
|
307
|
+
For more information please visit http://cloudblocks.co
|
294
308
|
|
295
309
|
Usage: quartz [register|unregister|start|stop] [options]
|
296
310
|
|
@@ -300,7 +314,7 @@ EOF
|
|
300
314
|
opts.on('--url URL', 'Server URL') do |server_url|
|
301
315
|
@url = server_url
|
302
316
|
end
|
303
|
-
@url = @url || 'https://api.
|
317
|
+
@url = @url || 'https://api.cloudblocks.co'
|
304
318
|
|
305
319
|
opts.on('--agent-id AGENTID', 'Agent id') do |v|
|
306
320
|
@agent_id = v
|
@@ -331,6 +345,10 @@ EOF
|
|
331
345
|
@api_key = v
|
332
346
|
end
|
333
347
|
|
348
|
+
opts.on('--secret-key SECRETKET', 'Secret Key') do |v|
|
349
|
+
@secret_key = v
|
350
|
+
end
|
351
|
+
|
334
352
|
opts.on('-n', '--no-realtime', 'Disable realtime notifications') do |v|
|
335
353
|
@realtime = false
|
336
354
|
end
|
@@ -365,17 +383,24 @@ if (@api_key.empty? || @agent_id.empty?) && File.exists?(@config_full)
|
|
365
383
|
config = YAML::load(File.open(@config_full))
|
366
384
|
@api_key = config['api_key']
|
367
385
|
@agent_id = config['agent_id']
|
386
|
+
@secret_key = config['secret_key']
|
368
387
|
end
|
369
388
|
|
370
389
|
# still no api key, we need to get it
|
371
390
|
if @api_key.empty?
|
372
391
|
puts 'CloudBlocks CloudQuartz'
|
373
|
-
@api_key = ask('Please enter your API key. (you can find it at https://
|
392
|
+
@api_key = ask('Please enter your API key. (you can find it at https://cloudblocks.co/me): ')
|
374
393
|
if @api_key.length != 32
|
375
394
|
puts 'Invalid API key'
|
376
395
|
exit -1
|
377
396
|
end
|
378
397
|
|
398
|
+
@secret_key = ask('Please enter your Secret Key (you can find it at https://cloudblocks.co/me): ')
|
399
|
+
if @secret_key.length != 32
|
400
|
+
puts 'Invalid Secret key'
|
401
|
+
exit -1
|
402
|
+
end
|
403
|
+
|
379
404
|
save_config
|
380
405
|
puts 'Configuration Saved'
|
381
406
|
end
|
@@ -384,12 +409,12 @@ end
|
|
384
409
|
if @agent_id.empty?
|
385
410
|
q = ask("Register the agent? ") { |q| q.default = "Y" }
|
386
411
|
if q.chomp.downcase != 'n'
|
387
|
-
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url)
|
412
|
+
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :secret_key => @secret_key)
|
388
413
|
register
|
389
414
|
|
390
415
|
q = ask("Start the agent as daemon? ") { |q| q.default = "Y" }
|
391
416
|
if q.chomp.downcase != 'n'
|
392
|
-
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id)
|
417
|
+
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id, :secret_key => @secret_key)
|
393
418
|
start
|
394
419
|
else
|
395
420
|
exit 0
|
@@ -409,11 +434,11 @@ unless commands.include?(command)
|
|
409
434
|
exit -1
|
410
435
|
end
|
411
436
|
|
412
|
-
if (@agent_id.nil? || @agent_id.empty? || @agent_id.empty?) && command != 'register'
|
437
|
+
if (@agent_id.nil? || @agent_id.empty? || @agent_id.empty? || @secret_key.empty?) && command != 'register'
|
413
438
|
puts 'No Agent id found. Have you registered it yet? Use --help for more information'
|
414
439
|
exit -1
|
415
440
|
end
|
416
441
|
|
417
|
-
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id)
|
442
|
+
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id, :secret_key => @secret_key)
|
418
443
|
|
419
444
|
send(command)
|
data/lib/cloud-quartz.rb
CHANGED
@@ -9,7 +9,8 @@ class CloudQuartz
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@api_key = options[:api_key]
|
11
11
|
@agent_id = options[:agent_id]
|
12
|
-
|
12
|
+
@secret_key = options[:secret_key]
|
13
|
+
self.class.base_uri options[:url] || 'https://api.cloudblocks.co'
|
13
14
|
end
|
14
15
|
|
15
16
|
def get_job
|
@@ -32,6 +33,10 @@ class CloudQuartz
|
|
32
33
|
process(self.class.post("/job/#{job_id}/complete.json", { :headers => http_headers.merge({'Content-Type' => 'application/json'}), :body => data.to_json } ))
|
33
34
|
end
|
34
35
|
|
36
|
+
def pulse
|
37
|
+
process(self.class.get("/agent/#{@agent_id}/pulse.json", { :headers => http_headers } ))
|
38
|
+
end
|
39
|
+
|
35
40
|
def status(stat, version, plugins)
|
36
41
|
data = { :status => stat, :version => version, :plugins => plugins }
|
37
42
|
process(self.class.post("/agent/#{@agent_id}/status.json", { :headers => http_headers.merge({'Content-Type' => 'application/json'}), :body => data.to_json }))
|
@@ -40,7 +45,12 @@ class CloudQuartz
|
|
40
45
|
private
|
41
46
|
|
42
47
|
def http_headers
|
43
|
-
|
48
|
+
time = Time.now.utc.to_i
|
49
|
+
{ 'api_key' => @api_key, 'hash' => signature(time), 'time' => time.to_s }
|
50
|
+
end
|
51
|
+
|
52
|
+
def signature(time)
|
53
|
+
Digest::SHA1.hexdigest("#{@api_key}#{@secret_key}#{time}").downcase
|
44
54
|
end
|
45
55
|
|
46
56
|
def process(response)
|
data/lib/config-chief.rb
CHANGED
@@ -11,7 +11,7 @@ class ConfigChief
|
|
11
11
|
def initialize(options = {})
|
12
12
|
@api_key = options[:api_key]
|
13
13
|
@workspace = options[:workspace]
|
14
|
-
self.class.base_uri options[:url] || 'https://api.
|
14
|
+
self.class.base_uri options[:url] || 'https://api.cloudblocks.co'
|
15
15
|
end
|
16
16
|
|
17
17
|
def get_by_key(key, options = {}, params = {})
|
data/lib/plugins/broken.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
2
2
|
|
3
3
|
class Broken < QuartzPlugin
|
4
|
+
|
5
|
+
@@version_major = 0
|
6
|
+
@@version_minor = 0
|
7
|
+
@@version_revision = 1
|
8
|
+
|
4
9
|
def info
|
5
|
-
{ :uid => "04165a45fde840a9a17b41f019b3dca3", :name => "Broken", :version =>
|
10
|
+
{ :uid => "04165a45fde840a9a17b41f019b3dca3", :name => "Broken", :version => get_version }
|
6
11
|
end
|
7
12
|
|
8
13
|
def run(message)
|
data/lib/plugins/logrotate.rb
CHANGED
@@ -3,17 +3,21 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
class Logrotate < QuartzPlugin
|
5
5
|
|
6
|
+
@@version_major = 0
|
7
|
+
@@version_minor = 0
|
8
|
+
@@version_revision = 1
|
9
|
+
|
6
10
|
def info
|
7
|
-
{ :uid => "8f4286bfd946c8b08b234833673b8860", :name => "Log Rotate", :version =>
|
11
|
+
{ :uid => "8f4286bfd946c8b08b234833673b8860", :name => "Log Rotate", :version => get_version }
|
8
12
|
end
|
9
13
|
|
10
14
|
def run(message)
|
11
15
|
pl = payload(message)
|
12
16
|
|
13
|
-
@source_pattern = pl['
|
17
|
+
@source_pattern = pl['source_pattern']
|
14
18
|
@dest_folder = pl['destination']
|
15
19
|
@keep = pl['keep'].empty? ? 0 : pl['keep'].to_i
|
16
|
-
@post_run_step = pl['
|
20
|
+
@post_run_step = pl['post_rotate']
|
17
21
|
|
18
22
|
ext = Time.now.utc.strftime('%Y%m%d%H%M%S')
|
19
23
|
|
data/lib/plugins/mysql.rb
CHANGED
@@ -3,8 +3,12 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
class Mysql < QuartzPlugin
|
5
5
|
|
6
|
+
@@version_major = 0
|
7
|
+
@@version_minor = 0
|
8
|
+
@@version_revision = 1
|
9
|
+
|
6
10
|
def info
|
7
|
-
{ :uid => "67deb35a555344c8a7651c656e6c8e2e", :name => "MySQL Backup", :version =>
|
11
|
+
{ :uid => "67deb35a555344c8a7651c656e6c8e2e", :name => "MySQL Backup", :version => get_version }
|
8
12
|
end
|
9
13
|
|
10
14
|
def run(message)
|
@@ -14,17 +18,20 @@ class Mysql < QuartzPlugin
|
|
14
18
|
@log.debug "Pruned payload #{pl}"
|
15
19
|
|
16
20
|
@job_name = pl['job_name'].gsub(/[^\w\s_-]+/, '').gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2').gsub(/\s/, '_')
|
17
|
-
@mysqldump_utility = pl['
|
18
|
-
@name = pl['
|
21
|
+
@mysqldump_utility = pl['dump_utility'] || '/usr/bin/mysqldump'
|
22
|
+
@name = pl['db_name'] || :all
|
19
23
|
@username = pl['username']
|
20
24
|
@password = pl['password']
|
21
25
|
@socket = pl['socket']
|
22
26
|
@host = pl['host']
|
23
27
|
@port = pl['port']
|
24
|
-
@skip_tables = pl['
|
25
|
-
@only_tables = pl['
|
26
|
-
@additional_options = pl['
|
27
|
-
@path = pl['
|
28
|
+
@skip_tables = pl['skip_tables']
|
29
|
+
@only_tables = pl['only_tables']
|
30
|
+
@additional_options = pl['additional_options'] || ['--single-transaction', '--quick']
|
31
|
+
@path = pl['backup_folder']
|
32
|
+
|
33
|
+
@only_tables = @only_tables.split(',') unless @only_tables.nil?
|
34
|
+
@skip_tables = @skip_tables.split(',') unless @skip_tables.nil?
|
28
35
|
|
29
36
|
dump_cmd = "#{mysqldump} | gzip > '#{ File.join(@path, @job_name.downcase) }.sql.gz'"
|
30
37
|
@log.debug "Running #{dump_cmd}"
|
@@ -22,13 +22,7 @@ class QuartzPlugin
|
|
22
22
|
parsed_payload = JSON.parse(raw_payload) unless raw_payload.nil?
|
23
23
|
@log.debug "Parsed payload #{parsed_payload}"
|
24
24
|
|
25
|
-
v =
|
26
|
-
unless parsed_payload.nil?
|
27
|
-
parsed_payload.each do |p|
|
28
|
-
v = v.merge({ p['name'] => p['value']})
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
25
|
+
v = parsed_payload
|
32
26
|
v = v.merge({'job_name' => message['job_name']})
|
33
27
|
|
34
28
|
@log.debug "Payload #{v}"
|
@@ -46,4 +40,12 @@ class QuartzPlugin
|
|
46
40
|
{ :ok => false, :message => stderr.read.strip}
|
47
41
|
end
|
48
42
|
end
|
43
|
+
|
44
|
+
@@version_major = 0
|
45
|
+
@@version_minor = 0
|
46
|
+
@@version_revision = 0
|
47
|
+
|
48
|
+
def get_version
|
49
|
+
"#{@@version_major}.#{@@version_minor}.#{@@version_revision}"
|
50
|
+
end
|
49
51
|
end
|
data/lib/plugins/rake.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
2
2
|
|
3
3
|
class Rake < QuartzPlugin
|
4
|
+
|
5
|
+
@@version_major = 0
|
6
|
+
@@version_minor = 0
|
7
|
+
@@version_revision = 1
|
8
|
+
|
4
9
|
def info
|
5
|
-
{ :uid => "62e3583abfc24f209916c4ff97661fa0", :name => "Rake", :version =>
|
10
|
+
{ :uid => "62e3583abfc24f209916c4ff97661fa0", :name => "Rake", :version => get_version }
|
6
11
|
end
|
7
12
|
|
8
13
|
def run(message)
|
data/lib/plugins/redis.rb
CHANGED
@@ -3,23 +3,27 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
class Redis < QuartzPlugin
|
5
5
|
|
6
|
+
@@version_major = 0
|
7
|
+
@@version_minor = 0
|
8
|
+
@@version_revision = 1
|
9
|
+
|
6
10
|
def info
|
7
|
-
{ :uid => "6342c1ef0d8bb2a47ab1362a6b02c058", :name => "Redis Backup", :version =>
|
11
|
+
{ :uid => "6342c1ef0d8bb2a47ab1362a6b02c058", :name => "Redis Backup", :version => get_version }
|
8
12
|
end
|
9
13
|
|
10
14
|
def run(message)
|
11
15
|
pl = payload(message)
|
12
16
|
|
13
17
|
@job_name = pl['job_name'].gsub(/[^\w\s_-]+/, '').gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2').gsub(/\s/, '_')
|
14
|
-
@redisdump_utility = pl['
|
15
|
-
@name = pl['
|
18
|
+
@redisdump_utility = pl['redis_client'] || '/usr/bin/redis-cli'
|
19
|
+
@name = pl['db_name'] || 'dump'
|
16
20
|
@password = pl['password']
|
17
21
|
@socket = pl['socket']
|
18
22
|
@host = pl['host'] || '127.0.0.1'
|
19
23
|
@port = pl['port'] || 6379
|
20
|
-
@additional_options = pl['
|
21
|
-
@path = pl['
|
22
|
-
@dump_path = pl['
|
24
|
+
@additional_options = pl['additional_options'] || []
|
25
|
+
@path = pl['db_path']
|
26
|
+
@dump_path = pl['backup_folder']
|
23
27
|
|
24
28
|
@name = 'dump' if @name.empty?
|
25
29
|
@host = '127.0.0.1' if @host.empty?
|
data/lib/plugins/rotater.rb
CHANGED
@@ -3,17 +3,21 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
class Rotater < QuartzPlugin
|
5
5
|
|
6
|
+
@@version_major = 0
|
7
|
+
@@version_minor = 0
|
8
|
+
@@version_revision = 1
|
9
|
+
|
6
10
|
def info
|
7
|
-
{ :uid => "02f7d8237bcc438e8f0659babfef2911", :name => "File Rotater", :version =>
|
11
|
+
{ :uid => "02f7d8237bcc438e8f0659babfef2911", :name => "File Rotater", :version => get_version }
|
8
12
|
end
|
9
13
|
|
10
14
|
def run(message)
|
11
15
|
pl = payload(message)
|
12
16
|
|
13
|
-
source_pattern = pl['
|
17
|
+
source_pattern = pl['source_pattern']
|
14
18
|
dest_folder = pl['location']
|
15
19
|
keep = pl['keep'].nil? ? 5 : pl['keep'].to_i
|
16
|
-
post_rotate = pl['
|
20
|
+
post_rotate = pl['post_rotate']
|
17
21
|
|
18
22
|
archive = File.join(dest_folder, '/archive')
|
19
23
|
|
data/lib/plugins/s3backup.rb
CHANGED
@@ -4,8 +4,12 @@ require 'fog'
|
|
4
4
|
|
5
5
|
class S3backup < QuartzPlugin
|
6
6
|
|
7
|
+
@@version_major = 0
|
8
|
+
@@version_minor = 0
|
9
|
+
@@version_revision = 1
|
10
|
+
|
7
11
|
def info
|
8
|
-
{ :uid => "d3533989f9d542f393566511e8eb2090", :name => "S3 Backup", :version =>
|
12
|
+
{ :uid => "d3533989f9d542f393566511e8eb2090", :name => "S3 Backup", :version => get_version }
|
9
13
|
end
|
10
14
|
|
11
15
|
def run(message)
|
@@ -13,12 +17,12 @@ class S3backup < QuartzPlugin
|
|
13
17
|
|
14
18
|
@log.debug "Pruned payload #{pl}"
|
15
19
|
|
16
|
-
@access_key_id = pl['
|
17
|
-
@secret_access_key = pl['
|
20
|
+
@access_key_id = pl['access_key']
|
21
|
+
@secret_access_key = pl['secret_key']
|
18
22
|
@bucket = pl['bucket']
|
19
|
-
@remote_path = pl['
|
23
|
+
@remote_path = pl['remote_path']
|
20
24
|
@region = pl['region']
|
21
|
-
@local_pattern = pl['
|
25
|
+
@local_pattern = pl['local_pattern']
|
22
26
|
@keep = pl['keep'].empty? ? 0 : pl['keep'].to_i
|
23
27
|
|
24
28
|
@testing = pl['testing']
|
@@ -52,20 +56,25 @@ class S3backup < QuartzPlugin
|
|
52
56
|
|
53
57
|
count = 0
|
54
58
|
# get local files
|
59
|
+
directory = connection.directories.get(@bucket)
|
60
|
+
all_rotated = directory.files.reject { |m| File.dirname(m.key) != @remote_path }
|
61
|
+
|
55
62
|
Dir.glob(@local_pattern).each do |f|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
base_file = File.basename(f)
|
64
|
+
remote_files = all_rotated.map {|m| File.basename(m.key)}
|
65
|
+
unless remote_files.include? base_file
|
66
|
+
remote_file = File.join(@remote_path, base_file)
|
67
|
+
next if File.directory?(f)
|
68
|
+
@log.debug "Copying #{f} to #{remote_file}"
|
69
|
+
count += 1
|
70
|
+
File.open(f, 'r') do |file|
|
71
|
+
connection.put_object(@bucket, File.join(remote_path, base_file), file)
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
65
76
|
return run_result(true, "Files copied to S3 bucket successfully with no rotation") if @keep == 0
|
66
77
|
|
67
|
-
directory = connection.directories.get(@bucket)
|
68
|
-
all_rotated = directory.files.reject { |m| File.dirname(m.key) != @remote_path }
|
69
78
|
@log.debug "Found #{all_rotated.count} in the remote bucket"
|
70
79
|
if all_rotated.count > @keep
|
71
80
|
remove_count = all_rotated.count - @keep
|
data/lib/plugins/shell.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
2
2
|
|
3
3
|
class Shell < QuartzPlugin
|
4
|
+
|
5
|
+
@@version_major = 0
|
6
|
+
@@version_minor = 0
|
7
|
+
@@version_revision = 1
|
8
|
+
|
4
9
|
def info
|
5
|
-
{ :uid => "20e07c656e2f477d969e9561e13229fb", :name => "Shell", :version =>
|
10
|
+
{ :uid => "20e07c656e2f477d969e9561e13229fb", :name => "Shell", :version => get_version }
|
6
11
|
end
|
7
12
|
|
8
13
|
def run(message)
|
9
14
|
@log.debug "Running with #{message}"
|
10
15
|
payload = payload(message)
|
11
16
|
command = payload['command']
|
12
|
-
|
13
|
-
@log.info "Shell command '#{command}' with '#{params}'"
|
17
|
+
@log.info "Shell command '#{command}"
|
14
18
|
|
15
19
|
begin
|
16
|
-
result = run_shell("#{command}
|
20
|
+
result = run_shell("#{command}")
|
17
21
|
run_result(result[:ok], result[:message])
|
18
22
|
rescue => ex
|
19
23
|
run_result(false, "Failed to run shell command due to #{ex}")
|
data/lib/plugins/tester.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
2
2
|
|
3
3
|
class Tester < QuartzPlugin
|
4
|
+
|
5
|
+
@@version_major = 1
|
6
|
+
@@version_minor = 0
|
7
|
+
@@version_revision = 0
|
8
|
+
|
4
9
|
def info
|
5
|
-
{ :uid => "c0bb6ed7950b489f9abba8071ff0e0ab", :name => "Tester", :version =>
|
10
|
+
{ :uid => "c0bb6ed7950b489f9abba8071ff0e0ab", :name => "Tester", :version => get_version }
|
6
11
|
end
|
7
12
|
|
8
13
|
def run(message)
|
data/lib/plugins/webget.rb
CHANGED
@@ -2,8 +2,13 @@ require File.join(File.dirname(__FILE__), 'quartz_plugin')
|
|
2
2
|
require 'httparty'
|
3
3
|
|
4
4
|
class Webget < QuartzPlugin
|
5
|
+
|
6
|
+
@@version_major = 0
|
7
|
+
@@version_minor = 0
|
8
|
+
@@version_revision = 1
|
9
|
+
|
5
10
|
def info
|
6
|
-
{ :uid => "6b5f722d214f4d71a5be237d44094721", :name => "WebGet", :version =>
|
11
|
+
{ :uid => "6b5f722d214f4d71a5be237d44094721", :name => "WebGet", :version => get_version }
|
7
12
|
end
|
8
13
|
|
9
14
|
def run(message)
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudblocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.12a
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- CloudBlocks
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.8.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.1
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: json
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 1.6.3
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.3
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: eventmachine
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 0.12.10
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.12.10
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: eventmachine
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 1.0.0.beta.4
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0.beta.4
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: faye
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: 0.8.0
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.8.0
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: open4
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: 1.3.0
|
77
102
|
type: :runtime
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.3.0
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: fog
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: 1.1.2
|
88
118
|
type: :runtime
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.1.2
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: highline
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ~>
|
@@ -98,9 +133,14 @@ dependencies:
|
|
98
133
|
version: 1.6.11
|
99
134
|
type: :runtime
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
102
|
-
|
103
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 1.6.11
|
142
|
+
description: See http://cloudblocks.co for more info
|
143
|
+
email: hello@cloudblocks.co
|
104
144
|
executables:
|
105
145
|
- chief
|
106
146
|
- quartz
|
@@ -122,7 +162,7 @@ files:
|
|
122
162
|
- lib/plugins/webget.rb
|
123
163
|
- bin/chief
|
124
164
|
- bin/quartz
|
125
|
-
homepage: http://
|
165
|
+
homepage: http://cloudblocks.co
|
126
166
|
licenses: []
|
127
167
|
post_install_message:
|
128
168
|
rdoc_options: []
|
@@ -137,12 +177,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
178
|
none: false
|
139
179
|
requirements:
|
140
|
-
- - ! '
|
180
|
+
- - ! '>'
|
141
181
|
- !ruby/object:Gem::Version
|
142
|
-
version:
|
182
|
+
version: 1.3.1
|
143
183
|
requirements: []
|
144
184
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
185
|
+
rubygems_version: 1.8.24
|
146
186
|
signing_key:
|
147
187
|
specification_version: 3
|
148
188
|
summary: CloudBlocks Gem and Agent
|