creating python daemon ?

V

vineet daniel

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.
 
D

Diez B. Roggisch

vineet daniel said:
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
 
V

vineet daniel

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-pyth...

Diez

Hi Diez

Thanks for pointing that out.
Ever tried giving input to such python daemons from a dynamic source
like Apache logs which get generated in real time. I want apache to
directly write to this python daemon which in turn will process the
logs the way I want. Any help will help me immensely.
 
D

Diez B. Roggisch

vineet daniel said:
Hi Diez

Thanks for pointing that out.
Ever tried giving input to such python daemons from a dynamic source
like Apache logs which get generated in real time. I want apache to
directly write to this python daemon which in turn will process the
logs the way I want. Any help will help me immensely.

I don't understand the question. How is that input produced? How shall
the two processes interact? Through some logfile one writes, the other
reads? Through RPC-mechanisms? Sockets? Pipes?

The fact that process B is a daemon or not has nothing to do with this
whatsoever, btw.

Diez
 
V

vineet daniel

I don't understand the question. How is that input produced? How shall
the two processes interact? Through some logfile one writes, the other
reads? Through RPC-mechanisms? Sockets? Pipes?

The fact that process B is a daemon or not has nothing to do with this
whatsoever, btw.

Diez

Hi Diez

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'
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.
 
S

Stefan Schwarzer

Hi Daniel,


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
 
V

vineet daniel

Hi Daniel,



I guess you'll need some loop to process the input from
Apache.


Are the _four_ ws intentional?


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.
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top