46a47,48 > ROUNDUP_GROUP = None > ROUNDUP_LOG_IP = 1 48c50,53 < --- > HOSTNAME = '' > PORT = 8080 > PIDFILE = None > LOGFILE = None 193c198 < LOG_IPADDRESS = 1 --- > LOG_IPADDRESS = ROUNDUP_LOG_IP 200a206,300 > > # Define Windows Service if possible > try: > import win32serviceutil > except: > RoundupService = None > else: > # allow the win32 > import win32service > import win32event > from win32event import * > from win32file import * > > SvcShutdown = "ServiceShutdown" > > class RoundupService(win32serviceutil.ServiceFramework, > BaseHTTPServer.HTTPServer): > ''' A Roundup standalone server for Win32 by Ewout Prangsma > ''' > _svc_name_ = "Roundup Bug Tracker" > _svc_display_name_ = "Roundup Bug Tracker" > address = (HOSTNAME, PORT) > def __init__(self, args): > win32serviceutil.ServiceFramework.__init__(self, args) > BaseHTTPServer.HTTPServer.__init__(self, self.address, > RoundupRequestHandler) > > # Create the necessary NT Event synchronization objects... > # hevSvcStop is signaled when the SCM sends us a notification > # to shutdown the service. > self.hevSvcStop = win32event.CreateEvent(None, 0, 0, None) > > # hevConn is signaled when we have a new incomming connection. > self.hevConn = win32event.CreateEvent(None, 0, 0, None) > > # Hang onto this module for other people to use for logging > # purposes. > import servicemanager > self.servicemanager = servicemanager > > def SvcStop(self): > # Before we do anything, tell the SCM we are starting the > # stop process. > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > win32event.SetEvent(self.hevSvcStop) > > def SvcDoRun(self): > try: > self.serve_forever() > except SvcShutdown: > pass > > def get_request(self): > # Call WSAEventSelect to enable self.socket to be waited on. > WSAEventSelect(self.socket, self.hevConn, FD_ACCEPT) > while 1: > try: > rv = self.socket.accept() > except socket.error, why: > if why[0] != WSAEWOULDBLOCK: > raise > # Use WaitForMultipleObjects instead of select() because > # on NT select() is only good for sockets, and not general > # NT synchronization objects. > rc = WaitForMultipleObjects((self.hevSvcStop, self.hevConn), > 0, INFINITE) > if rc == WAIT_OBJECT_0: > # self.hevSvcStop was signaled, this means: > # Stop the service! > # So we throw the shutdown exception, which gets > # caught by self.SvcDoRun > raise SvcShutdown > # Otherwise, rc == WAIT_OBJECT_0 + 1 which means > # self.hevConn was signaled, which means when we call > # self.socket.accept(), we'll have our incoming connection > # socket! > # Loop back to the top, and let that accept do its thing... > else: > # yay! we have a connection > # However... the new socket is non-blocking, we need to > # set it back into blocking mode. (The socket that accept() > # returns has the same properties as the listening sockets, > # this includes any properties set by WSAAsyncSelect, or > # WSAEventSelect, and whether its a blocking socket or not.) > # > # So if you yank the following line, the setblocking() call > # will be useless. The socket will still be in non-blocking > # mode. > WSAEventSelect(rv[0], self.hevConn, 0) > rv[0].setblocking(1) > break > return rv > > > 274a375 > 283,286c384,391 < hostname = '' < port = 8080 < pidfile = None < logfile = None --- > hostname = HOSTNAME > port = PORT > pidfile = PIDFILE > logfile = LOGFILE > user = ROUNDUP_USER > group = ROUNDUP_GROUP > svc_args = None > 288a394,397 > options = 'n:p:u:d:l:hN' > if RoundupService: > options += 'c' > 290c399 < optlist, args = getopt.getopt(sys.argv[1:], 'n:p:u:d:l:hN') --- > optlist, args = getopt.getopt(sys.argv[1:], options) 294,295d402 < user = ROUNDUP_USER < group = None 304a412 > elif opt == '-c': svc_args = [opt] + args; args = None 305a414,416 > if svc_args is not None and len(optlist) > 1: > raise ValueError, _("windows service option must be the only one") > 365a477,480 > > if svc_args is not None: > # don't do any other stuff > return win32serviceutil.HandleCommandLine(RoundupService, argv=svc_args)