Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ruby script in background without using screen

I have a two scripts in the Rails environment which have to run 24/7. I'm working on a remote server, so I need to start the scripts using ssh, which means I need to keep the ssh windows open all the time.

I'm searching for a simple way to run these scripts in the background so they aren't canceled as soon as I close the ssh connection.

I don't want to use screen. I think there must be simpler way to handle this. Isn't there?

like image 726
davidb Avatar asked Apr 25 '12 12:04

davidb


4 Answers

I think the most basic solution would be nohup:

nohup myscript &> /dev/null &
like image 74
Sergey Kuleshov Avatar answered Nov 16 '22 02:11

Sergey Kuleshov


You can disown a script:

 ruby script.rb &!

STDOUT/STDERR are still attached to the current shell, but the ruby process isn't a child of the shell anymore, so it won't get killed if you close the terminal.

like image 4
Reactormonk Avatar answered Nov 16 '22 02:11

Reactormonk


Check Daemons. It's a toolkit for converting a script to a controllable daemon.

like image 2
luacassus Avatar answered Nov 16 '22 04:11

luacassus


You can use

  • runit
  • supervisord

For daemonizing

Or some ruby stuff: https://www.ruby-toolbox.com/#Background_Processing for background processing

like image 1
fl00r Avatar answered Nov 16 '22 03:11

fl00r