--- d:/cvs/roundup/branch/roundup/roundup/scripts/roundup_server.py 2003-11-11 23:25:00.000000000 +0100 +++ d:/apps/python23/lib/site-packages/roundup/scripts/roundup_server.py 2003-11-20 13:33:27.000000000 +0100 @@ -44,6 +44,12 @@ } ROUNDUP_USER = None +ROUNDUP_GROUP = None +ROUNDUP_LOG_IP = 1 +HOSTNAME = '' +PORT = 8080 +PIDFILE = None +LOGFILE = None # @@ -199,7 +205,7 @@ c = tracker.Client(tracker, self, env) c.main() - LOG_IPADDRESS = 1 + LOG_IPADDRESS = ROUNDUP_LOG_IP def address_string(self): if self.LOG_IPADDRESS: return self.client_address[0] @@ -226,8 +232,12 @@ ''' _svc_name_ = "Roundup Bug Tracker" _svc_display_name_ = "Roundup Bug Tracker" - address = ('', 8888) + address = (HOSTNAME, PORT) def __init__(self, args): + # redirect stdout/stderr to our logfile + if LOGFILE: + # appending, unbuffered + sys.stdout = sys.stderr = open(LOGFILE, 'a', 0) win32serviceutil.ServiceFramework.__init__(self, args) BaseHTTPServer.HTTPServer.__init__(self, self.address, RoundupRequestHandler) @@ -310,10 +320,16 @@ -p: sets the port to listen on -l: sets a filename to log to (instead of stdout) -d: run the server in the background and on UN*X write the server's PID - to the nominated file. Note: on Windows the PID argument is needed, - but ignored. The -l option *must* be specified if this option is. + to the nominated file. The -l option *must* be specified if this + option is. -N: log client machine names in access log instead of IP addresses (much slower) + -c: Windows Service options. If you want to run the server as a Windows + Service, you must configure the rest of the options by changing the + constants of this program. You will at least configure one tracker + in the TRACKER_HOMES variable. This option is mutually exclusive + from the rest. Typing "roundup-server -c help" shows Windows + Services specifics. name=tracker home: Sets the tracker home(s) to use. The name is how the tracker is @@ -379,18 +395,27 @@ if hasattr(socket, 'setdefaulttimeout'): socket.setdefaulttimeout(60) - hostname = '' - port = 8080 - pidfile = None - logfile = None + hostname = HOSTNAME + port = PORT + pidfile = PIDFILE + logfile = LOGFILE + user = ROUNDUP_USER + group = ROUNDUP_GROUP + svc_args = None + try: # handle the command-line args + options = 'n:p:u:d:l:hN' + if RoundupService: + options += 'c' + try: - optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:d:l:hN') + optlist, args = getopt.getopt(sys.argv[1:], options) except getopt.GetoptError, e: usage(str(e)) user = ROUNDUP_USER + group = None for (opt, arg) in optlist: if opt == '-n': hostname = arg elif opt == '-p': port = int(arg) @@ -399,6 +424,10 @@ elif opt == '-l': logfile = abspath(arg) elif opt == '-h': usage() elif opt == '-N': RoundupRequestHandler.LOG_IPADDRESS = 0 + elif opt == '-c': svc_args = [opt] + args; args = None + + if svc_args is not None and len(optlist) > 1: + raise ValueError, _("windows service option must be the only one") if pidfile and not logfile: raise ValueError, _("logfile *must* be specified if pidfile is") @@ -426,7 +455,7 @@ if args: d = {} for arg in args: - try: + try: name, home = arg.split('=') except ValueError: raise ValueError, _("Instances must be name=home") @@ -444,17 +473,17 @@ # fork? if pidfile: - if RoundupService: - # don't do any other stuff - RoundupService.address = address - return win32serviceutil.HandleCommandLine(RoundupService) - elif not hasattr(os, 'fork'): + if not hasattr(os, 'fork'): print "Sorry, you can't run the server as a daemon on this" \ 'Operating System' sys.exit(0) else: daemonize(pidfile) + if svc_args is not None: + # don't do any other stuff + return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args) + # redirect stdout/stderr to our logfile if logfile: # appending, unbuffered