wonko9-i_can_daemonize 0.0.0 → 0.3.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.
data/Rakefile CHANGED
@@ -1,37 +1,8 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rcov/rcovtask'
1
+ # -*- ruby -*-
5
2
 
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |s|
9
- s.name = "i_can_daemonize"
10
- s.summary = "ICanDaemonize makes it dead simple to create daemons of your own"
11
- s.email = "wonko9@gmail.com"
12
- s.homepage = "http://github.com/wonko9/i_can_daemonize"
13
- s.description = "ICanDaemonize makes it dead simple to create daemons of your own"
14
- s.authors = ["Adam Pisoni", "Amos Elliston"]
15
- s.files = FileList["[A-Z]*", "{lib,test}/**/*"]
16
- end
17
- rescue LoadError
18
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
- end
20
-
21
- Rake::TestTask.new
3
+ require 'rubygems'
4
+ require 'hoe'
22
5
 
23
- Rake::RDocTask.new do |rdoc|
24
- rdoc.rdoc_dir = 'rdoc'
25
- rdoc.title = 'test'
26
- rdoc.options << '--line-numbers' << '--inline-source'
27
- rdoc.rdoc_files.include('README*')
28
- rdoc.rdoc_files.include('lib/**/*.rb')
6
+ Hoe.new('ICanDaemonize', '0.6.0') do |p|
7
+ p.developer('Adam Pisoni', 'wonko9@gmail.com')
29
8
  end
