comparison roundup/scripts/roundup_server.py @ 2637:11811b313459

The demo.py script works again using the new configuration system.
author Richard Jones <richard@users.sourceforge.net>
date Tue, 27 Jul 2004 01:59:28 +0000
parents a9e1fff1e793
children 18a23afb1f89
comparison
equal deleted inserted replaced
2636:943f9d4592b8 2637:11811b313459
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.58 2004-07-27 00:57:18 richard Exp $ 20 $Id: roundup_server.py,v 1.59 2004-07-27 01:59:28 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
51 NMrs7CwHBwdotVoSiQRXXPG/IzY7RHtt922xjFRb01H1XhKfPBNbi/7my7rrLXJ88eppvxwEfV3f 51 NMrs7CwHBwdotVoSiQRXXPG/IzY7RHtt922xjFRb01H1XhKfPBNbi/7my7rrLXJ88eppvxwEfV3f
52 NY3Y6exofVdsV3+2wnPFDdPjB83n7xuVpcFvygPbGwxF31LZIKrQDfR2Xvh7lmrX654L/7bvlnng 52 NY3Y6exofVdsV3+2wnPFDdPjB83n7xuVpcFvygPbGwxF31LZIKrQDfR2Xvh7lmrX654L/7bvlnng
53 bn3Zuj8M9Hepux6VfZtW1yA6K7cfGqVu8TL325u+fHTb71QKbk+7TZQ+lTc6RcnpqW8qmVQBoj/g 53 bn3Zuj8M9Hepux6VfZtW1yA6K7cfGqVu8TL325u+fHTb71QKbk+7TZQ+lTc6RcnpqW8qmVQBoj/g
54 23eo0sr/NIGvB37K+lOWXMvJ+uWFeKGU/03Cb7n3D4M3wxI= 54 23eo0sr/NIGvB37K+lOWXMvJ+uWFeKGU/03Cb7n3D4M3wxI=
55 '''.strip())) 55 '''.strip()))
56
57 DEFAULT_PORT = 8080
56 58
57 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 59 class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
58 TRACKER_HOMES = {} 60 TRACKER_HOMES = {}
59 LOG_IPADDRESS = 1 61 LOG_IPADDRESS = 1
60 62
239 BaseHTTPServer.HTTPServer): 241 BaseHTTPServer.HTTPServer):
240 ''' A Roundup standalone server for Win32 by Ewout Prangsma 242 ''' A Roundup standalone server for Win32 by Ewout Prangsma
241 ''' 243 '''
242 _svc_name_ = "Roundup Bug Tracker" 244 _svc_name_ = "Roundup Bug Tracker"
243 _svc_display_name_ = "Roundup Bug Tracker" 245 _svc_display_name_ = "Roundup Bug Tracker"
244 address = (HOSTNAME, PORT)
245 def __init__(self, args): 246 def __init__(self, args):
246 # redirect stdout/stderr to our logfile 247 # redirect stdout/stderr to our logfile
247 if LOGFILE: 248 if LOGFILE:
248 # appending, unbuffered 249 # appending, unbuffered
249 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0) 250 sys.stdout = sys.stderr = open(LOGFILE, 'a', 0)
332 os_part = ""''' -u <UID> runs the Roundup web server as this UID 333 os_part = ""''' -u <UID> runs the Roundup web server as this UID
333 -g <GID> runs the Roundup web server as this GID 334 -g <GID> runs the Roundup web server as this GID
334 -d <PIDfile> run the server in the background and write the server's PID 335 -d <PIDfile> run the server in the background and write the server's PID
335 to the file indicated by PIDfile. The -l option *must* be 336 to the file indicated by PIDfile. The -l option *must* be
336 specified if -d is used.''' 337 specified if -d is used.'''
337 port=PORT 338 port=DEFAULT_PORT
338 if message: 339 if message:
339 message += '\n' 340 message += '\n'
340 print _('''%(message)sUsage: roundup-server [options] [name=tracker home]* 341 print _('''%(message)sUsage: roundup-server [options] [name=tracker home]*
341 342
342 Options: 343 Options:
435 if not hasattr(os, 'getuid'): 436 if not hasattr(os, 'getuid'):
436 return 437 return
437 438
438 # People can remove this check if they're really determined 439 # People can remove this check if they're really determined
439 if user is None: 440 if user is None:
441 if os.getuid():
442 return
440 raise ValueError, _("Can't run as root!") 443 raise ValueError, _("Can't run as root!")
441 444
442 if os.getuid(): 445 if os.getuid():
443 print _('WARNING: ignoring "-u" argument, not root') 446 print _('WARNING: ignoring "-u" argument, not root')
444 447
455 pwd.getpwuid(uid) 458 pwd.getpwuid(uid)
456 except KeyError: 459 except KeyError:
457 raise ValueError, _("User %(user)s doesn't exist")%locals() 460 raise ValueError, _("User %(user)s doesn't exist")%locals()
458 os.setuid(uid) 461 os.setuid(uid)
459 462
460 def run(port=PORT, success_message=None): 463 undefined = []
464 def run(port=undefined, success_message=None):
461 ''' Script entry point - handle args and figure out what to to. 465 ''' Script entry point - handle args and figure out what to to.
462 ''' 466 '''
463 # time out after a minute if we can 467 # time out after a minute if we can
464 import socket 468 import socket
465 if hasattr(socket, 'setdefaulttimeout'): 469 if hasattr(socket, 'setdefaulttimeout'):
466 socket.setdefaulttimeout(60) 470 socket.setdefaulttimeout(60)
467 471
468 undefined = []
469 hostname = pidfile = logfile = user = group = svc_args = log_ip = undefined 472 hostname = pidfile = logfile = user = group = svc_args = log_ip = undefined
470 config = None 473 config = None
471 474
472 try: 475 try:
473 # handle the command-line args 476 # handle the command-line args
504 # handle the config file 507 # handle the config file
505 if config: 508 if config:
506 cfg = ConfigParser.ConfigParser() 509 cfg = ConfigParser.ConfigParser()
507 cfg.read(filename) 510 cfg.read(filename)
508 if port is undefined: 511 if port is undefined:
509 port = cfg.get('server', 'port', 8080) 512 port = cfg.get('server', 'port', DEFAULT_PORT)
510 if user is undefined and cfg.has_option('server', 'user'): 513 if user is undefined and cfg.has_option('server', 'user'):
511 user = cfg.get('server', 'user') 514 user = cfg.get('server', 'user')
512 if group is undefined and cfg.has_option('server', 'group'): 515 if group is undefined and cfg.has_option('server', 'group'):
513 group = cfg.get('server', 'group') 516 group = cfg.get('server', 'group')
514 if log_ip is undefined and cfg.has_option('server', 'log_ip'): 517 if log_ip is undefined and cfg.has_option('server', 'log_ip'):
522 for section in cfg.sections(): 525 for section in cfg.sections():
523 if section == 'server': 526 if section == 'server':
524 continue 527 continue
525 homes[section] = cfg.get(section, 'home') 528 homes[section] = cfg.get(section, 'home')
526 529
530 # defaults
531 if hostname is undefined:
532 hostname = ''
533 if group is undefined:
534 group = None
535 if user is undefined:
536 user = None
537 if svc_args is undefined:
538 svc_args = None
539
527 # obtain server before changing user id - allows to use port < 540 # obtain server before changing user id - allows to use port <
528 # 1024 if started as root 541 # 1024 if started as root
529 address = (hostname, port) 542 address = (hostname, port)
530 try: 543 try:
531 httpd = server_class(address, RoundupRequestHandler) 544 httpd = server_class(address, RoundupRequestHandler)
550 RoundupRequestHandler.TRACKER_HOMES[name] = home 563 RoundupRequestHandler.TRACKER_HOMES[name] = home
551 except SystemExit: 564 except SystemExit:
552 raise 565 raise
553 except ValueError: 566 except ValueError:
554 usage(error()) 567 usage(error())
555 except: 568 # except:
556 print error() 569 # print error()
557 sys.exit(1) 570 # sys.exit(1)
558 571
559 # we don't want the cgi module interpreting the command-line args ;) 572 # we don't want the cgi module interpreting the command-line args ;)
560 sys.argv = sys.argv[:1] 573 sys.argv = sys.argv[:1]
561 574
562 # fork the server from our parent if a pidfile is specified 575 # fork the server from our parent if a pidfile is specified
568 else: 581 else:
569 daemonize(pidfile) 582 daemonize(pidfile)
570 583
571 if svc_args is not None: 584 if svc_args is not None:
572 # don't do any other stuff 585 # don't do any other stuff
586 RoundupService.address = address
573 return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args) 587 return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args)
574 588
575 # redirect stdout/stderr to our logfile 589 # redirect stdout/stderr to our logfile
576 if logfile: 590 if logfile:
577 # appending, unbuffered 591 # appending, unbuffered

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