Changeset 56:911c57416443 in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
12/23/08 14:28:44 (10 years ago)
Author:
Nikolas Tautenhahn <nik@…>
Branch:
default
Message:

added sighandlers for sender in case apache kills its piped logger

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh_sender.py

    r55 r56  
    4444        self.last_check_connection = datetime.datetime.now() 
    4545        signal.signal(signal.SIGALRM, self.timeout) 
     46        signal.signal(signal.SIGHUP, self.sighandler) 
     47        signal.signal(signal.SIGTERM, self.sighandler) 
     48        signal.signal(signal.SIGINT, self.sighandler) 
     49        signal.signal(signal.SIGQUIT, self.sighandler) 
    4650 
    4751    def readlines(self): 
     
    9296                self.s = None 
    9397                self.last_check_connection = self.startedbuffering = datetime.datetime.now() 
    94                 sys.stderr.write("%s (%s): Socket connection lost, starting to log to buffer and/or recovery file" % (self.progname, self.startedbuffering.isoformat())) 
     98                sys.stderr.write("%s (%s): Socket connection lost, starting to log to buffer and/or recovery file\n" % (self.progname, self.startedbuffering.isoformat())) 
    9599                self.send_tempfile(line) 
    96100            signal.alarm(0) 
     
    142146                            self.buffer = self.buffer[i:] # and the content which was transmitted to the server in time 
    143147                            return 
    144                     sys.stderr.write("%s (%s): Socket connection established again, all data could be sent to the server" % (self.progname, self.last_check_connection.isoformat())) 
     148                    sys.stderr.write("%s (%s): Socket connection established again, all data could be sent to the server\n" % (self.progname, self.last_check_connection.isoformat())) 
    145149                    self.buffer = [] # if we arrive here everything was sent successfully 
    146150 
     
    199203            raise 
    200204 
     205    def sighandler(self, signum, frame): 
     206        self.flush_buffer() 
     207        if signum in (signal.SIGQUIT, signal.SIGTERM, signal.SIGINT): 
     208            sys.exit(signum) 
     209 
     210 
    201211def main(args=None): 
    202212    import optparse 
     
    210220        sys.stderr.flush() 
    211221        return 1 
    212     S = Sender(args[0], intify(args[1], None), intify(options.buffertime, 0), options.backuppath, p.get_prog_name()) 
     222    S = Sender(args[0], intify(args[1], None), intify(options.buffertime, 0), options.backuppath, sys.stdin, p.get_prog_name()) 
    213223    S.send() 
    214224