def __init__(self, module='Main', ip='127.0.0.1', port=None, socket_file=None, pid_file=None, pcgi_file=None, resolver=None, logger_object=None): self.ip = ip asyncore.dispatcher.__init__(self) self.count = counter() if not logger_object: logger_object = logger.file_logger(sys.stdout) if resolver: self.logger = logger.resolving_logger(resolver, logger_object) else: self.logger = logger.unresolving_logger(logger_object) # get configuration self.module = module self.port = port self.pid_file = pid_file self.socket_file = socket_file if pcgi_file is not None: self.read_info(pcgi_file) # write pid file try: f = open(self.pid_file, 'w') f.write(str(os.getpid())) f.close() except IOError: self.log_info("Cannot write PID file.", 'error') # setup sockets if self.port: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((self.ip, self.port)) self.log_info('PCGI Server started at %s\n' '\tInet socket port: %s' % (time.ctime(time.time()), self.port)) else: try: os.unlink(self.socket_file) except os.error: pass self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.set_reuse_addr() self.bind(self.socket_file) try: os.chmod(self.socket_file, 0777) except os.error: pass self.log_info('PCGI Server started at %s\n' '\tUnix socket: %s' % (time.ctime(time.time()), self.socket_file)) self.listen(256)
def __init__(self, module='Main', ip='127.0.0.1', port=None, socket_file=None, resolver=None, logger_object=None): self.ip = ip self.count = counter() asyncore.dispatcher.__init__(self) if not logger_object: logger_object = logger.file_logger(sys.stdout) if resolver: self.logger = logger.resolving_logger(resolver, logger_object) else: self.logger = logger.unresolving_logger(logger_object) # get configuration self.module = module self.port = port self.socket_file = socket_file # setup sockets if self.port: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((self.ip, self.port)) else: try: os.unlink(self.socket_file) except os.error: pass self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.set_reuse_addr() self.bind(self.socket_file) try: os.chmod(self.socket_file, 0o777) except os.error: pass self.listen(256) self.log_info('FastCGI Server (V%s) started at %s\n' '\tIP : %s\n' '\tPort : %s\n' '\tSocket path : %s\n' % ('1.0', time.ctime(time.time()), self.ip, self.port, self.socket_file))