immortalize 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/immortalize +20 -11
- data/immortalize.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/immortalize
CHANGED
@@ -20,12 +20,6 @@ require 'merb-core'
|
|
20
20
|
require 'merb-mailer'
|
21
21
|
Merb::Mailer.delivery_method = :sendmail
|
22
22
|
|
23
|
-
$log_location = "#{ENV['HOME']}/.immortalize"
|
24
|
-
`mkdir -p "#{$log_location}"` unless File.directory?($log_location)
|
25
|
-
$registry_filename = "#{$log_location}/registry.yaml"
|
26
|
-
File.open($registry_filename, 'w'){|f| f << {}.to_yaml} unless File.exists?($registry_filename)
|
27
|
-
$registry = YAML.load_file($registry_filename)
|
28
|
-
|
29
23
|
optparse = OptionParser.new do |opts|
|
30
24
|
opts.banner = <<-ENDBANNER
|
31
25
|
Usage: #{$0} [run|remove|inspect] [options]
|
@@ -59,13 +53,28 @@ ENDBANNER
|
|
59
53
|
$options[:max_failures] = num.to_i
|
60
54
|
end
|
61
55
|
|
56
|
+
$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|
|
58
|
+
if !File.directory?(path)
|
59
|
+
warn "`#{path}' is not a valid path."
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
$log_location = path
|
63
|
+
end
|
64
|
+
|
62
65
|
opts.on( '-h', '--help', 'Display this screen' ) do
|
63
66
|
puts opts
|
64
67
|
exit
|
65
68
|
end
|
66
69
|
end
|
67
|
-
|
68
70
|
optparse.parse!
|
71
|
+
|
72
|
+
|
73
|
+
`mkdir -p "#{$log_location}"` unless File.directory?($log_location)
|
74
|
+
$registry_filename = "#{$log_location}/registry.yaml"
|
75
|
+
File.open($registry_filename, 'w'){|f| f << {}.to_yaml} unless File.exists?($registry_filename)
|
76
|
+
$registry = YAML.load_file($registry_filename)
|
77
|
+
|
69
78
|
$action = ARGV[0]
|
70
79
|
|
71
80
|
def notify(immortal, message)
|
@@ -116,7 +125,7 @@ class Immortal
|
|
116
125
|
def start!
|
117
126
|
# Run the command and gather the pid
|
118
127
|
pid = nil
|
119
|
-
open("
|
128
|
+
open("|#{@reg[:command]} 1>/dev/null & echo $!") do |f|
|
120
129
|
pid = f.sysread(5).chomp.to_i
|
121
130
|
end
|
122
131
|
# Log the pid
|
@@ -153,7 +162,7 @@ class Immortal
|
|
153
162
|
end
|
154
163
|
|
155
164
|
def inspect
|
156
|
-
self[:command] + (failures.length >= self[:max_failures].to_i ? "\n\tLast #{self[:max_failures]} failures: #{failures[-5..1]}" : '')
|
165
|
+
self[:command] + (failures.length >= self[:max_failures].to_i ? "\n\tLast #{self[:max_failures]} failures: #{failures[-5..1].join(", ")}" : '')
|
157
166
|
end
|
158
167
|
|
159
168
|
private
|
@@ -194,8 +203,8 @@ unless ::Object.const_defined?(:IRB)
|
|
194
203
|
warn "Couldn't find installed version of the 'immortalize' command! (Try `which immortalize`)"
|
195
204
|
exit
|
196
205
|
end
|
197
|
-
crons.reject! {|c| c =~ /immortalize
|
198
|
-
crons << "* * * * * #{immortalize_cmd} >> #{$log_location}/cron.log 2>&1\n"
|
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"
|
199
208
|
puts "Installing crons:\n\t#{crons.join("\n\t")}"
|
200
209
|
f = IO.popen("crontab -", 'w')
|
201
210
|
f << crons.join("\n")
|
data/immortalize.gemspec
CHANGED