I had to hack in the ability to rotate the log files while the Appserver was still running, to avoid downtime.
This works nicely with newsyslog on BSD systems.
It isn't pretty, or ideal, but at least it works. Hopefully this will seed the idea of working this feature into WebWare in a future release so that I don't have to patch it on my side.
The patch for ThreadedAppServer.py also includes a fix for BSD systems regarding opening the socket with appropriate flags set.
--- WebKit/ThreadedAppServer.py.orig Sun Jan 25 06:17:38 2009
+++ WebKit/ThreadedAppServer.py Wed Jul 8 13:10:30 2009
<at> <at> -271,6 +271,19 <at> <at>
try:
sock.bind(serverAddress)
sock.listen(1024)
+ try:
+ import fcntl
+ fd = sock.fileno()
+ flags = fcntl.fcntl(fd, fcntl.F_GETFD)
+ try:
+ flags |= fcntl.FD_CLOEXEC
+ except AttributeError, e:
+ # Python 2.2 does not include FD_CLOEXEC
+ flags |= 1
+ fcntl.fcntl(fd, fcntl.F_SETFD, flags)
+ except ImportError, e:
+ # Platform does not have fcntl module
+ pass
except Exception:
print "Error: Can not listen for %s on %s" % (
handlerClass.settingPrefix, str(serverAddress))
<at> <at> -1310,7 +1323,11 <at> <at>
print "App server has been signaled to shutdown."
if server and server._running > 2:
print "Shutting down at", asclocaltime()
+ global logtuple
+ log, stdout, stderr = logtuple
sys.stdout.flush()
+ sys.stdout, sys.stderr = stdout, stderr
+ log.close()
server._running = 2
if signum == SIGINT:
raise KeyboardInterrupt
<at> <at> -1321,6 +1338,34 <at> <at>
else:
print "No running app server was found."
+def rotateLogs(signum, frame):
+ print
+ print "App server has been signaled to rotate logs."
+ if server and server._running > 2:
+ print "Rotating logs at", asclocaltime()
+ logFile = server.serverSidePath(server.application().setting('ErrorLogFilename'))
+ # attempt to close logs
+ global logtuple
+ log, stdout, stderr = logtuple
+ if log:
+ sys.stdout, sys.stderr = stdout, stderr
+ log.close()
+
+ try:
+ log = open(logFile, 'a', 1) # append, line buffered mode
+ print 'Output has been redirected to %r...' % logFile
+ stdout, stderr = sys.stdout, sys.stderr
+ sys.stdout = sys.stderr = log
+ logtuple = (log, stdout, stderr)
+ except IOError, error:
+ print 'Cannot redirect output to %r.' % logFile
+ print error.strerror
+ log = None
+ sys.exit(1)
+ else:
+ print "No running app server was found."
+
+
try:
# Use the threadframe module for dumping thread stack frames:
# http://www.majid.info/mylos/stories/2004/06/10/threadframe.html
<at> <at> -1371,6 +1416,11 <at> <at>
signal.signal(SIGINT, shutDown)
except AttributeError:
SIGINT = None
+try:
+ SIGUSR1 = signal.SIGUSR1
+ signal.signal(SIGUSR1, rotateLogs)
+except AttributeError:
+ SIGUSR1 = None
if threadDump:
<at> <at> -1392,6 +1442,7 <at> <at>
import re
settingRE = re.compile(r'^(?:--)?([a-zA-Z][a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z0-9]*)=')
from MiscUtils import Configurable
+import types
usage = re.search('\n.* arguments:\n\n(.*\n)*?\n', __doc__).group(0)
<at> <at> -1405,8 +1456,12 <at> <at>
function = run
daemon = False
workDir = None
+ global logtuple
+ logtuple = None
for a in args[:]:
- if settingRE.match(a):
+ if isinstance(a, types.TupleType):
+ logtuple = a
+ elif settingRE.match(a):
match = settingRE.match(a)
name = match.group(1)
value = a[match.end():]
--- WebKit/Launch.py.orig Sun Jan 25 06:17:38 2009
+++ WebKit/Launch.py Wed Jul 8 13:10:30 2009
<at> <at> -431,6 +431,8 <at> <at>
print 'WARNING: Applications run much slower when profiled,'
print 'so turn off profiling in Launch.py when you are finished.'
else:
+ if log is not None:
+ args[2].append((log, stdout, stderr))
errorlevel = launchWebKit(*args)
finally:
print
Regards,
Justin Akehurst
Software Development Engineer II, UI
Main: (206) 315-7500 Fax: (206) 315-7501
Direct: (206) 315-7576 Mobile: (206) 790-4736
Twitter | Blog | Web | YouTube
Simple is Smart™