30
-
31
- Rcov::RcovTask.new do |t|
32
- t.libs << 'test'
33
- t.test_files = FileList['test/**/*_test.rb']
34
- t.verbose = true
35
- end
36
-
37
- task :default => :test
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'i_can_daemonize'
3
+
4
+ class ICanDaemonize::FeatureDemo
5
+ include ICanDaemonize
6
+
7
+ def self.define_args(args)
8
+ # "See the OptionParser docs for more info on how to define your own args.\n http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html\n"
9
+ @options[:nobugs] = true
10
+ args.on("--scott-rocks=TRUE", "Thanks scott") do |t|
11
+ @options[:scott_rocks] = t
12
+ end
13
+ args.on("--nobugs=TRUE", "No bugs flag") do |t|
14
+ @options[:nobugs] = false if t == "1" or t.downcase == "false"
15
+ end
16
+ end
17
+
18
+ before do
19
+ puts "The before block is executed after daemonizing, but before looping over the daemonize block"
20
+ if @options[:nobugs]
21
+ puts "Running with no bugs. Pass nobugs=false to run with bugs."
22
+ else
23
+ puts "There mite be busg"
24
+ end
25
+ end
26
+
27
+ after do
28
+ puts "The after block is executed before the program exits gracefully, but is not run if the program dies."
29
+ end
30
+
31
+ die_if do
32
+ puts "The die_if block is executed after every loop and dies if true is returned."
33
+ false
34
+ end
35
+
36
+ exit_if do
37
+ puts "The exit_if block is executed after every loop and exits gracefully if true is returned."
38
+ false
39
+ end
40
+
41
+ daemonize(:loop_every => 3, :timeout=>2, :die_on_timeout => false) do
42
+ puts "The daemonize block is called in a loop."
43
+ end
44
+
45
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'i_can_daemonize'
3
+ begin
4
+ require File.dirname(__FILE__) + "/../config/environment"
5
+ rescue LoadError
6
+ puts "\n****** ERROR LOADING RAILS ******\n\trails_daemon.rb should be put in your RAILS_ROOT/script directory so it can find your environment.rb\n\tOr you can change the environment require on line 4.\n*********************************\n\n"
7
+ end
8
+
9
+ class ICanDaemonize::RailsDaemon
10
+ include ICanDaemonize
11
+
12
+ before do
13
+ puts "This daemon has access to your entire rails stack and will log to RAILS_ROOT/log"
14
+ end
15
+
16
+ daemonize(:loop_every => 3, :timeout=>2, :die_on_timeout => false) do
17
+ puts "The daemonize block is called in a loop."
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'i_can_daemonize'
3
+
4
+ class ICanDaemonize::FeatureDemo
5
+ include ICanDaemonize
6
+
7
+ daemonize(:loop_every => 3) do
8
+ puts "The daemonize block is called in a loop."
9
+ end
10
+
11
+ end
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'pp'
3
+ require 'i_can_daemonize'
4
+ begin
5
+ require 'starling'
6
+ rescue LoadError
7
+ puts "\n****** ERROR LOADING STARLING ******\n\tStarling is not installed. Please run 'sudo gem install starling' before running this script.\n*********************************\n\n"
8
+ end
9
+
10
+ class ICanDaemonize::StarlingDaemon
11
+ include ICanDaemonize
12
+
13
+ if ARGV.include?('start')
14
+ puts <<-DOC
15
+
16
+ This daemon will listen to a starling queue called '#{@queue_name}' and print out whatever is added
17
+ First tail this daemon's log in another window.
18
+ The log is @ #{log_file}
19
+ Run irb at the console and type
20
+ > require 'rubygems'
21
+ > require 'starling'
22
+ > starling = Starling.new('127.0.0.1:22122')
23
+ > starling.set('#{@queue_name}','Hi there!')
24
+ Now watch the log file.
25
+
26
+ DOC
27
+ end
28
+
29
+ before do
30
+ @queue_name = "starlingdeamon"
31
+ @starling = Starling.new("127.0.0.1:22122")
32
+ @fetch_count = 0
33
+ end
34
+
35
+ daemonize(:log_prefix => false) do
36
+ puts "Trying to fetch from the '#{@queue_name}' queue. Dequeued #{@fetch_count} so far"
37
+ pp "GOT: ", @starling.get(@queue_name)
38
+ @fetch_count += 1
39
+ end
40
+
41
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "i_can_daemonize"
3
+ s.version = "0.3.0"
4
+ s.date = "2009-01-15"
5
+ s.summary = "Better way to build daemons"
6
+ s.email = "apisoni@yammer-inc.com"
7
+ s.homepage = "http://github.com/wonko9/i_can_daemonize"
8
+ s.description = "Better daemonizer."
9
+ s.has_rdoc = true
10
+ s.authors = ["Adam Pisoni", "Amos Elliston"]
11
+ s.files = [
12
+ "History.txt",
13
+ "README.txt",
14
+ "Rakefile",
15
+ "i_can_daemonize.gemspec",
16
+ "lib/i_can_daemonize.rb",
17
+ "lib/i_can_daemonize/version.rb",
18
+ "examples/feature_demo.rb",
19
+ "examples/rails_daemon.rb",
20
+ "examples/simple_daemon.rb",
21
+ "examples/starling_queue_daemon.rb",
22
+ ]
23
+
24
+ s.test_files = ["test/test_i_can_daemonize.rb"]
25
+ s.rdoc_options = ["--main", "README.txt"]
26
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
27
+ # s.add_dependency("diff-lcs", ["> 0.0.0"])
28
+ end
29
+
@@ -0,0 +1,10 @@
1
+ module Clay #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
10
+
@@ -45,12 +45,12 @@ module ICanDaemonize
45
45
  options[:loop_every] = value
46
46
  end
47
47
 
48
- opt.on('-t', '--ontop', 'Stay on top (does not daemonize)') do
49
- options[:ontop] = true
48
+ opt.on('-t', '--ontop', 'Stay on top (does not daemonize)') do |value|
49
+ options[:ontop] = value
50
50
  end
51
51
 
52
52
  opt.on('--instances=NUM', 'Allow multiple instances to run simultaneously? 0 for infinite. default: 1') do |value|
53
- self.instances = value.to_i
53
+ @instances = value.to_i
54
54
  end
55
55
 
56
56
  opt.on('--log-file=LOGFILE', 'Logfile to log to') do |value|
@@ -61,8 +61,10 @@ module ICanDaemonize
61
61
  options[:pid_file] = File.expand_path(value)
62
62
  end
63
63
 
64
- opt.on('--no-log-prefix', 'Do not prefix PID and date/time in log file.') do
65
- options[:log_prefix] = false
64
+ opt.on('--log-prefix=BOOLEAN', 'All output to logfiles will be prefixed with PID and date/time.') do |value|
65
+ if value.downcase == 'false' or value == '0'
66
+ options[:log_prefix] = false
67
+ end
66
68
  end
67
69
  end
68
70
 
@@ -73,14 +75,17 @@ module ICanDaemonize
73
75
  end
74
76
 
75
77
  opts.parse!
