By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

process

P: n/a
I have a farm with 4 web servers.
I want to write a client-server program to rotate logs.
Basically the server has only one file, if I run it, the server listens.
The client has 2 files, one client and another server.
If the log is greater than xxx bytes, then the client send a message to
the server, then the server send another message to all the webservers,
and they must to rotate logs.
I'm too new in Python and I don't know a lot of modules, so the problem
is: how can I know which processes are running?.
I writed all, but I want that the "client server" look at the processes.
In case it's rotating logs, it must pause all. In bash it could be:

#ps ax|grep rotatelogs

But how in Python?

thanks in advance

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, 12 May 2004 12:33:16 +0200, José wrote:
I have a farm with 4 web servers.
I want to write a client-server program to rotate logs.
Basically the server has only one file, if I run it, the server listens.
The client has 2 files, one client and another server.
If the log is greater than xxx bytes, then the client send a message to
the server, then the server send another message to all the webservers,
and they must to rotate logs.
I'm too new in Python and I don't know a lot of modules, so the problem
is: how can I know which processes are running?.
I writed all, but I want that the "client server" look at the processes.
In case it's rotating logs, it must pause all. In bash it could be:

#ps ax|grep rotatelogs

But how in Python?

thanks in advance


I'm not aware of any way to retrieve the process list from python, but you
might try this:

import commands

x = commands.getstatusoutput('ps ax|grep rotatelogs')[1]
Jul 18 '05 #2

P: n/a

Thank you, finally I write a pid file when rotatelogs starts, and I
delete it when it stops, then with isfile() I know if the process is
working.

Ryan Paul escribió:

I'm not aware of any way to retrieve the process list from python, but you
might try this:

import commands

x = commands.getstatusoutput('ps ax|grep rotatelogs')[1]


Jul 18 '05 #3

P: n/a

Now the problem is different.
I can do the first part, and is good, but if I try to send a message
from server to the clients, I can only send the first message, and can't
the other three.
Here I have the code.

Code from client (first request):

#!/usr/bin/env python
from socket import *
import sys
from os.path import *
from os import *
sock = socket(AF_INET,SOCK_STREAM)
sock.connect(('192.168.4.115', 6969))
tm = str(getsize("/var/log/apache2/access_log"))
message = tm

if ( tm > 50 ):
sock.send(message)

sock.close()

Code from server (second request):

#!/usr/bin/env python
from SocketServer import BaseRequestHandler, TCPServer
from socket import *
import sys

class manejador(BaseRequestHandler):
def handle(self):
print "Conected Client: ", self.client_address
datos = self.request.recv(4096)
self.request.close()
print "los datos: ", datos
while ( datos != 0 ):
a=['172.26.0.138','192.168.4.111','192.168.4.112',
'192.168.4.113','192.168.4.114']
for i in range(len(a)):
web = a[i]
sock = socket(AF_INET,SOCK_STREAM)
sock.connect((web, 6970))
message = "adelante"
sock.send(message)
sock.close()
TCPServer((('',6969)), manejador).serve_forever()
and this is the client server script, the last:

!/usr/bin/env python
from SocketServer import BaseRequestHandler, TCPServer
import sys, socket
from os.path import *
from os import *

class manejador(BaseRequestHandler):
def handle(self):
print "Cliente Conectado: ", self.client_address
datos = self.request.recv(4096)
self.request.close()
archivo = isfile("./rotatelogs")
if ( archivo == False ):
print "success"
else:
print "errorrrr"
TCPServer((('',6970)), manejador).serve_forever()
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.