comparison roundup/scripts/roundup_server.py @ 2020:027b297ce23c

safer logging from HTTP server ([SF#896917]
author Richard Jones <richard@users.sourceforge.net>
date Sun, 15 Feb 2004 21:44:02 +0000
parents fc52d57c6c3e
children f4a16b186efc
comparison
equal deleted inserted replaced
2019:8fab5d394f22 2020:027b297ce23c
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16 # 16 #
17 17
18 """Command-line script that runs a server over roundup.cgi.client. 18 """Command-line script that runs a server over roundup.cgi.client.
19 19
20 $Id: roundup_server.py,v 1.37 2004-02-11 23:55:10 richard Exp $ 20 $Id: roundup_server.py,v 1.38 2004-02-15 21:44:02 richard Exp $
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
24 # python version check 24 # python version check
25 from roundup import version_check 25 from roundup import version_check
67 NpvNarUmk0mWZS/yr9frcrmc+iMOh+NWydPp1Ov1SiSSc344HL7fKKfTiSN2u12tVqOcxWJxn6/V 67 NpvNarUmk0mWZS/yr9frcrmc+iMOh+NWydPp1Ov1SiSSc344HL7fKKfTiSN2u12tVqOcxWJxn6/V
68 ag0GAwxkrlKp5vP5fT7ulMlk6XRar9dLpVIUXi6Xb5Hxa1wul0ajKZVKsVjM7XYXCoVOp3OVPJvN 68 ag0GAwxkrlKp5vP5fT7ulMlk6XRar9dLpVIUXi6Xb5Hxa1wul0ajKZVKsVjM7XYXCoVOp3OVPJvN
69 AoFAtVo1m825XO7hSODOYrH4kHbxxGAwwODBGI/H6DBs5LNara7yl8slGjIcDsHpdrunU6PRCAP2 69 AoFAtVo1m825XO7hSODOYrH4kHbxxGAwwODBGI/H6DBs5LNara7yl8slGjIcDsHpdrunU6PRCAP2
70 r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo 70 r3fPdUcIYeyEfLSAJ0LeAUZHCAt8Al/8/kLIEWDB5YDj0wm8fAP6fVfo
71 '''.strip())) 71 '''.strip()))
72
73 class RoundupHTTPServer(SafeLogging, BaseHTTPServer.HTTPServer):
74 def log_message(self, format, *args):
75 ''' Try to use the logging package, otherwise *safely* log to
76 stderr.
77 '''
78 try:
79 BaseHTTPServer.HTTPServer.log_message(self, format, *args)
80 except IOError:
81 # stderr is no longer viable, we can't log
82 pass
72 83
73 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 84 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
74 TRACKER_HOMES = TRACKER_HOMES 85 TRACKER_HOMES = TRACKER_HOMES
75 ROUNDUP_USER = ROUNDUP_USER 86 ROUNDUP_USER = ROUNDUP_USER
76 87
227 from win32event import * 238 from win32event import *
228 from win32file import * 239 from win32file import *
229 240
230 SvcShutdown = "ServiceShutdown" 241 SvcShutdown = "ServiceShutdown"
231 242
232 class RoundupService(win32serviceutil.ServiceFramework, 243 class RoundupService(win32serviceutil.ServiceFramework, RoundupHTTPServer):
233 BaseHTTPServer.HTTPServer):
234 ''' A Roundup standalone server for Win32 by Ewout Prangsma 244 ''' A Roundup standalone server for Win32 by Ewout Prangsma
235 ''' 245 '''
236 _svc_name_ = "Roundup Bug Tracker" 246 _svc_name_ = "Roundup Bug Tracker"
237 _svc_display_name_ = "Roundup Bug Tracker" 247 _svc_display_name_ = "Roundup Bug Tracker"
238 address = (HOSTNAME, PORT) 248 address = (HOSTNAME, PORT)
240 # redirect stdout/stderr to our logfile 250 # redirect stdout/stderr to our logfile
241 if LOGFILE: 251 if LOGFILE:
242 # appending, unbuffered 252 # appending, unbuffered
243 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0) 253 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0)
244 win32serviceutil.ServiceFramework.__init__(self, args) 254 win32serviceutil.ServiceFramework.__init__(self, args)
245 BaseHTTPServer.HTTPServer.__init__(self, self.address, 255 RoundupHTTPServer.__init__(self, self.address,
246 RoundupRequestHandler) 256 RoundupRequestHandler)
247 257
248 # Create the necessary NT Event synchronization objects... 258 # Create the necessary NT Event synchronization objects...
249 # hevSvcStop is signaled when the SCM sends us a notification 259 # hevSvcStop is signaled when the SCM sends us a notification
250 # to shutdown the service. 260 # to shutdown the service.
433 443
434 # obtain server before changing user id - allows to use port < 444 # obtain server before changing user id - allows to use port <
435 # 1024 if started as root 445 # 1024 if started as root
436 address = (hostname, port) 446 address = (hostname, port)
437 try: 447 try:
438 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) 448 httpd = RoundupHTTPServer(address, RoundupRequestHandler)
439 except socket.error, e: 449 except socket.error, e:
440 if e[0] == errno.EADDRINUSE: 450 if e[0] == errno.EADDRINUSE:
441 raise socket.error, \ 451 raise socket.error, \
442 _("Unable to bind to port %s, port already in use." % port) 452 _("Unable to bind to port %s, port already in use." % port)
443 raise 453 raise

Roundup Issue Tracker: http://roundup-tracker.org/