Daemons

Discussion in 'Ruby' started by Iain Barnett, Dec 13, 2010.

  1. Iain Barnett

    Iain Barnett Guest

    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 Barnett, Dec 13, 2010
    #1
    1. Advertising

  2. Iain Barnett

    Alex Young Guest

    Iain Barnett 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Young, Dec 13, 2010
    #2
    1. Advertising

  3. Iain Barnett

    Iain Barnett Guest

    On 13 Dec 2010, at 17:44, Alex Young wrote:

    > Iain Barnett 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
    >
    > --
    > Posted via http://www.ruby-forum.com/.



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

    Regards,
    Iain
    >
     
    Iain Barnett, Dec 13, 2010
    #3
  4. On Tue, Dec 14, 2010 at 02:21:21AM +0900, Iain Barnett 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

    --
    ========================================================================
    Jeremy Hinegardner
     
    Jeremy Hinegardner, Dec 19, 2010
    #4
  5. Iain Barnett

    Tim Pease Guest

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

    > On Tue, Dec 14, 2010 at 02:21:21AM +0900, Iain Barnett wrote:
    >> Hi,
    >>=20
    >> 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.
    >>=20
    >> Any help is much appreciated.
    >>=20
    >> Regards,
    >> Iain

    >=20
    >=20
    > Also take a look at the 'servolux' gem.
    >=20
    > http://rubygems.org/gems/servolux
    >=20



    require 'servolux'

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


    There are some example files demonstrating how to accomplish various =
    tasks:
    https://github.com/TwP/servolux/tree/master/examples

    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 :)
     
    Tim Pease, Dec 19, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. about daemons and IPC

    , Aug 27, 2006, in forum: Python
    Replies:
    4
    Views:
    324
    Irmen de Jong
    Aug 29, 2006
  2. Replies:
    2
    Views:
    442
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 13, 2006
  3. Andrey
    Replies:
    0
    Views:
    356
    Andrey
    Sep 12, 2007
  4. Steven W. Orr
    Replies:
    0
    Views:
    435
    Steven W. Orr
    Sep 14, 2007
  5. PurpleServerMonkey

    Python, Daemons and D-Bus

    PurpleServerMonkey, May 24, 2008, in forum: Python
    Replies:
    3
    Views:
    346
    Diez B. Roggisch
    May 25, 2008
Loading...

Share This Page