78
+ options[:ontop] ||= !ARGV.include?('start')
76
79
 
77
80
  if ARGV.include?('stop')
78
- stop_daemons
81
+ @instances ||= 0
82
+ stop_daemons(@instances)
79
83
  elsif ARGV.include?('restart')
80
84
  restart_daemons
81
- elsif ARGV.include?('start') or ontop?
82
- self.running = true
83
- self.restarted = true if ARGV.include?('HUP')
85
+ elsif ARGV.include?('start')
86
+ @instances ||= 1
87
+ @running = true
88
+ @restarted = true if ARGV.include?("HUP")
84
89
  else
85
90
  puts opts.help
86
91
  end
@@ -99,7 +104,7 @@ module ICanDaemonize
99
104
  end
100
105
 
101
106
  def options
102
- @options ||= {}
107
+ @options ||= {:log_prefix => true}
103
108
  end
104
109
 
105
110
  def config
@@ -160,26 +165,23 @@ module ICanDaemonize
160
165
  # Run this check after each iteration of the loop. If the block returns true, exit gracefully
161
166
  # You can also define the after block by putting an exit_if do/end block in your class.
162
167
  #
163
- # <tt>:log_prefix</tt> BOOL (DEFAULT true)
168
+ # <tt>:log_prefix</tt> BOOL (DEFAULT false)
164
169
  # Prefix log file entries with PID and timestamp
165
- def daemonize(opts={}, &block)
170
+ def daemonize(options={},&block)
166
171
  parse_options
167
172
  return unless ok_to_start?
168
173
 
169
- options.merge!(opts)
170
- puts "Starting #{instances_to_start} #{script_name} #{pluarlize('instance', instances_to_start)}..."
171
- puts "Logging to: #{log_file}" unless ontop?
174
+ options.merge!(options)
175
+ puts "Starting #{script_name} instances: #{instances_to_start} Logging to: #{log_file}"
172
176
 
173
- unless ontop?
177
+ if not options[:ontop]
174
178
  instances_to_start.times do
175
179
  safefork do
176
- open(pid_file, 'a+') {|f| f << Process.pid << "\n"}
177
- at_exit { remove_pid! }
180
+ add_pid_to_pidfile
178
181
 
179
-
180
- trap('TERM') { callback!(:sig_term) ; self.running = false }
181
- trap('INT') { callback!(:sig_int) ; Process.kill('TERM', $$) }
182
- trap('HUP') { callback!(:sig_hup) ; restart_self }
182
+ trap('TERM') { callback!(:sig_term) ; stop; }
183
+ trap('INT') { callback!(:sig_int) ; Process.kill('TERM', $$) }
184
+ trap('HUP') { callback!(:sig_hup) ; restart_self }
183
185
 
184
186
  sess_id = Process.setsid
185
187
  reopen_filehandes
@@ -208,7 +210,7 @@ module ICanDaemonize
208
210
 
209
211
  def run_block(&block)
210
212
  loop do
211
- break unless running?
213
+ break unless @running
212
214
  if options[:timeout]
213
215
  begin
214
216
  Timeout::timeout(options[:timeout].to_i) do
@@ -216,9 +218,9 @@ module ICanDaemonize
216
218
  end
217
219
  rescue Timeout::Error => e
218
220
  if options[:die_on_timeout]
219
- raise TimeoutError.new("#{self} timed out after #{options[:timeout]} seconds while executing block in loop")
221
+ raise TimeoutError.new("#{self} Timed out after #{options[:timeout]} seconds while executing block in loop")
220
222
  else
221
- $stderr.puts "#{self} timed out after #{options[:timeout]} seconds while executing block in loop #{e.backtrace.join("\n")}"
223
+ $stderr.puts "#{self} Timed out after #{options[:timeout]} seconds while executing block in loop #{e.backtrace.join("\n")}"
222
224
  end
223
225
  end
224
226
  else
@@ -231,18 +233,17 @@ module ICanDaemonize
231
233
  sleep 0.1
232
234
  end
233
235
  break if should_exit?
234
- raise DieTime.new('Die if conditions were met!') if should_die?
236
+ raise DieTime.new("Die if conditions were met!") if should_die?
235
237
  end
236
238
  exit(0)
237
239
  end
238
240
 
239
241
  def should_die?
