How to run long scripts on production/staging server

Updated . Posted . Visible to the public. Repeats.

In a nutshell, use screen

Why?
Sometimes we are concerned that if our connection gets closed, the process we are running will close too.

The processes or login sessions you establish through screen don't go away. You can resume your screen sessions.

How?

  1. run screen command
    screen
    or you can give that screen a name (will help afterwards)
    screen -S some_name

  2. run your time consuming command
    script/runner path_to_some_long_script.rb

  3. detatch from your screen with the following commands

  • Crtl + A
  • d
  1. to reattach run
    screen -r some_name

  2. to exit the screen run
    exit :)

TIPS
to see all screens you can run (it will show the screen PID and name)
screen -ls

you can reattach a screen by giving it's name or it's PID
screen -r some_name or screen -r PID

if there is only one screen, then you can use simply
screen -r

can be used for other things not only for running lengthy scripts

Dragos Miron
Last edit
Posted by Dragos Miron to HouseTrip Deck (2012-10-01 14:42)