mirror of https://github.com/scrapy/scrapy.git
Bind the web server and telnet server to a configurable interface (WEBSERVICE_HOST). The default is to bind to all interfaces. Also add documentation for WEBSERVICE_HOST and TELNETCONSOLE_HOST.
This commit is contained in:
parent
b76c5c597f
commit
130276605b
|
|
@ -140,3 +140,28 @@ Telnet Console signals
|
|||
:param telnet_vars: the dict of telnet variables
|
||||
:type telnet_vars: dict
|
||||
|
||||
Telnet settings
|
||||
===============
|
||||
|
||||
These are the settings that control the telnet console's behaviour:
|
||||
|
||||
.. setting:: TELNETCONSOLE_HOST
|
||||
|
||||
TELNETCONSOLE_PORT
|
||||
------------------
|
||||
|
||||
Default: ``[6023, 6073]``
|
||||
|
||||
The port range to use for the etlnet console. If set to ``None`` or ``0``, a
|
||||
dynamically assigned port is used.
|
||||
|
||||
|
||||
.. setting:: TELNETCONSOLE_HOST
|
||||
|
||||
TELNETCONSOLE_HOST
|
||||
------------------
|
||||
|
||||
Default: ``'0.0.0.0'``
|
||||
|
||||
The interface the telnet console should listen on
|
||||
|
||||
|
|
|
|||
|
|
@ -136,6 +136,15 @@ Default: ``[6080, 7030]``
|
|||
The port range to use for the web service. If set to ``None`` or ``0``, a
|
||||
dynamically assigned port is used.
|
||||
|
||||
.. setting:: WEBSERVICE_HOST
|
||||
|
||||
WEBSERVICE_HOST
|
||||
---------------
|
||||
|
||||
Default: ``'0.0.0.0'``
|
||||
|
||||
The interface the web service should listen on
|
||||
|
||||
WEBSERVICE_RESOURCES
|
||||
--------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -259,10 +259,12 @@ USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)
|
|||
|
||||
TELNETCONSOLE_ENABLED = 1
|
||||
TELNETCONSOLE_PORT = [6023, 6073]
|
||||
TELNETCONSOLE_HOST = '0.0.0.0'
|
||||
|
||||
WEBSERVICE_ENABLED = True
|
||||
WEBSERVICE_LOGFILE = None
|
||||
WEBSERVICE_PORT = [6080, 7030]
|
||||
WEBSERVICE_HOST = '0.0.0.0'
|
||||
WEBSERVICE_RESOURCES = {}
|
||||
WEBSERVICE_RESOURCES_BASE = {
|
||||
'scrapy.contrib.webservice.crawler.CrawlerResource': 1,
|
||||
|
|
|
|||
|
|
@ -39,13 +39,14 @@ class TelnetConsole(protocol.ServerFactory):
|
|||
raise NotConfigured
|
||||
self.noisy = False
|
||||
self.portrange = map(int, settings.getlist('TELNETCONSOLE_PORT'))
|
||||
self.host = settings['TELNETCONSOLE_HOST']
|
||||
dispatcher.connect(self.start_listening, signals.engine_started)
|
||||
dispatcher.connect(self.stop_listening, signals.engine_stopped)
|
||||
|
||||
def start_listening(self):
|
||||
self.port = listen_tcp(self.portrange, self)
|
||||
log.msg("Telnet console listening on port %d" % self.port.getHost().port,
|
||||
log.DEBUG)
|
||||
self.port = listen_tcp(self.portrange, self.host, self)
|
||||
h = self.port.getHost()
|
||||
log.msg("Telnet console listening on %s:%d" % (h.host, h.port), log.DEBUG)
|
||||
|
||||
def stop_listening(self):
|
||||
self.port.stopListening()
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
from twisted.internet import reactor, error
|
||||
|
||||
def listen_tcp(portrange, factory):
|
||||
def listen_tcp(portrange, host, factory):
|
||||
"""Like reactor.listenTCP but tries different ports in a range."""
|
||||
assert len(portrange) <= 2, "invalid portrange: %s" % portrange
|
||||
if not hasattr(portrange, '__iter__'):
|
||||
return reactor.listenTCP(portrange, factory)
|
||||
return reactor.listenTCP(portrange, factory, interface=host)
|
||||
if not portrange:
|
||||
return reactor.listenTCP(0, factory)
|
||||
return reactor.listenTCP(0, factory, interface=host)
|
||||
if len(portrange) == 1:
|
||||
return reactor.listenTCP(portrange[0], factory)
|
||||
return reactor.listenTCP(portrange[0], factory, interface=host)
|
||||
for x in range(portrange[0], portrange[1]+1):
|
||||
try:
|
||||
return reactor.listenTCP(x, factory)
|
||||
return reactor.listenTCP(x, factory, interface=host)
|
||||
except error.CannotListenError:
|
||||
if x == portrange[1]:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class WebService(server.Site):
|
|||
raise NotConfigured
|
||||
logfile = settings['WEBSERVICE_LOGFILE']
|
||||
self.portrange = map(int, settings.getlist('WEBSERVICE_PORT'))
|
||||
self.host = settings['WEBSERVICE_HOST']
|
||||
root = RootResource()
|
||||
reslist = build_component_list(settings['WEBSERVICE_RESOURCES_BASE'], \
|
||||
settings['WEBSERVICE_RESOURCES'])
|
||||
|
|
@ -80,9 +81,9 @@ class WebService(server.Site):
|
|||
dispatcher.connect(self.stop_listening, signals.engine_stopped)
|
||||
|
||||
def start_listening(self):
|
||||
self.port = listen_tcp(self.portrange, self)
|
||||
log.msg("Web service listening on port %d" % self.port.getHost().port,
|
||||
log.DEBUG)
|
||||
self.port = listen_tcp(self.portrange, self.host, self)
|
||||
h = self.port.getHost()
|
||||
log.msg("Web service listening on %s:%d" % (h.host, h.port), log.DEBUG)
|
||||
|
||||
def stop_listening(self):
|
||||
self.port.stopListening()
|
||||
|
|
|
|||
Loading…
Reference in New Issue