240
- die_if = options[:die_if]
241
- if die_if
242
- if die_if.is_a?(Symbol) or die_if.is_a?(String)
243
- self.send(die_if)
244
- elsif die_if.is_a?(Proc)
245
- die_if.call
242
+ if options[:die_if]
243
+ if options[:die_if].is_a?(Symbol) or options[:die_if].is_a?(String)
244
+ self.send(options[:die_if])
245
+ elsif options[:die_if].is_a?(Proc)
246
+ options[:die_if].call
246
247
  end
247
248
  else
248
249
  false
@@ -250,12 +251,11 @@ module ICanDaemonize
250
251
  end
251
252
 
252
253
  def should_exit?
253
- exit_if = options[:exit_if]
254
- if exit_if
255
- if exit_if.is_a?(Symbol) or exit_if.is_a?(String)
256
- self.send(exit_if.to_sym)
257
- elsif exit_if.is_a?(Proc)
258
- exit_if.call
254
+ if options[:exit_if]
255
+ if options[:exit_if].is_a?(Symbol) or options[:exit_if].is_a?(String)
256
+ self.send(options[:exit_if].to_sym)
257
+ elsif options[:exit_if].is_a?(Proc)
258
+ options[:exit_if].call
259
259
  end
260
260
  else
261
261
  false
@@ -263,27 +263,27 @@ module ICanDaemonize
263
263
  end
264
264
 
265
265
  def instances_to_start
266
- return 1 if restarted?
267
- instances - pids.size
266
+ return 1 if @restarted
267
+ @instances - read_pid_file.size
268
268
  end
269
269
 
270
270
  def ok_to_start?
271
- return false unless running?
272
- return true if restarted?
273
-
271
+ return false unless @running
272
+ return true if @restarted
273
+ pids = read_pid_file
274
274
  living_pids = []
275
275
  if pids and pids.any?
276
276
  pids.each do |pid|
277
277
  if process_alive?(pid)
278
278
  living_pids << pid
279
279
  else
280
- $stderr.puts "Removing stale pid: #{pid}..."
280
+ $stderr.puts "Removing stale pid: #{pid}"
281
281
  pids -= [pid]
282
- self.pids = pids
282
+ rewrite_pidfile(pids)
283
283
  end
284
284
  end
285
- if instances > 0 and living_pids.size >= instances
286
- $stderr.puts "#{script_name} is already running #{living_pids.size} out of #{pluralize('instance', instances)}"
285
+ if @instances > 0 and living_pids.size >= @instances
286
+ $stderr.puts "#{script_name} is already running #{living_pids.size} out of #{@instances} instances"
287
287
  return false
288
288
  end
289
289
  end
@@ -291,37 +291,43 @@ module ICanDaemonize
291
291
  end
292
292
 
293
293
  # stop the daemon, nicely at first, and then forcefully if necessary
294
- def stop_daemons
295
- self.running = false
296
- puts "Stopping #{instances} #{script_name} #{pluarlize('instance', instances)}..."
294
+ def stop_daemons(number_of_pids_to_stop=0)
295
+ @running = false
296
+ pids = read_pid_file
297
+ number_of_pids_to_stop = pids.size if number_of_pids_to_stop == 0
298
+ puts "stopping #{number_of_pids_to_stop} pids"
297
299
  if pids.empty?
298
300
  $stderr.puts "#{script_name} doesn't appear to be running"
299
301
  exit
300
302
  end
301
- pids.each_with_index do |pid, ii|
303
+ pids.each_with_index do |pid,ii|
302
304
  kill_pid(pid)
303
- break if ii == (instances - 1)
305
+ break if ii == (number_of_pids_to_stop - 1)
304
306
  end
305
307
  end
306
308
 
307
309
  def restart_daemons
308
- pids.each do |pid|
310
+ read_pid_file.each do |pid|
309
311
  kill_pid(pid, 'HUP')
310
312
  end
311
313
  end
312
314
 
313
- def kill_pid(pid, signal='TERM')
314
- $stdout.puts("Stopping pid #{pid} with #{signal}...")
315
+ def stop
316
+ @running = false
317
+ end
318
+
319
+ def kill_pid(pid,signal="TERM")
320
+ $stdout.puts("stopping pid: #{pid} sig: #{signal} #{script_name}...")
315
321
  begin
316
322
  Process.kill(signal, pid)
317
323
  if pid_running?(pid, options[:timeout] || 120)
