6

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.

Community
  • 1
  • 1
Stanley
  • 5,261
  • 9
  • 38
  • 55
  • Could anyone point me to figure out why nohup doesn't work like we'd expect it to for a console application like this? – Kevin Jun 14 '22 at 07:16

3 Answers3

10

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
Matt
  • 17,290
  • 7
  • 57
  • 71
  • 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. – Joshua Pinter Apr 10 '15 at 18:34
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

Tigraine
  • 23,358
  • 11
  • 65
  • 110
0

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

Johnno Nolan
  • 29,228
  • 19
  • 111
  • 160