immortalize 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/immortalize +39 -13
- data/immortalize.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/bin/immortalize
CHANGED
@@ -25,8 +25,10 @@ optparse = OptionParser.new do |opts|
|
|
25
25
|
Usage: #{$0} [run|remove|inspect] [options]
|
26
26
|
|
27
27
|
To add (and start) a command:
|
28
|
-
#{$0} run "command" --
|
28
|
+
#{$0} run "command" --notify admin@email.com --max_failures 5
|
29
29
|
To change a command's options, just re-add it.
|
30
|
+
You can group commands by adding a --group option, which allows
|
31
|
+
you to perform future actions on all commands in the group.
|
30
32
|
|
31
33
|
To stop a daemon:
|
32
34
|
#{$0} stop "command"
|
@@ -50,9 +52,9 @@ Run this command with no arguments as a cron job, to run every minute:
|
|
50
52
|
Options:
|
51
53
|
ENDBANNER
|
52
54
|
|
53
|
-
$options[:
|
55
|
+
$options[:notify] = nil
|
54
56
|
opts.on( '--notify EMAIL', "The email address to which failure notifications should be sent." ) do |email|
|
55
|
-
$options[:
|
57
|
+
$options[:notify] = email
|
56
58
|
end
|
57
59
|
|
58
60
|
$options[:max_failures] = 5
|
@@ -60,6 +62,11 @@ ENDBANNER
|
|
60
62
|
$options[:max_failures] = num.to_i
|
61
63
|
end
|
62
64
|
|
65
|
+
$options[:group] = nil
|
66
|
+
opts.on('--group GROUP', "Set the group of immortal commands that this command belongs to.") do |group|
|
67
|
+
$options[:group] = group
|
68
|
+
end
|
69
|
+
|
63
70
|
$log_location = "#{ENV['HOME']}/.immortalize"
|
64
71
|
opts.on('--log-location PATH', "Manually set the location for immortalize to keep its registry and cron.log (default #{$log_location})") do |path|
|
65
72
|
if !File.directory?(path)
|
@@ -86,7 +93,7 @@ $action = ARGV[0]
|
|
86
93
|
|
87
94
|
def notify(immortal, message)
|
88
95
|
m = Merb::Mailer.new(
|
89
|
-
:to => immortal[:
|
96
|
+
:to => immortal[:notify],
|
90
97
|
:from => "immortalize@video.iremix.org",
|
91
98
|
:subject => "ImmortalCommand `#{immortal[:command]}' keeps dying!",
|
92
99
|
:text => message
|
@@ -111,6 +118,10 @@ class Immortal
|
|
111
118
|
end
|
112
119
|
end
|
113
120
|
|
121
|
+
def self.in_group(group)
|
122
|
+
$registry.select {|k,i| i[:group] == group}.collect { |k,i| new(k) }
|
123
|
+
end
|
124
|
+
|
114
125
|
attr_reader :identifier
|
115
126
|
def initialize(identifier)
|
116
127
|
@identifier = identifier
|
@@ -169,7 +180,7 @@ class Immortal
|
|
169
180
|
end
|
170
181
|
|
171
182
|
def inspect
|
172
|
-
self[:command] + (failures.length >= self[:max_failures].to_i ? "\n\tLast #{self[:max_failures]} failures: #{failures[-5..1].join(", ")}" : '')
|
183
|
+
self[:command] + (" (group=#{self[:group]})" if self[:group]).to_s + (failures.length >= self[:max_failures].to_i ? "\n\tLast #{self[:max_failures]} failures: #{failures[-5..1].join(", ")}" : '')
|
173
184
|
end
|
174
185
|
|
175
186
|
private
|
@@ -179,6 +190,7 @@ class Immortal
|
|
179
190
|
end
|
180
191
|
|
181
192
|
# Curate the command string
|
193
|
+
$command_string = nil
|
182
194
|
if ARGV[1].to_s.length > 1 && ARGV[1] !~ /^\d+$/ && ARGV[1] != 'all'
|
183
195
|
$command_string = ARGV[1]
|
184
196
|
# Complain about the string if it does not have proper output redirections
|
@@ -234,13 +246,19 @@ unless ::Object.const_defined?(:IRB)
|
|
234
246
|
immortal.stop!
|
235
247
|
end
|
236
248
|
else
|
237
|
-
|
238
|
-
|
239
|
-
|
249
|
+
if $command_string
|
250
|
+
identifier = SHA1.hexdigest($command_string)
|
251
|
+
immortal = Immortal.new(identifier)
|
252
|
+
immortal.stop!
|
253
|
+
elsif $options[:group]
|
254
|
+
Immortal.in_group($options[:group]).each do |immortal|
|
255
|
+
immortal.stop!
|
256
|
+
end
|
257
|
+
end
|
240
258
|
end
|
241
259
|
|
242
260
|
when 'run'
|
243
|
-
if $options[:
|
261
|
+
if $options[:notify].nil?
|
244
262
|
warn "Must include --notify EMAIL_ADDRESS when adding a command!"
|
245
263
|
exit
|
246
264
|
end
|
@@ -250,7 +268,8 @@ unless ::Object.const_defined?(:IRB)
|
|
250
268
|
|
251
269
|
# Create the command
|
252
270
|
$registry[identifier] ||= {
|
253
|
-
:command => $command_string
|
271
|
+
:command => $command_string,
|
272
|
+
:group => $options[:group]
|
254
273
|
}
|
255
274
|
$registry[identifier].merge!($options)
|
256
275
|
|
@@ -274,9 +293,16 @@ unless ::Object.const_defined?(:IRB)
|
|
274
293
|
puts "Deleted #{identifier}: \"#{reg[:command]}\""
|
275
294
|
end
|
276
295
|
else
|
277
|
-
|
278
|
-
|
279
|
-
|
296
|
+
if $command_string
|
297
|
+
identifier = SHA1.hexdigest($command_string)
|
298
|
+
reg = $registry.delete(identifier)
|
299
|
+
puts "Deleted #{identifier}: \"#{reg[:command]}\""
|
300
|
+
elsif $options[:group]
|
301
|
+
Immortal.in_group($options[:group]).each do |immortal|
|
302
|
+
reg = $registry.delete(immortal.identifier)
|
303
|
+
puts "Deleted #{immortal.identifier}: \"#{reg[:command]}\""
|
304
|
+
end
|
305
|
+
end
|
280
306
|
end
|
281
307
|
|
282
308
|
when nil
|
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.
|
8
|
+
s.version = "0.2.2"
|
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-04-
|
12
|
+
s.date = %q{2010-04-27}
|
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
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
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-04-
|
17
|
+
date: 2010-04-27 00:00:00 -04:00
|
18
18
|
default_executable: immortalize
|
19
19
|
dependencies: []
|
20
20
|
|