daemon-kit 0.1.7.7 → 0.1.7.8
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/History.txt +13 -0
- data/README.rdoc +1 -0
- data/app_generators/daemon_kit/templates/config/environment.rb +3 -3
- data/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
- data/app_generators/daemon_kit/templates/config/environments/production.rb +2 -0
- data/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
- data/lib/daemon_kit.rb +1 -1
- data/lib/daemon_kit/application.rb +5 -1
- data/lib/daemon_kit/initializer.rb +39 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 0.1.7.8 2009-06-22
|
2
|
+
|
3
|
+
* Optional logging of all exceptions when the daemon process dies
|
4
|
+
unexpectedly
|
5
|
+
* Update generated environment.rb to reflect new backtraces option
|
6
|
+
|
7
|
+
== 0.1.7.7 2009-06-22
|
8
|
+
|
9
|
+
* Fixed compatibility with rufus-scheduler-2.0.0 (or newer) in cron
|
10
|
+
generator
|
11
|
+
* Started central eventmachine reactor management code
|
12
|
+
* Now depends on eventmachine
|
13
|
+
|
1
14
|
== 0.1.7.6 (Not released)
|
2
15
|
|
3
16
|
* Support for cucumber
|
data/README.rdoc
CHANGED
@@ -11,12 +11,12 @@ DaemonKit::Initializer.run do |config|
|
|
11
11
|
# The name of the daemon as reported by process monitoring tools
|
12
12
|
config.daemon_name = '<%= daemon_name %>'
|
13
13
|
|
14
|
-
# Uncomment to allow multiple instances to run
|
15
|
-
# config.mulitple = true
|
16
|
-
|
17
14
|
# Force the daemon to be killed after X seconds from asking it to
|
18
15
|
# config.force_kill_wait = 30
|
19
16
|
|
17
|
+
# Log backraces when a thread/daemon dies (Recommended)
|
18
|
+
# config.backtraces = true
|
19
|
+
|
20
20
|
# Configure the safety net (see DaemonKit::Safety)
|
21
21
|
# config.safety_net.handler = :mail # (or :hoptoad )
|
22
22
|
# config.safety_net.mail.host = 'localhost'
|
data/lib/daemon_kit.rb
CHANGED
@@ -9,7 +9,7 @@ $:.unshift( File.dirname(__FILE__).to_absolute_path ) unless
|
|
9
9
|
$:.include?( File.dirname(__FILE__).to_absolute_path )
|
10
10
|
|
11
11
|
module DaemonKit
|
12
|
-
VERSION = '0.1.7.
|
12
|
+
VERSION = '0.1.7.8'
|
13
13
|
|
14
14
|
autoload :Initializer, 'daemon_kit/initializer'
|
15
15
|
autoload :Application, 'daemon_kit/application'
|
@@ -79,7 +79,11 @@ module DaemonKit
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
@pid_file.
|
82
|
+
if @pid_file.running?
|
83
|
+
puts "Process still running, leaving pidfile behind! Consider using configuration.force_kill_wait."
|
84
|
+
else
|
85
|
+
@pid_file.cleanup
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
# Call this from inside a daemonized process to complete the
|
@@ -61,6 +61,10 @@ module DaemonKit
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.shutdown
|
64
|
+
DaemonKit.logger.info "Running shutdown hooks"
|
65
|
+
|
66
|
+
log_exceptions if DaemonKit.configuration.backtraces
|
67
|
+
|
64
68
|
DaemonKit.logger.warn "Shutting down #{DaemonKit.configuration.daemon_name}"
|
65
69
|
exit
|
66
70
|
end
|
@@ -85,6 +89,7 @@ module DaemonKit
|
|
85
89
|
|
86
90
|
include_core_lib
|
87
91
|
load_postdaemonize_configs
|
92
|
+
configure_backtraces
|
88
93
|
|
89
94
|
set_process_name
|
90
95
|
|
@@ -160,6 +165,7 @@ module DaemonKit
|
|
160
165
|
term_proc = Proc.new { DaemonKit::Initializer.shutdown }
|
161
166
|
configuration.trap( 'INT', term_proc )
|
162
167
|
configuration.trap( 'TERM', term_proc )
|
168
|
+
at_exit { DaemonKit::Initializer.shutdown }
|
163
169
|
end
|
164
170
|
|
165
171
|
def include_core_lib
|
@@ -168,9 +174,38 @@ module DaemonKit
|
|
168
174
|
end
|
169
175
|
end
|
170
176
|
|
177
|
+
def configure_backtraces
|
178
|
+
Thread.abort_on_exception = configuration.backtraces
|
179
|
+
end
|
180
|
+
|
171
181
|
def set_process_name
|
172
182
|
$0 = configuration.daemon_name
|
173
183
|
end
|
184
|
+
|
185
|
+
def self.log_exceptions
|
186
|
+
trace_file = File.join( DaemonKit.root, "backtrace-#{Time.now.strftime('%Y%m%d%H%M%S')}-#{Process.pid}.log" )
|
187
|
+
trace_log = Logger.new( trace_file )
|
188
|
+
|
189
|
+
# Find the last exception
|
190
|
+
e = nil
|
191
|
+
ObjectSpace.each_object {|o|
|
192
|
+
if ::Exception === o
|
193
|
+
e = o
|
194
|
+
end
|
195
|
+
}
|
196
|
+
|
197
|
+
trace_log.info "*** Below you'll find the most recent exception thrown, this will likely (but not certainly) be the exception that made #{DaemonKit.configuration.daemon_name} exit abnormally ***"
|
198
|
+
trace_log.error e
|
199
|
+
|
200
|
+
trace_log.info "*** Below you'll find all the exception objects in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***"
|
201
|
+
ObjectSpace.each_object {|o|
|
202
|
+
if ::Exception === o
|
203
|
+
trace_log.error o
|
204
|
+
end
|
205
|
+
}
|
206
|
+
|
207
|
+
trace_log.close
|
208
|
+
end
|
174
209
|
end
|
175
210
|
|
176
211
|
# Holds our various configuration values
|
@@ -203,7 +238,10 @@ module DaemonKit
|
|
203
238
|
configurable :daemon_name, :locked => true
|
204
239
|
|
205
240
|
# Use the force kill patch? Give the number of seconds
|
206
|
-
|
241
|
+
configurable :force_kill_wait
|
242
|
+
|
243
|
+
# Should be log backtraces
|
244
|
+
configurable :backtraces, false
|
207
245
|
|
208
246
|
# Collection of signal traps
|
209
247
|
attr_reader :signal_traps
|