mirror of
https://github.com/django/daphne.git
synced 2024-11-11 02:26:35 +03:00
Merge pull request #32 from mcallistersean/master
Support inherited file descriptors
This commit is contained in:
commit
cfc7ec51b3
15
README.rst
15
README.rst
|
@ -24,6 +24,21 @@ set a bind address and port (defaults to localhost, port 8000)::
|
|||
daphne -b 0.0.0.0 -p 8001 django_project.asgi:channel_layer
|
||||
|
||||
|
||||
If you intend to run daphne behind a proxy server you can use UNIX
|
||||
sockets to communicate between the two::
|
||||
|
||||
daphne -u /tmp/daphne.sock django_project.asgi:channel_layer
|
||||
|
||||
|
||||
If daphne is being run inside a process manager such as
|
||||
`Circus <https://github.com/circus-tent/circus/>`_ you might
|
||||
want it to bind to a file descriptor passed down from a parent process.
|
||||
To achieve this you can use the --fd flag::
|
||||
|
||||
daphne --fd 5 django_project.asgi:channel_layer
|
||||
|
||||
To see all available command line options run daphne with the *-h* flag.
|
||||
|
||||
Root Path (SCRIPT_NAME)
|
||||
-----------------------
|
||||
|
||||
|
|
|
@ -41,6 +41,13 @@ class CommandLineInterface(object):
|
|||
help='Bind to a UNIX socket rather than a TCP host/port',
|
||||
default=None,
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'--fd',
|
||||
type=int,
|
||||
dest='file_descriptor',
|
||||
help='Bind to a file descriptor rather than a TCP host/port or named unix socket',
|
||||
default=None,
|
||||
)
|
||||
self.parser.add_argument(
|
||||
'-v',
|
||||
'--verbosity',
|
||||
|
@ -133,6 +140,7 @@ class CommandLineInterface(object):
|
|||
host=args.host,
|
||||
port=args.port,
|
||||
unix_socket=args.unix_socket,
|
||||
file_descriptor=args.file_descriptor,
|
||||
http_timeout=args.http_timeout,
|
||||
ping_interval=args.ping_interval,
|
||||
action_logger=AccessLogGenerator(access_log_stream) if access_log_stream else None,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import logging
|
||||
from twisted.internet import reactor
|
||||
|
||||
import socket
|
||||
from .http_protocol import HTTPFactory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -14,6 +14,7 @@ class Server(object):
|
|||
host="127.0.0.1",
|
||||
port=8000,
|
||||
unix_socket=None,
|
||||
file_descriptor=None,
|
||||
signal_handlers=True,
|
||||
action_logger=None,
|
||||
http_timeout=120,
|
||||
|
@ -26,6 +27,7 @@ class Server(object):
|
|||
self.host = host
|
||||
self.port = port
|
||||
self.unix_socket = unix_socket
|
||||
self.file_descriptor = file_descriptor
|
||||
self.signal_handlers = signal_handlers
|
||||
self.action_logger = action_logger
|
||||
self.http_timeout = http_timeout
|
||||
|
@ -48,8 +50,13 @@ class Server(object):
|
|||
)
|
||||
if self.unix_socket:
|
||||
reactor.listenUNIX(self.unix_socket, self.factory)
|
||||
elif self.file_descriptor:
|
||||
# socket returns the same socket if supplied with a fileno
|
||||
sock = socket.socket(fileno=self.file_descriptor)
|
||||
reactor.adoptStreamPort(self.file_descriptor, sock.family, self.factory)
|
||||
else:
|
||||
reactor.listenTCP(self.port, self.factory, interface=self.host)
|
||||
|
||||
reactor.callLater(0, self.backend_reader)
|
||||
reactor.callLater(2, self.timeout_checker)
|
||||
reactor.run(installSignalHandlers=self.signal_handlers)
|
||||
|
|
Loading…
Reference in New Issue
Block a user