immortalize 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/immortalize +32 -16
  3. data/immortalize.gemspec +2 -2
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/bin/immortalize CHANGED
@@ -28,8 +28,15 @@ To add (and start) a command:
28
28
  #{$0} run "command" --notification_recipient admin@email.com --max_failures 5
29
29
  To change a command's options, just re-add it.
30
30
 
31
+ To stop a daemon:
32
+ #{$0} stop "command"
33
+ #{$0} stop 1 # <- 1 is an index as in 'immortalize list' below
34
+ #{$0} stop all
35
+
31
36
  To remove a command:
32
37
  #{$0} remove "command"
38
+ #{$0} remove 1 # <- 1 is an index as in 'immortalize list' below
39
+ #{$0} remove all
33
40
 
34
41
  To inspect the current list of immortal commands:
35
42
  #{$0} list
@@ -44,17 +51,17 @@ Options:
44
51
  ENDBANNER
45
52
 
46
53
  $options[:notification_recipient] = nil
47
- opts.on( '--notify=EMAIL', "The email address to which failure notifications should be sent." ) do |email|
54
+ opts.on( '--notify EMAIL', "The email address to which failure notifications should be sent." ) do |email|
48
55
  $options[:notification_recipient] = email
49
56
  end
50
57
 
51
58
  $options[:max_failures] = 5
52
- opts.on('--max_failures=NUM', "Notify on NUM or more failures within an hour (default 5)") do |num|
59
+ opts.on('--max_failures NUM', "Notify on NUM or more failures within an hour (default 5)") do |num|
53
60
  $options[:max_failures] = num.to_i
54
61
  end
55
62
 
56
63
  $log_location = "#{ENV['HOME']}/.immortalize"
57
- opts.on('--log-location=PATH', "Manually set the location for immortalize to keep its registry and cron.log (default #{$log_location})") do |path|
64
+ opts.on('--log-location PATH', "Manually set the location for immortalize to keep its registry and cron.log (default #{$log_location})") do |path|
58
65
  if !File.directory?(path)
59
66
  warn "`#{path}' is not a valid path."
60
67
  exit 1
@@ -172,7 +179,7 @@ class Immortal
172
179
  end
173
180
 
174
181
  # Curate the command string
175
- if ARGV[1].to_s.length > 1 && ARGV[1] !~ /^\d+$/
182
+ if ARGV[1].to_s.length > 1 && ARGV[1] !~ /^\d+$/ && ARGV[1] != 'all'
176
183
  $command_string = ARGV[1]
177
184
  # Complain about the string if it does not have proper output redirections
178
185
  cmds = $command_string.split(/; ?/)
@@ -198,13 +205,8 @@ unless ::Object.const_defined?(:IRB)
198
205
  case $action
199
206
  when 'setup'
200
207
  crons = `crontab -l 2>/dev/null`.split(/\n/)
201
- immortalize_cmd = `which immortalize`.chomp
202
- if immortalize_cmd.empty?
203
- warn "Couldn't find installed version of the 'immortalize' command! (Try `which immortalize`)"
204
- exit
205
- end
206
- crons.reject! {|c| c =~ /immortalize.*>> #{$log_location}\/cron.log/}
207
- crons << "* * * * * #{immortalize_cmd} --log-location=\"#{$log_location}\" >> #{$log_location}/cron.log 2>&1\n"
208
+ crons.reject! {|c| c =~ /immortalize.*>?> #{$log_location}\/cron.log/}
209
+ crons << "* * * * * #{$0} --log-location=\"#{$log_location}\" >> #{$log_location}/cron.log 2>&1\n"
208
210
  puts "Installing crons:\n\t#{crons.join("\n\t")}"
209
211
  f = IO.popen("crontab -", 'w')
210
212
  f << crons.join("\n")
@@ -224,11 +226,18 @@ unless ::Object.const_defined?(:IRB)
224
226
  when 'stop'
225
227
  if ARGV[1] =~ /^\d+$/
226
228
  identifier = $registry.keys.sort[ARGV[1].to_i-1]
229
+ immortal = Immortal.new(identifier)
230
+ immortal.stop!
231
+ elsif ARGV[1] == 'all'
232
+ $registry.keys.each do |identifier|
233
+ immortal = Immortal.new(identifier)
234
+ immortal.stop!
235
+ end
227
236
  else
228
237
  identifier = SHA1.hexdigest($command_string)
238
+ immortal = Immortal.new(identifier)
239
+ immortal.stop!
229
240
  end
230
- immortal = Immortal.new(identifier)
231
- immortal.stop!
232
241
 
233
242
  when 'run'
234
243
  if $options[:notification_recipient].nil?
@@ -257,11 +266,18 @@ unless ::Object.const_defined?(:IRB)
257
266
  when 'remove'
258
267
  if ARGV[1] =~ /^\d+$/
259
268
  identifier = $registry.keys.sort[ARGV[1].to_i-1]
269
+ reg = $registry.delete(identifier)
270
+ puts "Deleted #{identifier}: \"#{reg[:command]}\""
271
+ elsif ARGV[1] == 'all'
272
+ $registry.keys.each do |identifier|
273
+ reg = $registry.delete(identifier)
274
+ puts "Deleted #{identifier}: \"#{reg[:command]}\""
275
+ end
260
276
  else
261
277
  identifier = SHA1.hexdigest($command_string)
278
+ reg = $registry.delete(identifier)
279
+ puts "Deleted #{identifier}: \"#{reg[:command]}\""
262
280
  end
263
- reg = $registry.delete(identifier)
264
- puts "Deleted #{identifier}: \"#{reg[:command]}\""
265
281
 
266
282
  when nil
267
283
  # Running bare from cron.
@@ -280,7 +296,7 @@ unless ::Object.const_defined?(:IRB)
280
296
  # Notify if failures have been frequent
281
297
  if immortal.frequent_failures?
282
298
  puts " #{i+1}) FREQUENT FAILURE ON #{identifier} (`#{immortal[:command]}')"
283
- notify(immortal, "ImmortalCommand failure!\n\nCommand `#{immortal[:command]}' failed, threshold is #{immortal[:max_failures]} / hour.\n\n#{immortal.failures_today.size} failures so far today, #{immortal.failures_this_hour.size} in the past hour.")
299
+ notify(immortal, "ImmortalCommand failure!\n\nCommand `#{immortal[:command]}' failed at #{Time.now}, threshold is #{immortal[:max_failures]} / hour.\n\n#{immortal.failures_today.size} failures so far today, #{immortal.failures_this_hour.size} in the past hour.")
284
300
  end
285
301
  # Start it
286
302
  immortal.start!
data/immortalize.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{immortalize}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["BehindLogic"]
12
- s.date = %q{2010-03-17}
12
+ s.date = %q{2010-04-06}
13
13
  s.default_executable = %q{immortalize}
14
14
  s.description = %q{Watch a specific process, restart it if it dies.}
15
15
  s.email = %q{gems@behindlogic.com}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - BehindLogic
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 -04:00
17
+ date: 2010-04-06 00:00:00 -04:00
18
18
  default_executable: immortalize
19
19
  dependencies: []
20
20