Changeset 1284
- Timestamp:
- 05/04/05 11:10:13 (4 years ago)
- Files:
-
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/dispatches/dispatch.fcgi (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/CHANGELOG
r1261 r1284 1 1 *SVN* 2 3 4 * Allow graceful exits for dispatch.fcgi processes by sending a SIGUSR1. If the process is currently handling a request, the request will be allowed to complete and then will terminate itself. If a request is not being handled, the process is terminated immediately (via #exit). This basically works like restart graceful on Apache. [Jamis Buck] 5 6 * Made dispatch.fcgi more robust by catching fluke errors and retrying unless its a permanent condition. [Jamis Buck] 2 7 3 8 * Added console --profile for profiling an IRB session #1154 [bitsweat] trunk/railties/dispatches/dispatch.fcgi
r981 r1284 1 1 #!/usr/local/bin/ruby 2 3 def dispatcher_log(level, path,msg) 4 Logger.new(path).send(level, msg) 5 rescue Object => log_error 6 STDERR << "Couldn't write to #{path}: #{msg}" 7 end 2 8 3 9 def dispatcher_error(path,e,msg="") 4 10 error_message = 5 11 "[#{Time.now}] Dispatcher failed to catch: #{e} (#{e.class})\n #{e.backtrace.join("\n ")}\n#{msg}" 6 Logger.new(path).fatal(error_message) 7 rescue Object => log_error 8 STDERR << "Couldn't write to #{path} (#{e} [#{e.class}])\n" << error_message 12 dispatcher_log(:error, path, error_message) 9 13 end 10 14 15 last_error_on = nil 11 16 begin 12 17 require File.dirname(__FILE__) + "/../config/environment" … … 15 20 16 21 log_file_path = "#{RAILS_ROOT}/log/fastcgi.crash.log" 22 dispatcher_log(:info, log_file_path, "fcgi #{$$} starting") 23 24 # Allow graceful exits by sending the process SIGUSR1. If the process is 25 # currently handling a request, the request will be allowed to complete and 26 # then will terminate itself. If a request is not being handled, the 27 # process is terminated immediately (via #exit). 28 29 $please_exit_at_your_earliest_convenience = false 30 $i_am_currently_processing_a_request = false 31 trap("USR1") do 32 if $i_am_currently_processing_a_request 33 dispatcher_log(:info, log_file_path, "asking #{$$} to terminate ASAP") 34 $please_exit_at_your_earliest_convenience = true 35 else 36 dispatcher_log(:info, log_file_path, "telling #{$$} to terminate NOW") 37 exit 38 end 39 end 40 41 # Process each request as it comes in, as a pseudo-CGI. 17 42 18 43 FCGI.each_cgi do |cgi| 19 44 begin 45 $i_am_currently_processing_a_request = true 20 46 Dispatcher.dispatch(cgi) 21 rescue Object => rails_error 22 dispatcher_error(log_file_path, rails_error) 47 rescue Object => e 48 dispatcher_error(log_file_path, e) 49 ensure 50 $stdout.flush 51 $i_am_currently_processing_a_request = false 52 break if $please_exit_at_your_earliest_convenience 23 53 end 24 54 end 55 56 dispatcher_log(:info, log_file_path, "fcgi #{$$} terminated gracefully") 57 rescue SystemExit => exit_error 58 dispatcher_log(:info, log_file_path, "fcgi #{$$} terminated by explicit exit") 25 59 rescue Object => fcgi_error 26 dispatcher_error(log_file_path, fcgi_error, "FCGI process #{$$} killed by this error\n") 60 # retry on errors that would otherwise have terminated the FCGI process, but 61 # only if they occur more than 10 seconds apart. 62 if !(SignalException === fcgi_error) && (last_error_on.nil? || last_error_on - Time.now > 10) 63 last_error_on = Time.now 64 dispatcher_error(log_file_path, fcgi_error, "FCGI process #{$$} almost killed by this error\n") 65 retry 66 else 67 dispatcher_error(log_file_path, fcgi_error, "FCGI process #{$$} killed by this error\n") 68 end 27 69 end