wonko9-i_can_daemonize 0.7.2 → 0.8.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 (3) hide show
  1. data/VERSION.yml +2 -2
  2. data/lib/i_can_daemonize.rb +22 -1
  3. metadata +1 -1
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 7
4
- :patch: 2
3
+ :minor: 8
4
+ :patch: 0
@@ -25,7 +25,7 @@ module ICanDaemonize
25
25
  end
26
26
 
27
27
  module ClassMethods
28
-
28
+
29
29
  def initialize_options
30
30
  @@config = Config.new
31
31
  @@config.script_path = File.expand_path(File.dirname($0))
@@ -78,6 +78,8 @@ module ICanDaemonize
78
78
  stop_daemons
79
79
  elsif ARGV.include?('restart')
80
80
  restart_daemons
81
+ elsif ARGV.include?('rotate')
82
+ rotate_daemons
81
83
  elsif ARGV.include?('start') or ontop?
82
84
  self.running = true
83
85
  self.restarted = true if ARGV.include?('HUP')
@@ -189,6 +191,7 @@ module ICanDaemonize
189
191
  trap('TERM') { callback!(:sig_term) ; self.running = false }
190
192
  trap('INT') { callback!(:sig_int) ; Process.kill('TERM', $$) }
191
193
  trap('HUP') { callback!(:sig_hup) ; restart_self }
194
+ trap('USR1') { callback!(:sig_usr1) ; reopen_filehandes }
192
195
 
193
196
  sess_id = Process.setsid
194
197
  reopen_filehandes
@@ -316,6 +319,22 @@ module ICanDaemonize
316
319
  end
317
320
  end
318
321
 
322
+ def rotate_daemons
323
+ if pids.empty?
324
+ $stdout.puts "#{script_name} doesn't appear to be running!"
325
+ exit(1)
326
+ end
327
+
328
+ $stdout.puts "Sending SIGUSR1 to #{pids.join(', ')} ..."
329
+ pids.each do |pid|
330
+ begin
331
+ Process.kill('USR1', pid)
332
+ rescue Errno::ESRCH
333
+ $stdout.puts("Couldn't send USR1 #{pid} as it wasn't running")
334
+ end
335
+ end
336
+ end
337
+
319
338
  def restart_daemons
320
339
  pids.each do |pid|
321
340
  kill_pid(pid, 'HUP')
@@ -388,6 +407,7 @@ module ICanDaemonize
388
407
  STDOUT.reopen(log_file, 'a')
389
408
  STDOUT.sync = true
390
409
  STDERR.reopen(STDOUT)
410
+
391
411
  if log_prefix?
392
412
  def STDOUT.write(string)
393
413
  if @no_prefix
@@ -490,5 +510,6 @@ module ICanDaemonize
490
510
  def script_name=(script_name)
491
511
  @script_name = script_name
492
512
  end
513
+
493
514
  end
494
515
  end
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.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Pisoni