How to make a Ruby script into a daemon process

Use Daemons.

1.Install

gem install daemons

2. Then, say you have myserver.rb, create a control script, myserver_control.rb, like this:

require 'rubygems'        # if you use RubyGems
require 'daemons'

Daemons.run('myserver.rb')

3. and use it from the console like this:

$ ruby myserver_control.rb start
    (myserver.rb is now running in the background)
$ ruby myserver_control.rb restart
    (...)
$ ruby myserver_control.rb stop

http://daemons.rubyforge.org/

 

Leave a Reply

Your email address will not be published. Required fields are marked *