creating python daemon ?

Diez B. Roggisch deets at web.de
Tue Sep 21 18:47:08 CEST 2010


vineet daniel <vineetdaniel at gmail.com> writes:

> Hi
>
> I have succesfully created daemon with python script and as next step
> I am trying to give input to that python script daemon from Apache
> Logs....here I have got stuck and I have even checked IRC python
> channel for solution. Apache is able to call the file but fails to
> execute it properly and I get this error continuosly :
>
> piped log program '/var/www/html/test.py' failed unexpectedly
>
> How do I rectify the above error and make adjustment to the code so
> that it takes input from apache.
>
> code that I am using is as follows :
>
> #! /usr/bin/env python
> import sys,os
> pid = os.fork()
> os.chdir("/var/www/html/")
> os.setsid()
> os.umask(0)
> #this line will read apache log in real time as redirected from the
> CustomLog directive of Apache.
> log = sys.stdin.readlines()
> f = open('/var/www/logmongo.txt','a') # append log to this text file
> f.write(log)
>
> I'd appreciate if anybody could share the code that they used for
> daemon or used with Apache CustomLog directive.

The above code looks errornous - you don't check for the return-value of
PID & take appropriate action. Like 

There is a daemonization recipe on active-state, which works nicely for
me.

http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/

Diez



More information about the Python-list mailing list