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
work.

I am running webrick or mongrel.

by
TheR

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:

reset_session

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

redirect_to :controller => ‘my_controller’, :action => ‘my_action’

Both things are done in your controllers.

On Oct 13, 3:19 am, Damjan R. [email protected]

pepe wrote:

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:

reset_session

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

redirect_to :controller => ‘my_controller’, :action => ‘my_action’

Both things are done in your controllers.

On Oct 13, 3:19�am, Damjan R. [email protected]

I would like to quit (kill) session. Just like pressing Ctrl+C.

by
TheR

Is the kill from outside application the only solution?

by
TheR

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
browser.

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.

On Oct 14, 4:01 am, Damjan R. [email protected]id

On Oct 13, 11:56 am, Damjan R. [email protected]
wrote:


Posted viahttp://www.ruby-forum.com/.

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

controller:
def restart
sudo monit restart -g mongrel all << server_sudo_password
end

view:
<% 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.

[email protected] wrote:

On Oct 13, 11:56�am, Damjan R. [email protected]
wrote:


Posted viahttp://www.ruby-forum.com/.

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

controller:
def restart
sudo monit restart -g mongrel all << server_sudo_password
end

view:
<% 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
TheR

Damjan R. wrote:
[…]

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.

There are better ways to build PDF files. If you can tell us a bit more
about what you’re doing, perhaps we can make suggestions…

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 think you may be anticipating a problem that may or may not exist.
Why don’t you test it out and see if you need this feature?

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

Thank you
TheR

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

Damjan R. wrote:
[…]

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.

There are better ways to build PDF files. If you can tell us a bit more
about what you’re doing, perhaps we can make suggestions…

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 think you may be anticipating a problem that may or may not exist.
Why don’t you test it out and see if you need this feature?

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

Thank you
TheR

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I would use something like god (http://god.rubyforge.org/) to watch the
application for memory problems and the like. You could easily use this
daemon to check for a “restart.txt” file and if it exists:

  1. erase the file
  2. restart application

Your restart method in the controller is just:

def restart
File.open(‘restart.txt’,‘wb’) {}
end

and don’t forget the equivalent of
before_filter :check_is_admin, :only => [:restart]

Without a daemon running, you can crash your app fine but it will lay
down dead without any hope for resurection…

Gaspard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs