Commits

John Costa  committed 6300df8

current work

  • Participants
  • Parent commits 3297642

Comments (0)

Files changed (13)

 <http://docs.dotcloud.com/>`_, especially the one for the `Python service
 <http://docs.dotcloud.com/services/python/>`_ which is used by this app.
 
+Notes:
+
+python manage.py runserver_socketio --settings=settings.local
+http://localhost:9000/chat
+
+
+gunicorn wsgi:application -c gunicorn.config --settings=/Users/jcosta/projects/django-on-dotcloud/hellodjango/settings/local.py
+
+
+gunicorn wsgi_ws:application --settings=/Users/jcosta/projects/django-on-dotcloud/hellodjango/settingsocal.py --error-log='/tmp/gunicorn.log' --worker-class geventwebsocket.gunicorn.workers.GeventWebSocketWorker --bind="127.0.0.1:5000"
+gunicorn wsgi:application --settings=/Users/jcosta/projects/django-on-dotcloud/hellodjango/settings/local.py --error-log='/tmp/gunicorn.log' --worker-class geventwebsocket.gunicorn.workers.GeventWebSocketWorker --bind='127.0.0.1:8000'

File dotcloud.yml

 www:
-  type: python
+  type: python-worker
+  ports:
+      www: http
 db:
   type: mysql
 cache:
-  type: redis
+  type: redis

File gunicorn.conf

+import json
+with open('/home/dotcloud/environment.json') as f:
+    env = json.load(f)
+
+
+workers = 2
+worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'
+bind = "127.0.0.1:{0}".format(env['PORT_WWW'])
+pidfile = '/tmp/gunicorn.pid'
+debug = True
+loglevel = 'debug'
+errorlog = '/tmp/gunicorn.log'
+#daemon = True
+django_settings='/Users/jcosta/projects/django-on-dotcloud/hellodjango/settings/dotcloud.py'

File gunicorn_ws.conf

+workers = 2
+worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'
+bind = '127.0.0.1:5000'
+pidfile = '/tmp/gunicorn_ws.pid'
+debug = True
+loglevel = 'debug'
+errorlog = '/tmp/gunicorn.log'
+daemon = True
+django_settings='/Users/jcosta/projects/django-on-dotcloud/hellodjango/settings/dotcloud.py'

File hellodjango/settings/__init__.py

 try:
     if not "--settings" in ''.join(sys.argv):
         from .dotcloud import *
-
+    else:
+        from .local import *
 except ImportError:
     import sys
     print ('Warning importing settings/dotcloud.py. Did you forget to '
            'symlink your currentenv settings?')
 
     import traceback
-    print traceback.print_exc()
+    print traceback.print_exc()

File hellodjango/settings/base.py

         # Catch All Logger -- Captures any other logging
         '': {
             'handlers': ['console', 'log_file', 'mail_admins'],
-            'level': 'INFO',
+            'level': 'DEBUG',
             'propagate': True,
             }
     }
-}
+}

File hellodjango/settings/dotcloud.py

         'HOST': env['DOTCLOUD_DB_MYSQL_HOST'],
         'PORT': int(env['DOTCLOUD_DB_MYSQL_PORT']),
         }
-}
+}
+
+SOCKETIO_HOST = '127.0.0.1'
+SOCKETIO_PORT = '9000'

File hellodjango/settings/local.py

 }
 
 LOGGING['handlers']['log_file']['filename'] = '/tmp/djwebsocket.log'
+
+SOCKETIO_HOST = '127.0.0.1'
+SOCKETIO_PORT = '9000'

File hellodjango/urls.py

+from django.conf import settings
 from django.conf.urls.defaults import patterns, include, url
 # import the view from helloapp
 from helloapp.views import hello_view
 # Uncomment the next two lines to enable the admin:
 from django.contrib import admin
+
+
 admin.autodiscover()
 
 urlpatterns = patterns('',
     url("", include('django_socketio.urls')),
     url(r'^admin/', include(admin.site.urls)),
 )
+
+if settings.DEBUG:
+    urlpatterns += patterns('django.contrib.staticfiles.views',
+        url(r'^static/(?P<path>.*)$', 'serve'),
+    )

File requirements.txt

 Django==1.3.1
 django-redis==1.4.5
+gunicorn
+django-socketio

File supervisord.conf

+[program:webserver]
+command = gunicorn wsgi:application --settings=/home/dotcloud/current/hellodjango/settings/local.py -c /home/dotcloud/current/gunicorn.conf
+
+#[program:websocket]
+#command = gunicorn wsgi_ws:application --settings=/home/dotcloud/current/hellodjango/settings/local.py -c /home/dotcloud/current/gunicorn_ws.conf
 import os
 import sys
 
+PORT = 9000
+
 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'hellodjango')))
 os.environ['DJANGO_SETTINGS_MODULE'] = 'hellodjango.settings'
 import django.core.handlers.wsgi
 application = django.core.handlers.wsgi.WSGIHandler()
+
+#from socketio.server import SocketIOServer
+#
+##if __name__ == '__main__':
+#print 'Listening on port %s and on port 843 (flash policy server)' % PORT
+#SocketIOServer(('', PORT), application, resource="socket.io").serve_forever()
+import os
+import sys
+
+from django.core.handlers.wsgi import WSGIHandler
+
+from socketio.server import SocketIOServer
+
+PORT = 9000
+
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),'hellodjango')))
+os.environ['DJANGO_SETTINGS_MODULE'] = 'hellodjango.settings'
+
+# Make the port available here for the path:
+#   socketio_tags.socketio ->
+#   socketio_scripts.html ->
+#   io.Socket JS constructor
+# allowing the port to be set as the client-side default there.
+os.environ["DJANGO_SOCKETIO_PORT"] = str(PORT)
+
+
+bind = ('127.0.0.1', int(9000))
+print
+print "SocketIOServer running on %s:%s" % bind
+print
+handler = WSGIHandler()
+server = SocketIOServer(bind, handler, resource="socket.io")
+server.serve_forever()
+