318
- $stdout.puts("Using kill -9 #{pid}")
324
+ $stdout.puts("using kill -9 #{pid}")
319
325
  Process.kill(9, pid)
320
326
  else
321
- $stdout.puts("Process #{pid} stopped")
327
+ $stdout.puts("process #{pid} has stopped")
322
328
  end
323
329
  rescue Errno::ESRCH
324
- $stdout.puts("Couldn't #{signal} #{pid} as it wasn't running")
330
+ $stdout.puts("couldn't #{signal} #{pid} as it wasn't running")
325
331
  end
326
332
  end
327
333
 
@@ -343,21 +349,21 @@ module ICanDaemonize
343
349
  end
344
350
 
345
351
  def restart_self
346
- remove_pid!
352
+ remove_self_from_pidfile
347
353
  cmd = "#{@@config.script_path}/#{script_name} "
348
354
  cmd << 'HUP ' unless ARGV.include?('HUP')
349
355
  cmd << ARGV.join(' ')
350
- puts "Restarting #{cmd} pid: #{$$}..."
356
+ puts "restarting #{cmd} pid: #{$$}"
351
357
  system(cmd)
352
358
  Process.kill('TERM', $$)
353
359
  end
354
360
 
355
361
  def safefork(&block)
356
- fork_tries ||= 0
362
+ @fork_tries ||= 0
357
363
  fork(&block)
358
364
  rescue Errno::EWOULDBLOCK
359
- raise if fork_tries >= 20
360
- fork_tries += 1
365
+ raise if @fork_tries >= 20
366
+ @fork_tries += 1
361
367
  sleep 5
362
368
  retry
363
369
  end
@@ -379,9 +385,9 @@ module ICanDaemonize
379
385
  if log_prefix?
380
386
  def STDOUT.write(string)
381
387
  if @no_prefix
382
- @no_prefix = false if string[-1, 1] == "\n"
388
+ @no_prefix = false if string[-1,1] == "\n"
383
389
  else
384
- string = LOG_FORMAT % [$$, Time.now.strftime(TIME_FORMAT), string]
390
+ string = LOG_FORMAT % [$$,Time.now.strftime(TIME_FORMAT),string]
385
391
  @no_prefix = true
386
392
  end
387
393
  super(string)
@@ -389,64 +395,40 @@ module ICanDaemonize
389
395
  end
390
396
  end
391
397
 
392
- def remove_pid!(pid=Process.pid)
393
- pids.delete(pid)
394
- self.pids = pids
398
+ # create the PID file and install an at_exit handler
399
+ def add_pid_to_pidfile
400
+ open(pid_file, 'a+') {|f| f << Process.pid << "\n"}
401
+ at_exit { remove_self_from_pidfile }
395
402
  end
396
403
 
397
- def pids=(pids)
404
+ def rewrite_pidfile(pids)
398
405
  if pids.any?
399
406
  open(pid_file, 'w') {|f| f << pids.join("\n") << "\n"}
400
407
  else
401
- File.unlink(pid_file) if File.exists?(pid_file)
408
+ remove_pidfile
402
409
  end
403
- @pids = pids
404
- end
405
-
406
- def pids
407
- @pids ||= begin
408
- if File.exist?(pid_file)
409
- File.readlines(pid_file).collect {|p| p.to_i}
410
- else
411
- []
412
- end
413
- end
414
- end
415
-
416
- def instances=(num)
417
- @instances = num
418
- end
419
-
420
- def instances
421
- @instances ||= 1
422
410
  end
423
411
 
424
- def pluarlize(name, num)
425
- num == 1 ? name : "#{name}s"
412
+ def remove_self_from_pidfile
413
+ pids = read_pid_file
414
+ pids.delete(Process.pid)
415
+ rewrite_pidfile(pids)
426
416
  end
427
417
 
428
- def running?
429
- @running || false
418
+ def remove_pidfile
419
+ File.unlink(pid_file) if File.exists?(pid_file)
430
420
  end
431
421
 
432
- def running=(bool)
433
- @running = bool
434
- end
435
-
436
- def restarted?
437
- @restarted || false
438
- end
439
-
440
- def restarted=(bool)
441
- @restarted = bool
442
- end
443
-
444
- def ontop?
445
- options[:ontop]
422
+ def read_pid_file
423
+ if File.exist?(pid_file)
424
+ File.readlines(pid_file).collect {|p| p.to_i}
425
+ else
426
+ []
427
+ end
446
428
  end
