Isso can now listen on unix domain sockets, closes #25

This also changes the server configuration from `host` and `port`
to `listen = http://localhost:8080`.
pull/32/head
Martin Zimmermann 11 years ago
parent 6374d8a9e1
commit 4bb6e91f61

@ -91,25 +91,36 @@ purge-after
Server
------
HTTP server configuration, does **not** apply to uWSGI (except for `profile`).
HTTP server configuration.
.. code-block:: ini
[server]
host = localhost
port = 8080
listen = http://localhost:8080
reload = off
profile = off
host
listen on specified interface
listen
interface to listen on. Isso supports TCP/IP and unix domain sockets:
port
application port
.. code-block:: uni
; UNIX domain socket
listen = unix:///tmp/isso.sock
; TCP/IP
listen = http:///localhost:1234/
When ``gevent`` is available, it is automatically used for `http://`
Currently, gevent can not handle http requests on unix domain socket
(see `#295 <https://github.com/surfly/gevent/issues/295>`_ and
`#299 <https://github.com/surfly/gevent/issues/299>`_ for details).
Does not apply for `uWSGI`.
reload
reload application, when the source code has changed. Useful for
development (don't forget to use a fixed `session-key`).
development (don't forget to use a fixed `session-key`). Only works
when ``gevent`` and ``uwsgi`` are *not* available.
profile
show 10 most time consuming function in Isso after each request. Do

@ -30,8 +30,14 @@ from __future__ import print_function
import pkg_resources
dist = pkg_resources.get_distribution("isso")
try:
import gevent.monkey; gevent.monkey.patch_all()
except ImportError:
pass
import sys
import os
import socket
import logging
from os.path import dirname, join
@ -46,11 +52,10 @@ import misaka
from itsdangerous import URLSafeTimedSerializer
from werkzeug.routing import Map, Rule
from werkzeug.wrappers import Response
from werkzeug.exceptions import HTTPException, InternalServerError
from werkzeug.wsgi import SharedDataMiddleware
from werkzeug.serving import run_simple
from werkzeug.serving import run_simple, WSGIRequestHandler
from werkzeug.contrib.fixers import ProxyFix
from isso import db, migrate, views, wsgi
@ -208,8 +213,52 @@ def main():
migrate.disqus(db.SQLite3(conf.get('general', 'dbpath'), conf), args.dump)
sys.exit(0)
run_simple(conf.get('server', 'host'), conf.getint('server', 'port'), make_app(conf),
threaded=True, use_reloader=conf.getboolean('server', 'reload'))
if conf.get("server", "listen").startswith("http://"):
host, port, _ = parse.host(conf.get("server", "listen"))
try:
from gevent.pywsgi import WSGIServer
WSGIServer((host, port), make_app(conf)).serve_forever()
except ImportError:
run_simple(host, port, make_app(conf), threaded=True,
use_reloader=conf.getboolean('server', 'reload'))
else:
try:
from socketserver import ThreadingMixIn
from http.server import HTTPServer
except ImportError:
from SocketServer import ThreadingMixIn
from BaseHTTPServer import HTTPServer
class SocketWSGIRequestHandler(WSGIRequestHandler):
def run_wsgi(self):
self.client_address = ("<local>", 0)
super(SocketWSGIRequestHandler, self).run_wsgi()
class SocketHTTPServer(HTTPServer, ThreadingMixIn):
multithread = True
multiprocess = False
allow_reuse_address = 1
address_family = socket.AF_UNIX
request_queue_size = 128
def __init__(self, sock, app):
HTTPServer.__init__(self, sock, SocketWSGIRequestHandler)
self.app = app
self.ssl_context = None
self.shutdown_signal = False
sock = conf.get("server", "listen").partition("unix://")[2]
try:
os.unlink(sock)
except OSError:
pass
SocketHTTPServer(sock, make_app(conf)).serve_forever()
try:
import uwsgi

@ -92,7 +92,7 @@ class Config:
"enabled = false",
"purge-after = 30d",
"[server]",
"host = localhost", "port = 8080",
"listen = http://localhost:8080/",
"reload = off", "profile = off",
"[smtp]",
"username = ", "password = ",

Loading…
Cancel
Save