r20262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20261‎ | r20262 | r20263 >
Date:19:51, 8 March 2007
Author:Mark Bergsma
Status:old
Tags:
Comment:
Support HUP signal for cycling logs
Modified paths:
  • /trunk/pybal/pybal/pybal.py (modified) (history)
  • /trunk/pybal/pybal/util.py (modified) (history)

Diff [purge]

Index: trunk/pybal/pybal/util.py
@@ -9,8 +9,10 @@
1010
1111 class LogFile(object):
1212 def __init__(self, filename):
 13+ self.filename = filename
 14+ self.lineEnded = True
 15+
1316 self.file = file(filename, 'a')
14 - self.lineEnded = True
1517
1618 def write(self, s):
1719 """
@@ -26,3 +28,12 @@
2729 self.lineEnded = line.endswith('\n')
2830
2931 self.file.flush()
 32+
 33+ def reopen(self):
 34+ """
 35+ Close the logfile and reopen it. Useful for log rotation.
 36+ """
 37+
 38+ self.file.close()
 39+ self.file = file(self.filename, 'a')
 40+ self.lineEnded = True
Index: trunk/pybal/pybal/pybal.py
@@ -366,7 +366,7 @@
367367
368368 # When the first child terminates, all processes in the second child
369369 # are sent a SIGHUP, so it's ignored.
370 - signal.signal( signal.SIGHUP, signal.SIG_IGN )
 370+ #signal.signal( signal.SIGHUP, signal.SIG_IGN )
371371
372372 try:
373373 # Fork a second child to prevent zombies. Since the first child is
@@ -397,11 +397,11 @@
398398 except ( AttributeError, ValueError ):
399399 maxfd = 256 # default maximum
400400
401 - for fd in range( 0, maxfd ):
402 - try:
403 - os.close( fd )
404 - except OSError: # ERROR (ignore)
405 - pass
 401+ #for fd in range( 0, maxfd ):
 402+ # try:
 403+ # os.close( fd )
 404+ # except OSError: # ERROR (ignore)
 405+ # pass
406406
407407 # Redirect the standard file descriptors to /dev/null.
408408 os.open( "/dev/null", os.O_RDONLY ) # standard input (0)
@@ -441,13 +441,22 @@
442442
443443 if signum == signal.SIGTERM:
444444 terminate()
 445+ elif signum == signal.SIGHUP:
 446+ # Cycle logfiles
 447+ from util import LogFile
 448+ if isinstance(sys.stdout, LogFile):
 449+ print "Cycling log file..."
 450+ sys.stdout.reopen()
445451
446452 def installSignalHandlers():
447453 """
448454 Installs Unix signal handlers, e.g. to run terminate() on TERM
449455 """
450456
451 - signal.signal(signal.SIGTERM, sighandler)
 457+ signals = [signal.SIGTERM, signal.SIGHUP]
 458+
 459+ for sig in signals:
 460+ signal.signal(sig, sighandler)
452461
453462 def main():
454463 from twisted.internet import reactor
@@ -476,12 +485,12 @@
477486 from util import LogFile
478487 try:
479488 logfile = '/var/log/pybal.log'
480 - sys.stdout = LogFile(logfile)
 489+ sys.stdout = sys.stderr = LogFile(logfile)
481490 except:
482491 print "Unable to open logfile %s, using stdout" % logfile
483492
484493 # Install signal handlers
485 - installSignalHandlers
 494+ installSignalHandlers()
486495
487496 for section in config.sections():
488497 cfgtuple = (

Follow-up revisions

RevisionCommit summaryAuthorDate
r22993pybal (0.1+r20262-2) feisty; urgency=low...mark19:56, 14 June 2007