Skip to content
This repository was archived by the owner on May 21, 2021. It is now read-only.

UNIX sockets support #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/source/server/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ and tries to upgrade to websockets if possible.
-----------------------

Used to decide on which address the ``omnibusd`` server binds.
Defaults to all addresses.
Defaults to all addresses. If ``OMNIBUS_SERVER_PORT`` is set to ``None``
then acts as a UNIX socket path.

``OMNIBUS_SERVER_PORT``
-----------------------

Sets the port on which the ``omnibusd`` listens. Defaults to ``4242``.
Set ``None`` for UNIX socket.

``OMNIBUS_SERVER_BASE_URL``
---------------------------
Expand Down
4 changes: 4 additions & 0 deletions docs/source/server/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ This enables `django-omnibus` with normal websocket support.
``OMNIBUS_AUTH_TOKEN`` to the template context. You can use these variables
to configure the JS library.

.. hint::

If you're using UNIX sockets then ``OMNIBUS_ENDPOINT`` variable is useless.

Using SockJS
------------

Expand Down
18 changes: 15 additions & 3 deletions omnibus/management/commands/omnibusd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from django.core.management.base import BaseCommand
from django.utils.module_loading import import_by_path
from tornado import ioloop
from tornado.httpserver import HTTPServer
from tornado.netutil import bind_unix_socket

from ...pubsub import PubSub
from ...settings import (
SERVER_PORT, AUTHENTICATOR_FACTORY, CONNECTION_FACTORY, WEBAPP_FACTORY,
DIRECTOR_ENABLED, FORWARDER_ENABLED)
DIRECTOR_ENABLED, FORWARDER_ENABLED, SERVER_HOST)


logger = logging.getLogger(__name__)
Expand All @@ -31,9 +33,19 @@ def handle(self, *args, **kwargs):
connection_factory = import_by_path(CONNECTION_FACTORY)
webapp_factory = import_by_path(WEBAPP_FACTORY)

# Create app and listen on SEVER_PORT
# Create app
app = webapp_factory(connection_factory(authenticator_factory(), pubsub))
app.listen(SERVER_PORT)
if SERVER_PORT is None:
# Listen on UNIX socket
server = HTTPServer(app)
socket = bind_unix_socket(SERVER_HOST)
server.add_socket(socket)
else:
# Listen on SERVER_HOST:SERVER_PORT
if SERVER_HOST:
app.listen(SERVER_PORT, address=SERVER_HOST)
else:
app.listen(SERVER_PORT)

loop = ioloop.IOLoop().instance()
try:
Expand Down