Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 1940:5add2b83cfa3 maint-0.6
fix Windows service mode for roundup-server [SF#819890]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 04 Dec 2003 22:53:54 +0000 |
| parents | 4cd5adcc1e87 |
| children | 2fe25413867f |
comparison
equal
deleted
inserted
replaced
| 1938:4cd5adcc1e87 | 1940:5add2b83cfa3 |
|---|---|
| 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 16 # | 16 # |
| 17 """ HTTP Server that serves roundup. | 17 """ HTTP Server that serves roundup. |
| 18 | 18 |
| 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 $ |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 # python version check | 22 # python version check |
| 23 from roundup import version_check | 23 from roundup import version_check |
| 24 | 24 |
| 42 TRACKER_HOMES = { | 42 TRACKER_HOMES = { |
| 43 # 'example': '/path/to/example', | 43 # 'example': '/path/to/example', |
| 44 } | 44 } |
| 45 | 45 |
| 46 ROUNDUP_USER = None | 46 ROUNDUP_USER = None |
| 47 ROUNDUP_GROUP = None | |
| 48 ROUNDUP_LOG_IP = 1 | |
| 49 HOSTNAME = '' | |
| 50 PORT = 8080 | |
| 51 PIDFILE = None | |
| 52 LOGFILE = None | |
| 47 | 53 |
| 48 | 54 |
| 49 # | 55 # |
| 50 ## end configuration | 56 ## end configuration |
| 51 # | 57 # |
| 199 | 205 |
| 200 # do the roundup thang | 206 # do the roundup thang |
| 201 c = tracker.Client(tracker, self, env) | 207 c = tracker.Client(tracker, self, env) |
| 202 c.main() | 208 c.main() |
| 203 | 209 |
| 204 LOG_IPADDRESS = 1 | 210 LOG_IPADDRESS = ROUNDUP_LOG_IP |
| 205 def address_string(self): | 211 def address_string(self): |
| 206 if self.LOG_IPADDRESS: | 212 if self.LOG_IPADDRESS: |
| 207 return self.client_address[0] | 213 return self.client_address[0] |
| 208 else: | 214 else: |
| 209 host, port = self.client_address | 215 host, port = self.client_address |
| 226 BaseHTTPServer.HTTPServer): | 232 BaseHTTPServer.HTTPServer): |
| 227 ''' A Roundup standalone server for Win32 by Ewout Prangsma | 233 ''' A Roundup standalone server for Win32 by Ewout Prangsma |
| 228 ''' | 234 ''' |
| 229 _svc_name_ = "Roundup Bug Tracker" | 235 _svc_name_ = "Roundup Bug Tracker" |
| 230 _svc_display_name_ = "Roundup Bug Tracker" | 236 _svc_display_name_ = "Roundup Bug Tracker" |
| 231 address = ('', 8888) | 237 address = (HOSTNAME, PORT) |
| 232 def __init__(self, args): | 238 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) | |
| 233 win32serviceutil.ServiceFramework.__init__(self, args) | 243 win32serviceutil.ServiceFramework.__init__(self, args) |
| 234 BaseHTTPServer.HTTPServer.__init__(self, self.address, | 244 BaseHTTPServer.HTTPServer.__init__(self, self.address, |
| 235 RoundupRequestHandler) | 245 RoundupRequestHandler) |
| 236 | 246 |
| 237 # Create the necessary NT Event synchronization objects... | 247 # Create the necessary NT Event synchronization objects... |
| 302 | 312 |
| 303 | 313 |
| 304 def usage(message=''): | 314 def usage(message=''): |
| 305 if message: | 315 if message: |
| 306 message = _('Error: %(error)s\n\n')%{'error': message} | 316 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 = '' | |
| 307 print _('''%(message)sUsage: | 326 print _('''%(message)sUsage: |
| 308 roundup-server [options] [name=tracker home]* | 327 roundup-server [options] [name=tracker home]* |
| 309 | 328 |
| 310 options: | 329 options: |
| 311 -n: sets the host name | 330 -n: sets the host name |
| 312 -p: sets the port to listen on | 331 -p: sets the port to listen on |
| 313 -l: sets a filename to log to (instead of stdout) | 332 -l: sets a filename to log to (instead of stdout) |
| 314 -d: run the server in the background and on UN*X write the server's PID | 333 -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, | 334 to the nominated file. The -l option *must* be specified if this |
| 316 but ignored. The -l option *must* be specified if this option is. | 335 option is. |
| 317 -N: log client machine names in access log instead of IP addresses (much | 336 -N: log client machine names in access log instead of IP addresses (much |
| 318 slower) | 337 slower) |
| 338 %(win)s | |
| 319 | 339 |
| 320 name=tracker home: | 340 name=tracker home: |
| 321 Sets the tracker home(s) to use. The name is how the tracker is | 341 Sets the tracker home(s) to use. The name is how the tracker is |
| 322 identified in the URL (it's the first part of the URL path). The | 342 identified in the URL (it's the first part of the URL path). The |
| 323 tracker home is the directory that was identified when you did | 343 tracker home is the directory that was identified when you did |
| 379 # time out after a minute if we can | 399 # time out after a minute if we can |
| 380 import socket | 400 import socket |
| 381 if hasattr(socket, 'setdefaulttimeout'): | 401 if hasattr(socket, 'setdefaulttimeout'): |
| 382 socket.setdefaulttimeout(60) | 402 socket.setdefaulttimeout(60) |
| 383 | 403 |
| 384 hostname = '' | 404 hostname = HOSTNAME |
| 385 port = 8080 | 405 port = PORT |
| 386 pidfile = None | 406 pidfile = PIDFILE |
| 387 logfile = None | 407 logfile = LOGFILE |
| 408 user = ROUNDUP_USER | |
| 409 group = ROUNDUP_GROUP | |
| 410 svc_args = None | |
| 411 | |
| 388 try: | 412 try: |
| 389 # handle the command-line args | 413 # handle the command-line args |
| 414 options = 'n:p:u:d:l:hN' | |
| 415 if RoundupService: | |
| 416 options += 'c' | |
| 417 | |
| 390 try: | 418 try: |
| 391 optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:d:l:hN') | 419 optlist, args = getopt.getopt(sys.argv[1:], options) |
| 392 except getopt.GetoptError, e: | 420 except getopt.GetoptError, e: |
| 393 usage(str(e)) | 421 usage(str(e)) |
| 394 | 422 |
| 395 user = ROUNDUP_USER | 423 user = ROUNDUP_USER |
| 424 group = None | |
| 396 for (opt, arg) in optlist: | 425 for (opt, arg) in optlist: |
| 397 if opt == '-n': hostname = arg | 426 if opt == '-n': hostname = arg |
| 398 elif opt == '-p': port = int(arg) | 427 elif opt == '-p': port = int(arg) |
| 399 elif opt == '-u': user = arg | 428 elif opt == '-u': user = arg |
| 400 elif opt == '-d': pidfile = abspath(arg) | 429 elif opt == '-d': pidfile = abspath(arg) |
| 401 elif opt == '-l': logfile = abspath(arg) | 430 elif opt == '-l': logfile = abspath(arg) |
| 402 elif opt == '-h': usage() | 431 elif opt == '-h': usage() |
| 403 elif opt == '-N': RoundupRequestHandler.LOG_IPADDRESS = 0 | 432 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") | |
| 404 | 437 |
| 405 if pidfile and not logfile: | 438 if pidfile and not logfile: |
| 406 raise ValueError, _("logfile *must* be specified if pidfile is") | 439 raise ValueError, _("logfile *must* be specified if pidfile is") |
| 407 | 440 |
| 408 if hasattr(os, 'getuid'): | 441 if hasattr(os, 'getuid'): |
| 426 | 459 |
| 427 # handle tracker specs | 460 # handle tracker specs |
| 428 if args: | 461 if args: |
| 429 d = {} | 462 d = {} |
| 430 for arg in args: | 463 for arg in args: |
| 431 try: | 464 try: |
| 432 name, home = arg.split('=') | 465 name, home = arg.split('=') |
| 433 except ValueError: | 466 except ValueError: |
| 434 raise ValueError, _("Instances must be name=home") | 467 raise ValueError, _("Instances must be name=home") |
| 435 d[name] = home | 468 d[name] = home |
| 436 RoundupRequestHandler.TRACKER_HOMES = d | 469 RoundupRequestHandler.TRACKER_HOMES = d |
| 444 sys.argv = sys.argv[:1] | 477 sys.argv = sys.argv[:1] |
| 445 address = (hostname, port) | 478 address = (hostname, port) |
| 446 | 479 |
| 447 # fork? | 480 # fork? |
| 448 if pidfile: | 481 if pidfile: |
| 449 if RoundupService: | 482 if not hasattr(os, 'fork'): |
| 450 # don't do any other stuff | |
| 451 RoundupService.address = address | |
| 452 return win32serviceutil.HandleCommandLine(RoundupService) | |
| 453 elif not hasattr(os, 'fork'): | |
| 454 print "Sorry, you can't run the server as a daemon on this" \ | 483 print "Sorry, you can't run the server as a daemon on this" \ |
| 455 'Operating System' | 484 'Operating System' |
| 456 sys.exit(0) | 485 sys.exit(0) |
| 457 else: | 486 else: |
| 458 daemonize(pidfile) | 487 daemonize(pidfile) |
| 488 | |
| 489 if svc_args is not None: | |
| 490 # don't do any other stuff | |
| 491 return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args) | |
| 459 | 492 |
| 460 # redirect stdout/stderr to our logfile | 493 # redirect stdout/stderr to our logfile |
| 461 if logfile: | 494 if logfile: |
| 462 # appending, unbuffered | 495 # appending, unbuffered |
| 463 sys.stdout = sys.stderr = open(logfile, 'a', 0) | 496 sys.stdout = sys.stderr = open(logfile, 'a', 0) |
