Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 294
Stanley Avatar asked Jun 25 '12 13:06

Stanley


1 Answers

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
like image 101
Matt Avatar answered Oct 14 '22 03:10

Matt