Commit f5553ba2 authored by Michel Pelletier's avatar Michel Pelletier

Make start script output intelligible

parent 678a457e
...@@ -110,13 +110,14 @@ import os ...@@ -110,13 +110,14 @@ import os
import types import types
import thread import thread
import time import time
import socket
from cStringIO import StringIO from cStringIO import StringIO
from PubCore import handle from PubCore import handle
from HTTPResponse import make_response from HTTPResponse import make_response
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from medusa.http_server import http_server, http_channel from medusa.http_server import http_server, http_channel, VERSION_STRING
from medusa import counter, producers, asyncore, max_sockets from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header from medusa.default_handler import split_path, unquote, get_header
from medusa.asyncore import compact_traceback, dispatcher from medusa.asyncore import compact_traceback, dispatcher
...@@ -125,6 +126,7 @@ from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION ...@@ -125,6 +126,7 @@ from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
import DebugLogger import DebugLogger
from medusa import logger
register_subsystem('ZServer HTTPServer') register_subsystem('ZServer HTTPServer')
...@@ -382,6 +384,58 @@ class zhttp_server(http_server): ...@@ -382,6 +384,58 @@ class zhttp_server(http_server):
channel_class = zhttp_channel channel_class = zhttp_channel
def __init__ (self, ip, port, resolver=None, logger_object=None):
self.ip = ip
self.port = port
asyncore.dispatcher.__init__ (self)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.handlers = []
if not logger_object:
logger_object = logger.file_logger (sys.stdout)
self.set_reuse_addr()
self.bind ((ip, port))
# lower this to 5 if your OS complains
self.listen (1024)
host, port = self.socket.getsockname()
if not ip:
ip = socket.gethostbyname (socket.gethostname())
try:
self.server_name = socket.gethostbyaddr (ip)[0]
except socket.error:
self.log_info('Cannot do reverse lookup for server address', 'warning')
self.server_name = ip # use the IP address as the "hostname"
self.server_port = port
self.total_clients = counter.counter()
self.total_requests = counter.counter()
self.exceptions = counter.counter()
self.bytes_out = counter.counter()
self.bytes_in = counter.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)
self.log_info (
'HTTP server (V%s) started at %s\n'
'\tServer URL: http://%s:%s/\n' % (
VERSION_STRING,
time.ctime(time.time()),
self.server_name,
port,
)
)
def readable(self): def readable(self):
return self.accepting and \ return self.accepting and \
len(asyncore.socket_map) < CONNECTION_LIMIT len(asyncore.socket_map) < CONNECTION_LIMIT
......
...@@ -110,13 +110,14 @@ import os ...@@ -110,13 +110,14 @@ import os
import types import types
import thread import thread
import time import time
import socket
from cStringIO import StringIO from cStringIO import StringIO
from PubCore import handle from PubCore import handle
from HTTPResponse import make_response from HTTPResponse import make_response
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from medusa.http_server import http_server, http_channel from medusa.http_server import http_server, http_channel, VERSION_STRING
from medusa import counter, producers, asyncore, max_sockets from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header from medusa.default_handler import split_path, unquote, get_header
from medusa.asyncore import compact_traceback, dispatcher from medusa.asyncore import compact_traceback, dispatcher
...@@ -125,6 +126,7 @@ from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION ...@@ -125,6 +126,7 @@ from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
import DebugLogger import DebugLogger
from medusa import logger
register_subsystem('ZServer HTTPServer') register_subsystem('ZServer HTTPServer')
...@@ -382,6 +384,58 @@ class zhttp_server(http_server): ...@@ -382,6 +384,58 @@ class zhttp_server(http_server):
channel_class = zhttp_channel channel_class = zhttp_channel
def __init__ (self, ip, port, resolver=None, logger_object=None):
self.ip = ip
self.port = port
asyncore.dispatcher.__init__ (self)
self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
self.handlers = []
if not logger_object:
logger_object = logger.file_logger (sys.stdout)
self.set_reuse_addr()
self.bind ((ip, port))
# lower this to 5 if your OS complains
self.listen (1024)
host, port = self.socket.getsockname()
if not ip:
ip = socket.gethostbyname (socket.gethostname())
try:
self.server_name = socket.gethostbyaddr (ip)[0]
except socket.error:
self.log_info('Cannot do reverse lookup for server address', 'warning')
self.server_name = ip # use the IP address as the "hostname"
self.server_port = port
self.total_clients = counter.counter()
self.total_requests = counter.counter()
self.exceptions = counter.counter()
self.bytes_out = counter.counter()
self.bytes_in = counter.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)
self.log_info (
'HTTP server (V%s) started at %s\n'
'\tServer URL: http://%s:%s/\n' % (
VERSION_STRING,
time.ctime(time.time()),
self.server_name,
port,
)
)
def readable(self): def readable(self):
return self.accepting and \ return self.accepting and \
len(asyncore.socket_map) < CONNECTION_LIMIT len(asyncore.socket_map) < CONNECTION_LIMIT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment