Daemons

Hi,

I’ve got a process I’d like to daemonize, a call the twitter search API
ever 10 minutes or so. There seem to be a few gems that purport to make
this process easier and I was wondering if anyone could recommend (or
tell me to avoid) any? Or just any tips to watch out for.

Any help is much appreciated.

Regards,
Iain

Iain B. wrote in post #968104:

Hi,

I’ve got a process I’d like to daemonize, a call the twitter search API
ever 10 minutes or so. There seem to be a few gems that purport to make
this process easier and I was wondering if anyone could recommend (or
tell me to avoid) any? Or just any tips to watch out for.

The Daemons gem is good, but if you don’t need anything fancy then
it’s not much code to do it yourself:

# File lib/webrick/server.rb, line 28
def Daemon.start
  exit!(0) if fork
  Process::setsid
  exit!(0) if fork
  Dir::chdir("/")
  File::umask(0)
  STDIN.reopen("/dev/null")
  STDOUT.reopen("/dev/null", "w")
  STDERR.reopen("/dev/null", "w")
  yield if block_given?
end


Alex

On 13 Dec 2010, at 17:44, Alex Y. wrote:

it’s not much code to do it yourself:
STDOUT.reopen(“/dev/null”, “w”)
STDERR.reopen(“/dev/null”, “w”)
yield if block_given?
end


Alex


Posted via http://www.ruby-forum.com/.

Thanks Alex, I’ll give both that gem and the code a good look!

Regards,
Iain

On Tue, Dec 14, 2010 at 02:21:21AM +0900, Iain B. wrote:

Hi,

I’ve got a process I’d like to daemonize, a call the twitter search API ever 10
minutes or so. There seem to be a few gems that purport to make this process
easier and I was wondering if anyone could recommend (or tell me to avoid) any? Or
just any tips to watch out for.

Any help is much appreciated.

Regards,
Iain

Also take a look at the ‘servolux’ gem.

http://rubygems.org/gems/servolux

enjoy,

-jeremy

On Dec 19, 2010, at 1:18 PM, Jeremy H. wrote:

Also take a look at the ‘servolux’ gem.

servolux | RubyGems.org | your community gem host

require ‘servolux’

daemon = Servolux::Daemon.new(
:name => ‘Twitter Search’,
:pid_file => ‘/path/to/the/pid/file.pid’,
:startup_command => ‘/path/to/your/twitter/process’
)
daemon.startup

There are some example files demonstrating how to accomplish various
tasks:

And the documentation is fairly thorough:
http://rdoc.info/github/TwP/servolux/master/frames

Blessings,
TwP

PS Being the author of servolux, my opinion is completely biased :slight_smile: