[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to daemonize a Ruby program

Iñaki Baz Castillo

6/13/2009 5:37:00 PM

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

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

Basically I run the following:

tcp_server =3D 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.

=2D-=20
I=C3=B1aki Baz Castillo <ibc@aliax.net>

5 Answers

Iñaki Baz Castillo

6/13/2009 5:55:00 PM

0

El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
> 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=20
"daemonize ruby" and got two possbile solutions :

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

=2D-=20
I=C3=B1aki Baz Castillo <ibc@aliax.net>

Iñaki Baz Castillo

6/13/2009 6:11:00 PM

0

El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
> El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=
=B3:
> > 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:

=2D--daemon1.rb----------------------
#!/usr/bin/env ruby

require 'daemons'

Daemons.daemonize

loop do
sleep 2
end
=2D-----------------------------------

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

but it's not running =C2=BF?=C2=BF?=C2=BF

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


=2D-=20
I=C3=B1aki Baz Castillo <ibc@aliax.net>

Iñaki Baz Castillo

6/13/2009 6:43:00 PM

0

El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
> El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=
=B3:
> > El S=C3=A1bado, 13 de Junio de 2009, I=C3=B1aki Baz Castillo escribi=C3=
=B3:
> > > 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 keywor=
ds
> > "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 =C2=BF?=C2=BF?=C2=BF


Ups, forget it please, it works :)

=2D-=20
I=C3=B1aki Baz Castillo <ibc@aliax.net>

Sanjay Sharma

6/13/2009 7:20:00 PM

0

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-robustt... library
for your demonic[sic] needs. :-)

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

KM

6/15/2009 2:20:00 PM

0

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.

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