seamusabshere-daemon-spawn 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/daemon_spawn.rb +25 -1
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/lib/daemon_spawn.rb CHANGED
@@ -45,6 +45,16 @@ module DaemonSpawn
45
45
  end
46
46
  puts "#{daemon.app_name} started."
47
47
  end
48
+
49
+ def self.still_alive?(pid)
50
+ alive = true
51
+ begin
52
+ Process.kill 0, pid
53
+ rescue Errno::ESRCH
54
+ alive = false
55
+ end
56
+ alive
57
+ end
48
58
 
49
59
  def self.stop(daemon) #:nodoc:
50
60
  if pid = daemon.pid
@@ -54,6 +64,19 @@ module DaemonSpawn
54
64
  Process.wait(pid)
55
65
  rescue Errno::ECHILD
56
66
  end
67
+
68
+ # just in case...
69
+ ticks = daemon.timeout
70
+ while ticks > 0 and still_alive?(pid) do
71
+ puts "Process is still alive. #{ticks} seconds until I kill -9 it..."
72
+ sleep 1
73
+ ticks -= 1
74
+ end
75
+ if still_alive?(pid)
76
+ puts "Process didn't quit after timeout of #{daemon.timeout} seconds. Killing..."
77
+ Process.kill 9, pid
78
+ end
79
+ # ... ok.
57
80
  else
58
81
  puts "PID file not found. Is the daemon started?"
59
82
  end
@@ -66,11 +89,12 @@ module DaemonSpawn
66
89
  end
67
90
 
68
91
  class Base
69
- attr_accessor :log_file, :pid_file, :sync_log, :working_dir, :app_name, :singleton, :index, :signal
92
+ attr_accessor :log_file, :pid_file, :sync_log, :working_dir, :app_name, :singleton, :index, :signal, :timeout
70
93
 
71
94
  def initialize(opts = {})
72
95
  raise 'You must specify a :working_dir' unless opts[:working_dir]
73
96
  self.signal = opts[:signal] || "TERM"
97
+ self.timeout = opts[:timeout] || 15
74
98
  self.working_dir = opts[:working_dir]
75
99
  self.app_name = opts[:application] || classname
76
100
  self.pid_file = opts[:pid_file] || File.join(working_dir, 'tmp', 'pids', app_name + extension)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Vollmer