process

Discussion in 'Python' started by =?ISO-8859-1?Q?Jos=E9?=, May 12, 2004.

  1. 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
     
    =?ISO-8859-1?Q?Jos=E9?=, May 12, 2004
    #1
    1. Advertising

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

    Ryan Paul Guest

    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]
     
    Ryan Paul, May 12, 2004
    #2
    1. Advertising

  3. 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]
     
    =?ISO-8859-1?Q?Jos=E9?=, May 12, 2004
    #3
  4. connexion to all the servers

    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()
     
    =?ISO-8859-1?Q?Jos=E9?=, May 12, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rithesh Pai
    Replies:
    1
    Views:
    5,600
  2. walala
    Replies:
    3
    Views:
    746
    Allan Herriman
    Sep 9, 2003
  3. rtm
    Replies:
    0
    Views:
    801
  4. Jerry
    Replies:
    4
    Views:
    5,975
    Marina
    Dec 15, 2003
  5. Michael Johnson Sr.

    System.Diagnostic.Process and disfunctional process

    Michael Johnson Sr., Feb 17, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,954
    Michael Johnson Sr.
    Feb 17, 2004
Loading...

Share This Page