How to exit rails application from within

I would like to restart my rails application from within application. On
demand. But I am stucked on first step. How to exit. exit 0 doesn't

I am running webrick or mongrel.


What do you mean by "restarting" the application? Do you mean end the
session (if any) and (re)display the login/index/initial page?

If you need to end a session you can do it with this:


To send a user to the login/index/initial page you can just use a

redirect_to :controller => 'my_controller', :action => 'my_action'

Both things are done in your controllers.

Is the kill from outside application the only solution?


I don't think you'll be able to do that. I am assuming that you mean
the user being able to kill the application. Remember that the user
will probably be removed from the server that runs Rails and he/she
won't have access to it. That access is only available through the

The only way that you'll be able to do something like that will be to
provide a Logout link or something like that and make it available
through a main layout so it's present in all views.

If what you want to do is to be able to stop the session from the
server itself you'll have to figure out who the user is that you want
to end the session for and have a way of managing the sessions for all
users (database store?), then you could kill the session any way you
want (removing data from the DB for the session?). That won't buy you
much, though, if the user can still Login and keep going.

If you are running inside mongrels with monit I am sure you could
really do this quite easily...

def restart
  `sudo monit restart -g mongrel all << server_sudo_password`

<% link_to "Restart", :action => :restart %>

Of course because you CAN do something does not mean you SHOULD...
requires you put the sudo password in the code BAD BAD...

I have not tested it, because my dev system is not setup this way.
but looks like it would work.

Sadly my server is Windows. I am working on an application for internal
users which runs Word and Excel with ole automation a lot to provide
output documents in pdf.

I haven't yet had production loads but a lot of things can go wrong when
running ole automation. So I thought If I could close session and
restart it on demand .... ( You can always repair windows by restarting
it :wink:

I thought that Mongrel or Webrick have some interface to end itself.

Thank you