Skip to content

Commit b791ed5

Browse files
author
Richard Jones
committed
fix Windows service mode for roundup-server [SF#819890]
1 parent c46b450 commit b791ed5

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ are given with the most recent entry first.
44
2003-??-?? 0.6.4
55
Fixed:
66
- hard-coded python2.3-ism (socket.timeout) fixed
7-
- Fixed activity displaying as future because of Date arithmetic fix in 0.6.3
7+
- fixed activity displaying as future because of Date arithmetic fix in 0.6.3
88
(sf bug 842027).
9+
- fix Windows service mode for roundup-server (sf bug 819890)
910

1011

1112
2003-11-14 0.6.3

roundup/scripts/roundup_server.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
""" HTTP Server that serves roundup.
1818
19-
$Id: roundup_server.py,v 1.26.2.3 2003-12-04 02:39:04 richard Exp $
19+
$Id: roundup_server.py,v 1.26.2.4 2003-12-04 22:53:54 richard Exp $
2020
"""
2121

2222
# python version check
@@ -44,6 +44,12 @@
4444
}
4545

4646
ROUNDUP_USER = None
47+
ROUNDUP_GROUP = None
48+
ROUNDUP_LOG_IP = 1
49+
HOSTNAME = ''
50+
PORT = 8080
51+
PIDFILE = None
52+
LOGFILE = None
4753

4854

4955
#
@@ -201,7 +207,7 @@ def inner_run_cgi(self):
201207
c = tracker.Client(tracker, self, env)
202208
c.main()
203209

204-
LOG_IPADDRESS = 1
210+
LOG_IPADDRESS = ROUNDUP_LOG_IP
205211
def address_string(self):
206212
if self.LOG_IPADDRESS:
207213
return self.client_address[0]
@@ -228,8 +234,12 @@ class RoundupService(win32serviceutil.ServiceFramework,
228234
'''
229235
_svc_name_ = "Roundup Bug Tracker"
230236
_svc_display_name_ = "Roundup Bug Tracker"
231-
address = ('', 8888)
237+
address = (HOSTNAME, PORT)
232238
def __init__(self, args):
239+
# redirect stdout/stderr to our logfile
240+
if LOGFILE:
241+
# appending, unbuffered
242+
sys.stdout = sys.stderr = open(LOGFILE, 'a', 0)
233243
win32serviceutil.ServiceFramework.__init__(self, args)
234244
BaseHTTPServer.HTTPServer.__init__(self, self.address,
235245
RoundupRequestHandler)
@@ -304,6 +314,15 @@ def get_request(self):
304314
def usage(message=''):
305315
if message:
306316
message = _('Error: %(error)s\n\n')%{'error': message}
317+
if RoundupService:
318+
win = ''' -c: Windows Service options. If you want to run the server as a Windows
319+
Service, you must configure the rest of the options by changing the
320+
constants of this program. You will at least configure one tracker
321+
in the TRACKER_HOMES variable. This option is mutually exclusive
322+
from the rest. Typing "roundup-server -c help" shows Windows
323+
Services specifics.'''
324+
else:
325+
win = ''
307326
print _('''%(message)sUsage:
308327
roundup-server [options] [name=tracker home]*
309328
@@ -312,10 +331,11 @@ def usage(message=''):
312331
-p: sets the port to listen on
313332
-l: sets a filename to log to (instead of stdout)
314333
-d: run the server in the background and on UN*X write the server's PID
315-
to the nominated file. Note: on Windows the PID argument is needed,
316-
but ignored. The -l option *must* be specified if this option is.
334+
to the nominated file. The -l option *must* be specified if this
335+
option is.
317336
-N: log client machine names in access log instead of IP addresses (much
318337
slower)
338+
%(win)s
319339
320340
name=tracker home:
321341
Sets the tracker home(s) to use. The name is how the tracker is
@@ -381,18 +401,27 @@ def run():
381401
if hasattr(socket, 'setdefaulttimeout'):
382402
socket.setdefaulttimeout(60)
383403

384-
hostname = ''
385-
port = 8080
386-
pidfile = None
387-
logfile = None
404+
hostname = HOSTNAME
405+
port = PORT
406+
pidfile = PIDFILE
407+
logfile = LOGFILE
408+
user = ROUNDUP_USER
409+
group = ROUNDUP_GROUP
410+
svc_args = None
411+
388412
try:
389413
# handle the command-line args
414+
options = 'n:p:u:d:l:hN'
415+
if RoundupService:
416+
options += 'c'
417+
390418
try:
391-
optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:d:l:hN')
419+
optlist, args = getopt.getopt(sys.argv[1:], options)
392420
except getopt.GetoptError, e:
393421
usage(str(e))
394422

395423
user = ROUNDUP_USER
424+
group = None
396425
for (opt, arg) in optlist:
397426
if opt == '-n': hostname = arg
398427
elif opt == '-p': port = int(arg)
@@ -401,6 +430,10 @@ def run():
401430
elif opt == '-l': logfile = abspath(arg)
402431
elif opt == '-h': usage()
403432
elif opt == '-N': RoundupRequestHandler.LOG_IPADDRESS = 0
433+
elif opt == '-c': svc_args = [opt] + args; args = None
434+
435+
if svc_args is not None and len(optlist) > 1:
436+
raise ValueError, _("windows service option must be the only one")
404437

405438
if pidfile and not logfile:
406439
raise ValueError, _("logfile *must* be specified if pidfile is")
@@ -428,7 +461,7 @@ def run():
428461
if args:
429462
d = {}
430463
for arg in args:
431-
try:
464+
try:
432465
name, home = arg.split('=')
433466
except ValueError:
434467
raise ValueError, _("Instances must be name=home")
@@ -446,17 +479,17 @@ def run():
446479

447480
# fork?
448481
if pidfile:
449-
if RoundupService:
450-
# don't do any other stuff
451-
RoundupService.address = address
452-
return win32serviceutil.HandleCommandLine(RoundupService)
453-
elif not hasattr(os, 'fork'):
482+
if not hasattr(os, 'fork'):
454483
print "Sorry, you can't run the server as a daemon on this" \
455484
'Operating System'
456485
sys.exit(0)
457486
else:
458487
daemonize(pidfile)
459488

489+
if svc_args is not None:
490+
# don't do any other stuff
491+
return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args)
492+
460493
# redirect stdout/stderr to our logfile
461494
if logfile:
462495
# appending, unbuffered

0 commit comments

Comments
 (0)