How to daemonize a Ruby program

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

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 <[email protected]>
 
I

Iñaki Baz Castillo

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 <[email protected]>
 
I

Iñaki Baz Castillo

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 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.rubyforge.org/


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
I

Iñaki Baz Castillo

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 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 <[email protected]>
 
S

Sanjay Sharma

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

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top