immortalize 0.1.4 → 0.2.0

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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/immortalize +20 -11
  3. data/immortalize.gemspec +1 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
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("|echo \"#{@reg[:command]}\" 1>/dev/null 2>&1 & echo $!") do |f|
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 >> #{$log_location}\/cron.log/}
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{immortalize}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["BehindLogic"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 4
9
- version: 0.1.4
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - BehindLogic