How to restart server programmatically?

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

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