447
429
 
448
430
  def log_prefix?
449
- options[:log_prefix] || true
431
+ options[:log_prefix]
450
432
  end
451
433
 
452
434
  LOG_PATHS = ['log/', 'logs/', '../log/', '../logs/', '../../log', '../../logs', '.']
@@ -472,7 +454,7 @@ module ICanDaemonize
472
454
  end
473
455
 
474
456
  def script_name
475
- @script_name ||= File.basename($0).gsub('.rb', '')
457
+ @script_name ||= File.basename($0)
476
458
  end
477
459
 
478
460
  def script_name=(script_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wonko9-i_can_daemonize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Pisoni
@@ -10,35 +10,38 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-19 00:00:00 -08:00
13
+ date: 2009-01-15 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: ICanDaemonize makes it dead simple to create daemons of your own
18
- email: wonko9@gmail.com
17
+ description: Better daemonizer.
18
+ email: apisoni@yammer-inc.com
19
19
  executables: []
20
20
 
21
21
  extensions: []
22
22
 
23
- extra_rdoc_files: []
24
-
25
- files:
23
+ extra_rdoc_files:
26
24
  - History.txt
27
25
  - Manifest.txt
28
- - Rakefile
29
26
  - README.txt
30
- - lib/i_can_daemonize
31
- - lib/i_can_daemonize/version.rb
27
+ files:
28
+ - History.txt
29
+ - README.txt
30
+ - Rakefile
31
+ - i_can_daemonize.gemspec
32
32
  - lib/i_can_daemonize.rb
33
- - test/simple_daemon.rb
34
- - test/test_helper.rb
35
- - test/test_i_can_daemonize.rb
33
+ - lib/i_can_daemonize/version.rb
34
+ - examples/feature_demo.rb
35
+ - examples/rails_daemon.rb
36
+ - examples/simple_daemon.rb
37
+ - examples/starling_queue_daemon.rb
38
+ - Manifest.txt
36
39
  has_rdoc: true
37
40
  homepage: http://github.com/wonko9/i_can_daemonize
38
41
  post_install_message:
39
42
  rdoc_options:
40
- - --inline-source
41
- - --charset=UTF-8
43
+ - --main
44
+ - README.txt
42
45
  require_paths:
43
46
  - lib
44
47
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -59,6 +62,6 @@ rubyforge_project:
59
62
  rubygems_version: 1.2.0
60
63
  signing_key:
61
64
  specification_version: 2
62
- summary: ICanDaemonize makes it dead simple to create daemons of your own
63
- test_files: []
64
-
65
+ summary: Better way to build daemons
66
+ test_files:
67
+ - test/test_i_can_daemonize.rb
@@ -1,26 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require File.dirname(__FILE__) + '/../lib/i_can_daemonize'
3
-
4
- class SimpleDaemon
5
- include ICanDaemonize
6
-
7
- arg '--test=VALUE', 'Test Arg' do |value|
8
- @test = value
9
- end
10
-
11
- arg '-s', '--short-test=VALUE', 'Test arg with shortname' do |value|
12
- @short_test = value
13
- end
14
-
15
- counter = 0
16
- daemonize do
17
- if @options[:loop_every]
18
- counter += 1
19
- File.open(TEST_FILE, 'w'){|f| f << counter}
20
- elsif @test
21
- File.open(TEST_FILE, 'w'){|f| f << "#{@test}|#{@short_test}"}
22
- else
23
- File.open(TEST_FILE, 'w'){|f| f << "#{log_file}|#{pid_file}"}
24
- end
25
- end
26
- end
data/test/test_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'test/unit'
2
- require 'pp'
3
-
4
- TEST_FILE = File.dirname(__FILE__) + '/test.txt' unless defined?(TEST_FILE)
5
-
6
- unless Test::Unit::TestCase.respond_to?(:test)
7
- class << Test::Unit::TestCase
8
- def test(name, &block)
9
- test_name = "test_#{name.gsub(/[\s\W]/,'_')}"
10
- raise ArgumentError, "#{test_name} is already defined" if self.instance_methods.include? test_name
11
- define_method test_name, &block
12
- end
13
- end
14
- end