Skip to content

Commit

Permalink
feat: Add SCRAPYD_UNIX_SOCKET_PATH environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 16, 2024
1 parent e84aa92 commit 3faf1d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
18 changes: 14 additions & 4 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following environment variables override corresponding options:
* ``SCRAPYD_HTTP_PORT`` (:ref:`http_port`)
* ``SCRAPYD_USERNAME`` (:ref:`username`)
* ``SCRAPYD_PASSWORD`` (:ref:`password`)
* ``SCRAPYD_UNIX_SOCKET_PATH`` (:ref:`unix_socket_path`)

Application options
-------------------
Expand Down Expand Up @@ -78,14 +79,23 @@ Default
Options
Any integer

.. _username:
.. _unix_socket_path:

unix_socket_path
----------------

The filesystem path for a unix socket where the HTTP JSON API will listen.
Example: ``/var/run/scrapyd/http-api.socket``
File permissions: 0660
The filesystem path of the Unix socket on which the :ref:`webui` and :doc:`api` listen for connections.

For example:

.. code-block:: ini
unix_socket_path = /var/run/scrapyd/web.socket
The file's mode is set to 660 (owner and group, read and write).

.. _username:

username
~~~~~~~~

Expand Down
18 changes: 9 additions & 9 deletions scrapyd/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ def create_wrapped_resource(webroot_cls, config, app):

def application(config):
app = Application("Scrapyd")
http_port = int(os.getenv('SCRAPYD_HTTP_PORT') or config.getint('http_port', 6800))
bind_address = os.getenv('SCRAPYD_BIND_ADDRESS') or config.get('bind_address', '127.0.0.1')
uds_path = config.get('unix_socket_path', '')
uds_path = uds_path and os.path.abspath(uds_path)
http_port = int(os.getenv('SCRAPYD_HTTP_PORT') or config.getint('http_port', 6800))
unix_socket_path = os.getenv('SCRAPYD_UNIX_SOCKET_PATH') or config.get('unix_socket_path', '')

poll_interval = config.getfloat('poll_interval', 5)

Expand Down Expand Up @@ -71,15 +70,16 @@ def application(config):
webroot_cls = load_object(webroot_path)
resource = server.Site(create_wrapped_resource(webroot_cls, config, app))

if http_port:
if bind_address and http_port:
webservice = TCPServer(http_port, resource, interface=bind_address)
log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
bind_address=bind_address, http_port=http_port)
if uds_path:
webservice = UNIXServer(uds_path, resource, mode=0o660)
log.msg(format="Scrapyd web console available at http+unix://%(uds_path)s",
uds_path=uds_path)

if unix_socket_path:
unix_socket_path = os.path.abspath(unix_socket_path)
webservice = UNIXServer(unix_socket_path, resource, mode=0o660)
log.msg(format="Scrapyd web console available at http+unix://%(unix_socket_path)s",
unix_socket_path=unix_socket_path)

launcher.setServiceParent(app)
timer.setServiceParent(app)
webservice.setServiceParent(app)
Expand Down

0 comments on commit 3faf1d4

Please sign in to comment.