How to daemonize a Ruby program

Hi, I've coded a Ruby server listening in TCP and UDP. For TCP I use GServer
and for UDP an own code.

I need to daemonize it to get it working in background so I can manage the
service using a Debian init script, but I have no idea of how to do it.

Basically I run the following:

  tcp_server = GServer.new(bind_port, bind_ip)
  tcp_server.start
  tcp_server.join

So, how could I get the programm running in background?
This is, I must be able tu run the program in a terminal:
  ./my_server.rb
and leave the same terminal free to use it while the daemon is running.

Thanks a lot for any suggestion.

···

--
Iñaki Baz Castillo <ibc@aliax.net>

I had no luck on my first Google search, but I've tryed now eith keywords
"daemonize ruby" and got two possbile solutions :

1) Using "daemons" gem
2) Using "fokk" and Process.detach

···

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:

I need to daemonize it to get it working in background so I can manage the
service using a Debian init script, but I have no idea of how to do it.

--
Iñaki Baz Castillo <ibc@aliax.net>

The package 'daemon' is intended for this,
http://packages.debian.org/lenny/daemon

···

On 2009-06-13, Iñaki Baz Castillo <ibc@aliax.net> wrote:

I need to daemonize it to get it working in background so I can manage the
service using a Debian init script, but I have no idea of how to do it.

--
KM

I wonder why the following code doesn't work at all:

---daemon1.rb----------------------
#!/usr/bin/env ruby

require 'daemons'

Daemons.daemonize

loop do
  sleep 2
end

···

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:
> I need to daemonize it to get it working in background so I can manage
> the service using a Debian init script, but I have no idea of how to do
> it.

I had no luck on my first Google search, but I've tryed now eith keywords
"daemonize ruby" and got two possbile solutions :

1) Using "daemons" gem
2) Using "fokk" and Process.detach

------------------------------------

I run it (ruby daemon1.rb) and after it I check if there is any ruby process
running:
  ps -ef | grep ruby

but it's not running ¿?¿?¿

Do I miss something? The above comes in the documentaion of Daemons:
  http://daemons.rubyforge.org/

--
Iñaki Baz Castillo <ibc@aliax.net>

Iñaki Baz Castillo wrote:

···

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:

I need to daemonize it to get it working in background so I can manage the
service using a Debian init script, but I have no idea of how to do it.

I had no luck on my first Google search, but I've tryed now eith
keywords
"daemonize ruby" and got two possbile solutions :

1) Using "daemons" gem
2) Using "fokk" and Process.detach

Though I haven't personally used it, you might want to take a look at
the RobustThread <URL:
http://superjared.com/entry/ruby-daemons-using-robustthread/&gt; library
for your demonic[sic] needs. :slight_smile:

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

Ups, forget it please, it works :slight_smile:

···

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:

El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:
> El Sábado, 13 de Junio de 2009, Iñaki Baz Castillo escribió:
> > I need to daemonize it to get it working in background so I can manage
> > the service using a Debian init script, but I have no idea of how to do
> > it.
>
> I had no luck on my first Google search, but I've tryed now eith keywords
> "daemonize ruby" and got two possbile solutions :
>
> 1) Using "daemons" gem
> 2) Using "fokk" and Process.detach

I wonder why the following code doesn't work at all:

---daemon1.rb----------------------
#!/usr/bin/env ruby

require 'daemons'

Daemons.daemonize

loop do
  sleep 2
end
------------------------------------

I run it (ruby daemon1.rb) and after it I check if there is any ruby
process running:
  ps -ef | grep ruby

but it's not running ¿?¿?¿

--
Iñaki Baz Castillo <ibc@aliax.net>