creating python daemon ?

Stefan Schwarzer sschwarzer at
Sun Sep 26 11:20:18 CEST 2010

Hi Daniel,

On 2010-09-23 07:30, vineet daniel wrote:
> On Sep 22, 2:20 pm, de... at (Diez B. Roggisch) wrote:
>> vineet daniel <vineetdan... at> writes:
>>> On Sep 21, 9:47 pm, de... at (Diez B. Roggisch) wrote:
>>>> vineet daniel <vineetdan... at> writes:
>>>>> 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 guess you'll need some loop to process the input from

> There is a directive in Apache - CustomLog which can redirect logs to
> a script or another file by using Pipe. I googled about it and came to
> know that this works flawlessly with Perl as Apache treats Perl
> scripts as daemon, for Python to take input from Apache, it needs to
> work as daemon. Apache will then push its logs lines to this daemon as
> input. Perl takes this input as <stdin> but python's stdin is not
> working as expected it just takes the file name as given in CustomLog
> directive using Pipe i.e if I use CustomLog '|/var/wwww/'

Are the _four_ ws intentional?

> combined, what script reads is just the file name, how and why I am
> not able to figure it out. And thats the reason I am here. I hope
> you've got what I am trying to do.

Do you have a line for the interpreter at the top of your
script, like


Is the script executable (e. g. chmod +x


More information about the Python-list mailing list