diff --git a/docs/source/server/configuration.rst b/docs/source/server/configuration.rst index 8916c8c..494eaf6 100644 --- a/docs/source/server/configuration.rst +++ b/docs/source/server/configuration.rst @@ -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`` --------------------------- diff --git a/docs/source/server/installation.rst b/docs/source/server/installation.rst index db15e2a..4af7202 100644 --- a/docs/source/server/installation.rst +++ b/docs/source/server/installation.rst @@ -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 ------------ diff --git a/omnibus/management/commands/omnibusd.py b/omnibus/management/commands/omnibusd.py index ad26b22..c89da2e 100644 --- a/omnibus/management/commands/omnibusd.py +++ b/omnibus/management/commands/omnibusd.py @@ -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__) @@ -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: