creating python daemon ?

vineet daniel vineetdaniel at gmail.com
Sun Sep 26 20:50:09 CEST 2010


On Sep 26, 2:20 pm, Stefan Schwarzer <sschwar... at sschwarzer.net>
wrote:
> Hi Daniel,
>
> On 2010-09-23 07:30, vineet daniel wrote:
>
>
>
> > On Sep 22, 2:20 pm, de... at web.de (Diez B. Roggisch) wrote:
> >> vineet daniel <vineetdan... at gmail.com> writes:
> >>> On Sep 21, 9:47 pm, de... at web.de (Diez B. Roggisch) wrote:
> >>>> vineet daniel <vineetdan... at gmail.com> 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
> Apache.
>
> > 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/script.py'
>
> 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
>
> #!/usr/bin/python
>
> Is the script executable (e. g. chmod +x script.py)?
>
> Stefan

Hi Stefan

The four w's is a typo error its just 'www' and using #!/usr/bin/env
python.........yes script is executable.




More information about the Python-list mailing list