process

  • Thread starter =?ISO-8859-1?Q?Jos=E9?=
  • Start date
?

=?ISO-8859-1?Q?Jos=E9?=

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
 
R

Ryan Paul

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]
 
?

=?ISO-8859-1?Q?Jos=E9?=

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ó:
 
?

=?ISO-8859-1?Q?Jos=E9?=

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
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()
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top