Just in case anyone Googles this looking for a solution, the answer I came
up with is branching off a new Thread in an after_filter in the controller
and some polite modification of dispatch.fcgi.
[in my controller]
def ensure_fresh_server
begin
Thread.new do
logger.info "restarting server!"
system "#{RAILS_ROOT}/script/process/reaper -a graceful"
end if @site.is_active? or @site.is_active_modified?
end rescue nil
end
[dispatch.fcgi]
#!/usr/bin/env ruby
require File.dirname(__FILE__) + "/../config/environment"
require ''fcgi_handler''
class RailsFCGIHandler
private
def busy_exit_handler(signal)
dispatcher_log :info, "busy: asked to terminate during request signal
#{signal}, deferring!"
@when_ready = :exit
end
# Dreamhost sends the term signal and if were handling a request defer it
def term_process_request(cgi)
install_signal_handler(''TERM'',method(:busy_exit_handler).to_proc)
Dispatcher.dispatch(cgi)
rescue Exception => e # errors from CGI dispatch
raise if SignalException === e
dispatcher_error(e)
ensure
install_signal_handler(''TERM'',
method(:exit_now_handler).to_proc)
end
alias_method :process_request, :term_process_request
end
RailsFCGIHandler.process!
# End of file...
RSL
On 3/29/07, Russell Norris
<rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org>
wrote:>
> I need to be able to restart my server based on a specific database
> change. I''ve been trying a call to
system("script/process/reaper -a graceful
> -d dispatch.fcgi") but that raises a transaction error which rolls
back
> the save. I wasn''t aware that after_save would rollback.
That''s potentially
> useful but pretty much not right now. Here''s my code:
>
> def after_update
> system("#{RAILS_ROOT}/script/process/reaper -a graceful -d
dispatch.fcgi")
> if routing_modified?
> end
>
> I''ve also looked at calling the Killer in
> "vendor/rails/railties/lib/commands/process/reaper" but
can''t figure out how
> to pass it the correct parameters when just _requiring_
> "commands/process/reaper" calls an instance of Killer.
>
> I''d really appreciate your help, kittens. Before I forget,
I''m running
> Apache2 [no Mongrel, sadly] and Edge Rails if that makes a difference.
>
> RSL
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---