How to keep rails command from Rails Console running after SSH Client (PuTTy) closes
Asked Answered
P

3

7

I connect to our Ubuntu production server using PuTTy.

I want to reindex a specific Model using Solr. I want to run the reindex command from the Rails Console, i.e. Modelname.reindex (as this seems to run quicker than the rake task.)

We are, however, looking at a vast volume of data and this indexing is expected to take a few hours.

I want to be able to start this task in the rails console and it should continue running even if I exit PuTTy. How to do this?

Linux: Prevent a background process from being stopped after closing SSH client suggests nohup, but I don't see if/how that can be used with the rails console.

Phonometer answered 25/6, 2012 at 13:55 Comment(1)
Could anyone point me to figure out why nohup doesn't work like we'd expect it to for a console application like this?Packet
M
11

Use sudo apt-get install screen to install screen. Then run it using screen. Now you have a separate console window which can be detached using Ctrl + A, then D. Closing putty will not end your screen-session. If you log back in at any later point, you may resume the sessions using screen -r.

To summarize:

> sudo apt-get install screen
> screen
# pops up a new shell
> rails c
# run your reindex operation
# press Ctrl + A, then D
> exit
# putty closes

# reconnect using putty
> screen -r
# you should be back in your rails console
Mondrian answered 25/6, 2012 at 13:58 Comment(1)
Enough good words could not be said about screen. Take a look at the man screen when you have a sec and see all the things you can do with it.Quarterdeck
U
0

What you can do is use screen or tmux to keep your session open on the server.

If you simply type screen a terminal multiplexer will start that will keep the session even if you disconnect your console.

Once you reconnect to the console you can get the session back using screen -dr

Unpen answered 25/6, 2012 at 13:58 Comment(0)
E
0

You should use something like tmux or screen and detach from the session.

Edulcorate answered 25/6, 2012 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.