diff --git a/mayan/settings/kaze.py b/mayan/settings/kaze.py new file mode 100644 index 0000000000..6b2a005e02 --- /dev/null +++ b/mayan/settings/kaze.py @@ -0,0 +1,11 @@ +from __future__ import absolute_import, unicode_literals + +from .production import * # NOQA + +if not BROKER_URL: + BROKER_URL = 'redis://127.0.0.1:6379/0' + +if not CELERY_RESULT_BACKEND: + CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0' + + diff --git a/old_server.py b/old_server.py new file mode 100755 index 0000000000..3c9a9c3a05 --- /dev/null +++ b/old_server.py @@ -0,0 +1,58 @@ +import sys +import os + +from twisted.application import internet, service +from twisted.web import server, resource, wsgi, static +from twisted.python import threadpool +from twisted.internet import reactor, protocol + +#import twresource + +PORT = 8000 + +class ThreadPoolService(service.Service): + def __init__(self, pool): + self.pool = pool + + def startService(self): + service.Service.startService(self) + self.pool.start() + + def stopService(self): + service.Service.stopService(self) + self.pool.stop() + +# Environment setup for your Django project files: +sys.path.append("mayan") +os.environ['DJANGO_SETTINGS_MODULE'] = 'mayan.settings' +from django.core.handlers.wsgi import WSGIHandler + +# Twisted Application Framework setup: +application = service.Application('twisted-django') + + +# WSGI container for Django, combine it with twisted.web.Resource: +# XXX this is the only 'ugly' part: see the 'getChild' method in twresource.Root +# The MultiService allows to start Django and Twisted server as a daemon. + +multi = service.MultiService() +pool = threadpool.ThreadPool() +tps = ThreadPoolService(pool) +tps.setServiceParent(multi) +resource = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) +#root = twresource.Root(resource) + +# Servce Django media files off of /media: +mediasrc = static.File(os.path.join(os.path.abspath("."), "mydjangosite/media")) +staticsrc = static.File(os.path.join(os.path.abspath("."), "mydjangosite/static")) +root.putChild("media", mediasrc) +root.putChild("static", staticsrc) + +# The cool part! Add in pure Twisted Web Resouce in the mix +# This 'pure twisted' code could be using twisted's XMPP functionality, etc: +#root.putChild("google", twresource.GoogleResource()) + +# Serve it up: +main_site = server.Site(root) +internet.TCPServer(PORT, main_site).setServiceParent(multi) +multi.setServiceParent(application) diff --git a/run_tornado.py b/run_tornado.py new file mode 100755 index 0000000000..b34d5e5edb --- /dev/null +++ b/run_tornado.py @@ -0,0 +1,58 @@ +import os +import sys + +from django.core.wsgi import get_wsgi_application + +import tornado.httpserver +import tornado.ioloop +from tornado.options import options, define, parse_command_line +import tornado.web +import tornado.wsgi + +from tornado.process import Subprocess + +DEFAULT_PORT = 52723 + + +def main(): + define('port', type=int, default=DEFAULT_PORT) + define('single-process', type=bool, default=False) + + parse_command_line() + + os.environ['DJANGO_SETTINGS_MODULE'] = 'mayan.settings.production' + + wsgi_application = get_wsgi_application() + wsgi_container = tornado.wsgi.WSGIContainer(wsgi_application) + + tornado_application = tornado.web.Application( + handlers=( + ( + r'/static/(.*)', tornado.web.StaticFileHandler, + {'path': 'mayan/media/static'}, + ), + ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_container)), + ) + ) + + http_server = tornado.httpserver.HTTPServer(tornado_application) + + try: + if options.single_process: + http_server.listen(options.port) + ioloop = tornado.ioloop.IOLoop.instance() + Subprocess(['./manage.py', 'celery', 'worker']) + ioloop.start() + else: + http_server.bind(options.port) + http_server.start(0) # forks one process per cpu + ioloop = tornado.ioloop.IOLoop.current() + Subprocess(['./manage.py', 'celery', 'worker']) + ioloop.start() + except KeyboardInterrupt: + tornado.ioloop.IOLoop.instance().stop() + + +if __name__ == '__main__': + main() + diff --git a/run_tornado_base.py b/run_tornado_base.py new file mode 100755 index 0000000000..a6e3bcef13 --- /dev/null +++ b/run_tornado_base.py @@ -0,0 +1,16 @@ +import django.core.handlers.wsgi +import os +import tornado.httpserver +import tornado.ioloop +import tornado.wsgi + +def main(): + os.environ["DJANGO_SETTINGS_MODULE"] = 'mayan.settings' + application = django.core.handlers.wsgi.WSGIHandler() + container = tornado.wsgi.WSGIContainer(application) + http_server = tornado.httpserver.HTTPServer(container) + http_server.listen(8888) + tornado.ioloop.IOLoop.instance().start() + +if __name__ == "__main__": + main() diff --git a/tornado_server.py b/tornado_server.py new file mode 100755 index 0000000000..0de7b713e6 --- /dev/null +++ b/tornado_server.py @@ -0,0 +1,50 @@ +#/usr/bin/env python + +# Run this with +# Original file: https://github.com/bdarnell/django-tornado-demo/blob/master/testsite/tornado_main.py +# PYTHONPATH=. DJANGO_SETTINGS_MODULE=testsite.settings testsite/tornado_main.py +# Serves by default at +# http://localhost:8080/hello-tornado and +# http://localhost:8080/hello-django + +from tornado.options import options, define, parse_command_line +import django.core.handlers.wsgi +import tornado.httpserver +import tornado.ioloop +import tornado.web +import tornado.wsgi +#import daemon +import os, sys + + +SITE_ROOT = os.path.dirname(os.getcwd()) +PROJECT_NAME = 'mayan'#os.path.basename(os.getcwd()) + +sys.path.append( 'mayan' ) +os.environ['DJANGO_SETTINGS_MODULE'] = PROJECT_NAME + '.settings' + +define('port', type=int, default=8080) + +class HelloHandler(tornado.web.RequestHandler): + def get(self): + self.write('Hello from tornado') + +def main(): + tornado.options.parse_command_line() + + wsgi_app = tornado.wsgi.WSGIContainer( + django.core.handlers.wsgi.WSGIHandler()) + + tornado_app = tornado.web.Application( + [ + ('/hello-tornado', HelloHandler), + ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)), + ]) + + server = tornado.httpserver.HTTPServer(tornado_app) + server.listen(options.port) + tornado.ioloop.IOLoop.instance().start() + +if __name__ == '__main__': + #with daemon.DaemonContext(): + main()