Reload an application without restarting the Server?

Hi, I would like to set up a “shared hosting”-like rails environment on
a linux (+Apache1.3 +FastCGI +MySQL) machine. As we all know, rails
provides support for different environments.

Now I would like to enable my “users” to switch individual applications
between development and production mode. In theory, all they have to do
is to add “ENV[‘RAILS_ENV’] ||= ‘production’” into their environment.rb.

The problem is, that the production environment caches the rails
application and once you have entered production mode you cannot switch
back without killing the FastCGI processes or restarting the webserver.

I know that its possible because the RailsFCGIHandler has methods called
resart!, restore! and reload! that exactly that but they are private and
I don’t know how to obtain a reference to RailsFCGIHandler from a Rails
ActionController within that application.

I would like to have some kind of reload script or an admin page with
the button: “Reload Application”…

(And no, I can’t just restart the server because its a shared hosting
environment so there are other (non-rail/ruby) applications running on
that same server)

You mean, there is no way I can reload a production application without
restarting the whole server???

Christian K. wrote:

You mean, there is no way I can reload a production application without
restarting the whole server???

No need to restart the web server, check out script/process/reaper and
spawner

Ray

You could probably kill a given user’s FCGI processes with a shell
script; new ones should get spawned as needed. Try that.

I guess you could also have the production environments run in an
individual Mongrel or Lighttpd instance that you proxy through Apache.
Then the users could restart those to their hearts’ content. Just
guessing.

Still seems fishy to host a single instance of an app and switch it
between development and production modes. I’d think most people would
want to develop locally and only host the production version of the
site, and that the remaining folks who can’t or won’t install MySQL and
Rails on their own PC would want both environments available
simultaneously so they don’t have to take down their site every time
they want to develop.

Christian K. wrote:

You mean, there is no way I can reload a production application without
restarting the whole server???

Christian K. wrote:

You mean, there is no way I can reload a production application without
restarting the whole server???

The other way to do it would be to use like “ps -A | grep
/username/appname/dispatch.fcgi” then just kill those fcgi processes. I
use a similar method to reload my app hosted on textdrive
(www.miami-bid.com) when ever I do an svn-update. The exact syntax of
that would be a little complicated, probably, but perfectly doable.

From the Agile book:

killall -USR1 dispatch.fcgi

does a graceful restart of all currently running fcgi processes on *nix.
Always works for me.

  • michael.

Thanks for the answers. You saved my day! :slight_smile:

Steve K. wrote:

I guess you could also have the production environments run in an
individual Mongrel or Lighttpd instance that you proxy through Apache.
Then the users could restart those to their hearts’ content. Just
guessing.
Might be an idea. I’ve never done that though.

Still seems fishy to host a single instance of an app and switch it
between development and production modes.

I do plan to develop locally but at some point I would like to patches
I’ve uploaded. Or maybe I can’t reproduce a bug locally so I would like
to be able to run the web app in dev mode.

Thank you guys!

I know this is probably going to sound like a broken record, but check
out
Capistrano. I use it on Textdrive (shared), and for multiple apps on my
VPS,
and it’s the easiest way to deploy/restart an app, especially if you’re
already using SVN (which I also highly recommend). It can be a little
bit of
work to get it going, but now that I use it I can’t imagine deploying
without it. It will automatically call reaper and spawner to restart
your
app for you.

Matt

Christian K. wrote:

Matt W. wrote:

I know this is probably going to sound like a broken record, but check
out
Capistrano. I use it on Textdrive (shared), and for multiple apps on my
VPS,
and it’s the easiest way to deploy/restart an app, especially if you’re
already using SVN (which I also highly recommend). It can be a little
bit of
work to get it going, but now that I use it I can’t imagine deploying
without it. It will automatically call reaper and spawner to restart
your
app for you.

Matt

Hm… sounds useful too. I’ve never used subversion or CVS but that
might be worth a try too. Thx! :slight_smile:

Ok… I’m still working on it but the main problem is, that I (=my shell
account) don’t have permissions to kill (send any signals ot) the
“dispatch.fcgi” processes… I haven’t trief capistrano yet but I bet it
uses something like kill -9 #{pid} too… Please correct me if I’m
wrong…

Matt W. wrote:

I know this is probably going to sound like a broken record, but check
out
Capistrano. I use it on Textdrive (shared), and for multiple apps on my
VPS,
and it’s the easiest way to deploy/restart an app, especially if you’re
already using SVN (which I also highly recommend). It can be a little
bit of
work to get it going, but now that I use it I can’t imagine deploying
without it. It will automatically call reaper and spawner to restart
your
app for you.

Matt

Hm… sounds useful too. I’ve never used subversion or CVS but that
might be worth a try too. Thx! :slight_smile: