process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • José

    process

    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

  • Ryan Paul

    #2
    Re: process

    On Wed, 12 May 2004 12:33:16 +0200, José wrote:
    [color=blue]
    > 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[/color]

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

    import commands

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

    Comment

    • José

      #3
      Re: process


      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ó:
      [color=blue]
      >
      >
      >
      > I'm not aware of any way to retrieve the process list from python, but you
      > might try this:
      >
      > import commands
      >
      > x = commands.getsta tusoutput('ps ax|grep rotatelogs')[1][/color]

      Comment

      • José

        #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(messa ge)

        sock.close()

        Code from server (second request):

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

        class manejador(BaseR equestHandler):
        def handle(self):
        print "Conected Client: ", self.client_add ress
        datos = self.request.re cv(4096)
        self.request.cl ose()
        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((w eb, 6970))
        message = "adelante"
        sock.send(messa ge)
        sock.close()


        TCPServer((('', 6969)), manejador).serv e_forever()


        and this is the client server script, the last:

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

        class manejador(BaseR equestHandler):
        def handle(self):
        print "Cliente Conectado: ", self.client_add ress
        datos = self.request.re cv(4096)
        self.request.cl ose()
        archivo = isfile("./rotatelogs")
        if ( archivo == False ):
        print "success"
        else:
        print "errorrrr"


        TCPServer((('', 6970)), manejador).serv e_forever()


        Comment

        Working...