tags:

views:

119

answers:

2

Well, the title say it all. I have a ruby script I want running as a service (one I can start and stop) on my Linux box. I was able to find how to do it on Windows here

Some readings point to creating daemons or cron tasks.

I just need something simple I can call on my box's reboot, and can stop/start whenever I please. my script has an internal sleep call, and runs in "eternal loop"

thanks in advance

+2  A: 

RAA - deamons is a verfy useful tool for creating unix daemons from ruby scripts.

ennuikiller
That seems rather complicate. Could you post an example of usage? Or anything simpler?
Marcos Placona
Daemons aren't simple. There are a lot of assumptions about capabilities that the OS expects from a daemon... creating and defining those capabilities are a significant part of the complexity of Daemons.
Myrddin Emrys
A: 

I've actually found a much better way of doing that by using ruby scripts.

This is how I did it:

First of all, I installed daemon

gem install daemon

Then I did:

require 'rubygems'
require 'daemons'

pwd  = File.dirname(File.expand_path(__FILE__))
file = pwd + '/runner.rb'

Daemons.run_proc(
   'my_project', # name of daemon
   :log_output => true
 ) do
   exec "ruby #{file}"
end

I then create a file called runner.rb, in which I can call my scripts such as:

require "/var/www/rails/my_project/config/environment"
Post.send('details....')

Daemons is a great gem!

Marcos Placona