celery supervisord conf
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 27 Oct 2011 11:37:07 +0000 (13:37 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 27 Oct 2011 11:37:46 +0000 (13:37 +0200)
.gitignore
fabfile.py
wolnelektury-celery.conf.template [new file with mode: 0644]
wolnelektury.wsgi.template

index 944c338..c375441 100644 (file)
@@ -4,6 +4,7 @@ dev.sqlite
 *.db-journal
 *~
 *.orig
 *.db-journal
 *~
 *.orig
+*.log
 
 # Compress output
 /wolnelektury/static/css/all.min*.css
 
 # Compress output
 /wolnelektury/static/css/all.min*.css
@@ -31,4 +32,4 @@ thumbs.db
 .tmp_*
 
 # Tags file
 .tmp_*
 
 # Tags file
-TAGS
\ No newline at end of file
+TAGS
index 7e8934f..2171987 100644 (file)
@@ -65,6 +65,7 @@ def deploy():
     upload_tar_from_git()
     upload_wsgi_script()
     upload_vhost_sample()
     upload_tar_from_git()
     upload_wsgi_script()
     upload_vhost_sample()
+    upload_celery_conf()
     install_requirements()
     copy_localsettings()
     symlink_current_release()
     install_requirements()
     copy_localsettings()
     symlink_current_release()
@@ -120,6 +121,12 @@ def upload_wsgi_script():
     files.upload_template('%(project_name)s.wsgi.template' % env, '%(path)s/%(project_name)s.wsgi' % env, context=env)
     run('chmod ug+x %(path)s/%(project_name)s.wsgi' % env)
 
     files.upload_template('%(project_name)s.wsgi.template' % env, '%(path)s/%(project_name)s.wsgi' % env, context=env)
     run('chmod ug+x %(path)s/%(project_name)s.wsgi' % env)
 
+def upload_celery_conf():
+    "Create and upload a Celery conf for supervisord"
+    print ">>> upload celery supervisord conf"
+    files.upload_template('%(project_name)s-celery.conf.template' % env, '%(path)s/%(project_name)s-celery.conf' % env, context=env)
+    run('chmod ug+x %(path)s/%(project_name)s-celery.conf' % env)
+
 def install_requirements():
     "Install the required packages from the requirements file using pip"
     print '>>> install requirements'
 def install_requirements():
     "Install the required packages from the requirements file using pip"
     print '>>> install requirements'
@@ -157,3 +164,5 @@ def restart_webserver():
     "Restart the web server"
     print '>>> restart webserver'
     run('touch %(path)s/%(project_name)s.wsgi' % env)
     "Restart the web server"
     print '>>> restart webserver'
     run('touch %(path)s/%(project_name)s.wsgi' % env)
+    print '>>> restart Celery'
+    sudo('supervisord restart %(project_name)s-celery' % env)
diff --git a/wolnelektury-celery.conf.template b/wolnelektury-celery.conf.template
new file mode 100644 (file)
index 0000000..c5d24a4
--- /dev/null
@@ -0,0 +1,24 @@
+; =========================================
+; WolneLektury-Celeryd conf for supervisord
+; Put this in /etc/supervisor/conf.d
+; =========================================
+
+[program:%(project_name)s-celery]
+command=%(path)s/bin/python %(path)s/releases/current/%(project_name)s/manage.py celeryd --loglevel=INFO
+directory=%(path)s/releases/current/%(project_name)s
+user=%(user)s
+numprocs=2
+process_name=wolnelektury-celery-%%(process_num)
+stdout_logfile=%(path)s/celeryd.log
+stderr_logfile=%(path)s/celeryd.log
+autostart=true
+autorestart=true
+startsecs=10
+
+; Need to wait for currently executing tasks to finish at shutdown.
+; Increase this if you have very long running tasks.
+stopwaitsecs = 600
+
+; if rabbitmq is supervised, set its priority higher
+; so it starts first
+priority=998
index 3437e8f..6a56ad7 100644 (file)
@@ -1,6 +1,6 @@
 #!%(python)s
 import site
 #!%(python)s
 import site
-site.addsitedir('%(path)s/lib/python2.5/site-packages')
+site.addsitedir('%(path)s/lib/python2.6/site-packages')
 
 import os
 from os.path import abspath, dirname, join
 
 import os
 from os.path import abspath, dirname, join
@@ -10,9 +10,6 @@ import sys
 # print statements for optional import exceptions.
 sys.stdout = sys.stderr
 
 # print statements for optional import exceptions.
 sys.stdout = sys.stderr
 
-# we don't want these packages to cover our virtualenv
-sys.path = [p for p in sys.path if not p.startswith('/usr/lib/python2.5/site-packages') and not p.startswith('/var/lib/python-support/python2.5')]
-
 # Add apps and lib directories to PYTHONPATH
 sys.path = [
        '%(path)s/releases/current/%(project_name)s',
 # Add apps and lib directories to PYTHONPATH
 sys.path = [
        '%(path)s/releases/current/%(project_name)s',
@@ -23,6 +20,7 @@ sys.path = [
 ] + sys.path
 
 # Run Django
 ] + sys.path
 
 # Run Django
+os.environ["CELERY_LOADER"] = "django"
 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
 
 from django.core.handlers.wsgi import WSGIHandler
 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
 
 from django.core.handlers.wsgi import WSGIHandler