Question

Using Daemons, how do I specify that my script's log goes in /log/ and its pid goes in /tmp/pids/?

I've read the docs, and I see :dir/:dir_mode, but I can only make it do one or the other, not both -- seems like a really bad set of options if you ask me.

Was it helpful?

Solution

It doesn't look like vanilla Daemons can do what you want, but it's fixable. Try something like this:

require 'rubygems'
require 'daemons'

module Daemons
  class Application
    def logfile;        '/log/f1'; end
    def output_logfile; '/log/f2'; end
  end
end

Daemons.run '/tmp/test.rb',
    :dir        => '/tmp/pids',
    :dir_mode   => :normal,
    :ontop      => false,
    :log_output => true

You probably want the logic of *logfile to act more like the originals; just scan the daemons source for def.logfile. I would also have rather patched a subclass of Application but it is instantiated by name elsewhere in module Daemons so that makes things tricky.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top