Re: daemonizing a command
On 05/27/2010 02:52 PM, Israel Garcia wrote:
Hi,
I need to daemonize this command on a debian lenny?
ruby apd.rb
It's a simple app for my network.
I was thinking to use nohup ruby app.rb& at rc.local, but I want to
know if there's other ways to do it.
Using Python, I create a module named daemonize and then at the
beginning of any program I want to run as a daemon, I do:
import daemonize
daemonize.daemonize()
Maybe you can convert this code to Ruby...
# Daemon Module - basic facilities for becoming a daemon process
# written by Coy Krill (ckrill@qvlinc.com)
#
# Combines ideas from Steinar Knutsens daemonize.py and
# Jeff Kunces demonize.py
"""Facilities for Creating Python Daemons"""
import os
import time
import sys
class NullDevice:
def write(self, s):
pass
def daemonize():
if (not os.fork()):
# get our own session and fixup std[in,out,err]
os.setsid()
sys.stdin.close()
sys.stdout = NullDevice()
sys.stderr = NullDevice()
if (not os.fork()):
# hang around till adopted by init
ppid = os.getppid()
while (ppid != 1):
time.sleep(0.5)
ppid = os.getppid()
else:
# time for child to die
os._exit(0)
else:
# wait for child to die and then bail
os.wait()
sys.exit()
--
Dissent is patriotic, remember?
Reply to: