#!/usr/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log # and the GC period is nil (turned off). A reasonable number of requests # could range from 10-100 depending on the memory footprint of your app. # # Example: # # Default log path, normal GC behavior. # RailsFCGIHandler.process! # # # Default log path, 50 requests between GC. # RailsFCGIHandler.process! nil, 50 # # # Custom log path, normal GC behavior. # RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log' # ENV['RAILS_ENV'] ||= 'production' require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' class RailsFCGIHandler RUBY_FCGI_MAX_REQUESTS = 100 private def process_request_with_call_counter(cgi) @processed_request_count ||= 0 Dispatcher.dispatch(cgi) rescue Exception => e # errors from CGI dispatch raise if SignalException === e dispatcher_error(e) ensure @processed_request_count += 1 if @processed_request_count >= (RUBY_FCGI_MAX_REQUESTS + rand(30)) dispatcher_log :info, "battered trough #{@processed_request_count} requests, time to change shifts" @when_ready = :exit end end alias_method :process_request, :process_request_with_call_counter def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end RailsFCGIHandler.process!