cloudblocks 0.0.12c → 0.0.12d
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/{quartz → cb-agent} +52 -28
- metadata +4 -4
data/bin/{quartz → cb-agent}
RENAMED
@@ -34,13 +34,18 @@ public
|
|
34
34
|
|
35
35
|
def start
|
36
36
|
begin
|
37
|
-
@log.info "Starting
|
38
|
-
puts "Starting
|
37
|
+
@log.info "Starting the CloudBlocks Agent"
|
38
|
+
puts "Starting the CloudBlocks Agent"
|
39
39
|
|
40
40
|
pid = get_pid
|
41
41
|
if pid != 0
|
42
|
-
|
43
|
-
|
42
|
+
#check if the process is actually running
|
43
|
+
if pid_process_running?(pid)
|
44
|
+
warn "The CloudBlocks Agent is already running. Use stop command to stop it or --help for more info"
|
45
|
+
exit -1
|
46
|
+
else
|
47
|
+
File.delete(@pid_full)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
|
46
51
|
check_version
|
@@ -64,7 +69,7 @@ def start
|
|
64
69
|
Process.detach(pid)
|
65
70
|
rescue => exc
|
66
71
|
Process.kill('TERM', pid)
|
67
|
-
warn "Cannot start
|
72
|
+
warn "Cannot start the CloudBlocks Agent: #{exc.message}"
|
68
73
|
end
|
69
74
|
else
|
70
75
|
run
|
@@ -75,7 +80,7 @@ end
|
|
75
80
|
|
76
81
|
def stop
|
77
82
|
pid = get_pid
|
78
|
-
@log.info "Stopping
|
83
|
+
@log.info "Stopping the CloudBlocks Agent"
|
79
84
|
begin
|
80
85
|
@quartz.status(2, @version, plugin_meta_data)
|
81
86
|
EM.stop
|
@@ -88,15 +93,15 @@ def stop
|
|
88
93
|
rescue
|
89
94
|
end
|
90
95
|
File.delete(@pid_full)
|
91
|
-
puts "
|
96
|
+
puts "The CloudBlocks Agent was stopped"
|
92
97
|
else
|
93
|
-
warn "
|
98
|
+
warn "Did nothing - The CloudBlocks Agent was not running"
|
94
99
|
exit -1
|
95
100
|
end
|
96
101
|
end
|
97
102
|
|
98
103
|
def register
|
99
|
-
puts "Registering
|
104
|
+
puts "Registering the CloudBlocks Agent with #{@url} and API Key #{@api_key}"
|
100
105
|
os_name = RUBY_PLATFORM
|
101
106
|
os_id = os_name.include?('darwin') ? 5 : 1
|
102
107
|
agent = { :agent_type_id => os_id, :agent_name => Socket.gethostname, :agent_timezone => Time.new.zone, :extra => os_name}
|
@@ -113,7 +118,7 @@ def register
|
|
113
118
|
end
|
114
119
|
|
115
120
|
def unregister
|
116
|
-
puts "Unregister
|
121
|
+
puts "Unregister the CloudBlocks Agent #{@agent_id} with #{@url}"
|
117
122
|
@agent_id = ""
|
118
123
|
@quartz.unregister(@agent_id)
|
119
124
|
save_config
|
@@ -226,10 +231,10 @@ def check_version
|
|
226
231
|
result = @quartz.check_version
|
227
232
|
if result['ok']
|
228
233
|
latest = result['latest']
|
229
|
-
@log.warn 'A newer version of
|
234
|
+
@log.warn 'A newer version of the CloudBlocks Agent is available. Please update the cloudblocks gem. See http://help.cloudblocks.co for more info' if latest > @version
|
230
235
|
end
|
231
236
|
rescue => exc
|
232
|
-
warn "Cannot connect to the server"
|
237
|
+
warn "Cannot connect to the CloudBlocks server"
|
233
238
|
exit -1
|
234
239
|
end
|
235
240
|
end
|
@@ -270,25 +275,38 @@ def get_pid
|
|
270
275
|
file = File.new(@pid_full, "r")
|
271
276
|
pid = file.read
|
272
277
|
file.close
|
273
|
-
|
274
278
|
pid
|
275
279
|
else
|
276
280
|
0
|
277
281
|
end
|
278
282
|
end
|
279
283
|
|
284
|
+
def pid_process_running?(pid)
|
285
|
+
begin
|
286
|
+
pid_number = pid.to_i
|
287
|
+
Process.getpgid(pid_number)
|
288
|
+
true
|
289
|
+
rescue Errno::ESRCH
|
290
|
+
false
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
280
294
|
public
|
281
295
|
|
282
296
|
@version = 1
|
283
297
|
str_version = "0.0.#{@version}"
|
284
298
|
|
285
299
|
config_file = 'cloudblocks.yaml'
|
286
|
-
@pid_file = '
|
287
|
-
@log_file = '
|
300
|
+
@pid_file = 'cb-agent.pid'
|
301
|
+
@log_file = 'cb-agent.log'
|
288
302
|
@config_dir = File.join(File.expand_path('~'), '.cloudblocks')
|
289
303
|
@config_full = File.join(@config_dir, config_file)
|
290
|
-
|
291
|
-
@
|
304
|
+
|
305
|
+
@cb_tmp_dir = '/tmp/cloudblocks'
|
306
|
+
Dir.mkdir(@cb_tmp_dir) if !File.exists?(@cb_tmp_dir)
|
307
|
+
|
308
|
+
@pid_full = File.join(@cb_tmp_dir, @pid_file)
|
309
|
+
@log_full = File.join(@cb_tmp_dir, @log_file)
|
292
310
|
|
293
311
|
@api_key = ''
|
294
312
|
@faye_url = 'https://sockets.cloudblocks.co/push/'
|
@@ -303,10 +321,10 @@ command = nil
|
|
303
321
|
@realtime = true
|
304
322
|
OptionParser.new do |opts|
|
305
323
|
opts.banner = <<-EOF
|
306
|
-
|
324
|
+
CloudBlocks Agent. v#{str_version} (c) 2012 CloudBlocks
|
307
325
|
For more information please visit http://cloudblocks.co
|
308
326
|
|
309
|
-
Usage:
|
327
|
+
Usage: cb-agent [register|unregister|start|stop] [options]
|
310
328
|
|
311
329
|
Options:
|
312
330
|
EOF
|
@@ -328,7 +346,7 @@ EOF
|
|
328
346
|
@pid_full = v
|
329
347
|
end
|
330
348
|
|
331
|
-
opts.on('-l', '--log LOG', '
|
349
|
+
opts.on('-l', '--log LOG', 'Full log file path') do |v|
|
332
350
|
@log_full = v
|
333
351
|
end
|
334
352
|
|
@@ -362,10 +380,10 @@ EOF
|
|
362
380
|
puts <<-EOF
|
363
381
|
|
364
382
|
Commands:
|
365
|
-
register Register the
|
366
|
-
start Starts
|
367
|
-
stop Stops
|
368
|
-
unregister
|
383
|
+
register Register the CloudBlocks Agent
|
384
|
+
start Starts the CloudBlocks Agent as a deamon
|
385
|
+
stop Stops the CloudBlocks Agent daemon
|
386
|
+
unregister Unregisters the CloudBlocks Agent
|
369
387
|
|
370
388
|
EOF
|
371
389
|
exit 0
|
@@ -392,7 +410,7 @@ end
|
|
392
410
|
|
393
411
|
# still no api key, we need to get it
|
394
412
|
if @api_key.empty?
|
395
|
-
puts 'CloudBlocks
|
413
|
+
puts 'CloudBlocks Agent'
|
396
414
|
@api_key = ask('Please enter your API key. (you can find it at https://cloudblocks.co/me): ')
|
397
415
|
if @api_key.length != 32
|
398
416
|
puts 'Invalid API key'
|
@@ -416,7 +434,7 @@ if @agent_id.empty?
|
|
416
434
|
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :secret_key => @secret_key)
|
417
435
|
register
|
418
436
|
|
419
|
-
q = ask("Start the agent as daemon? ") { |q| q.default = "Y" }
|
437
|
+
q = ask("Start the agent as a daemon? ") { |q| q.default = "Y" }
|
420
438
|
if q.chomp.downcase != 'n'
|
421
439
|
@quartz = CloudQuartz.new(:api_key => @api_key, :url => @url, :agent_id => @agent_id, :secret_key => @secret_key)
|
422
440
|
start
|
@@ -429,7 +447,13 @@ if @agent_id.empty?
|
|
429
447
|
end
|
430
448
|
|
431
449
|
if command.nil? || command.empty?
|
432
|
-
|
450
|
+
pid = get_pid
|
451
|
+
#check if the process is actually running
|
452
|
+
if pid != 0 && pid_process_running?(pid)
|
453
|
+
puts "The CloudBlocks Agent is currently running. Use the stop command to stop it or --help for more info"
|
454
|
+
exit -1
|
455
|
+
end
|
456
|
+
puts 'The CloudBlocks Agent is currently not running. Use the start command to start it or --help for more information'
|
433
457
|
exit -1
|
434
458
|
end
|
435
459
|
|
@@ -439,7 +463,7 @@ unless commands.include?(command)
|
|
439
463
|
end
|
440
464
|
|
441
465
|
if (@agent_id.nil? || @agent_id.empty? || @agent_id.empty? || @secret_key.empty?) && command != 'register'
|
442
|
-
puts 'No Agent id found. Have you registered it yet? Use --help for more information'
|
466
|
+
puts 'No CloudBlocks Agent id found. Have you registered it yet? Use --help for more information'
|
443
467
|
exit -1
|
444
468
|
end
|
445
469
|
|
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.12d
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -140,10 +140,10 @@ dependencies:
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: 1.6.11
|
142
142
|
description: See http://cloudblocks.co for more info
|
143
|
-
email: hello@
|
143
|
+
email: hello@thecloudblocks.com
|
144
144
|
executables:
|
145
145
|
- chief
|
146
|
-
-
|
146
|
+
- cb-agent
|
147
147
|
extensions: []
|
148
148
|
extra_rdoc_files: []
|
149
149
|
files:
|
@@ -161,7 +161,7 @@ files:
|
|
161
161
|
- lib/plugins/tester.rb
|
162
162
|
- lib/plugins/webget.rb
|
163
163
|
- bin/chief
|
164
|
-
- bin/
|
164
|
+
- bin/cb-agent
|
165
165
|
homepage: http://cloudblocks.co
|
166
166
|
licenses: []
|
167
167
|
post_install_message:
|