Latest changes to fabfile.py and confs/prod/supervisord.conf
authorbobcall <bob@bobcall.me>
Wed, 3 Jul 2013 17:23:23 +0000 (13:23 -0400)
committerbobcall <bob@bobcall.me>
Wed, 3 Jul 2013 17:23:23 +0000 (13:23 -0400)
confs/prod/supervisord.conf
fabfile.py

index 5cd2bd2c36f8e5b8769f69ee8b0f0f40699a09eb..a116ed4160b6dc0ebc3f131047be05c6d2582f28 100644 (file)
@@ -16,24 +16,21 @@ chmod = 0777
 supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
 [program:gunicorn]
-environment = DJANGO_SETTINGS_MODULE=karmaworld.settings.prod
-command = gunicorn -c confs/production/gunicorn.conf karmaworld.wsgi:application
+command = ./manage.py run_gunicorn -c confs/production/gunicorn.conf
 autostart = true
 autorestart = true
 redirect_stderr = true
 stopsignal = QUIT
 
 [program:celeryd]
-environment = DJANGO_SETTINGS_MODULE=karmaworld.settings.prod
-command = ./manage.py celery worker --app=karmaworld.celery.config --pidfile=var/run/celeryd.pid -l info
+command = ./manage.py celery worker --pidfile=var/run/celeryd.pid -l info
 autorestart = true
 redirect_stderr = true
 stdout_logfile = var/log/celeryd.log
-priority = 2
 
 [program:celerybeat]
 environment = DJANGO_SETTINGS_MODULE=karmaworld.settings.prod
-command = ./manage.py celery beat --app=karmaworld.celery.config --pidfile=var/run/celerybeat.pid -s var/run/celerybeat-schedule -l info
+command = ./manage.py celery beat --pidfile=var/run/celerybeat.pid -s var/run/celerybeat-schedule -l info
 autorestart = true
 redirect_stderr = true
 stdout_logfile = var/log/celerybeat.log
index c366099d85fd738473b8c4f3c613d1027be08160..8a748d6879b490e7ee707f17c75529a23fe078b0 100644 (file)
@@ -27,6 +27,8 @@ def here():
     env.branch = 'beta'
     env.run = virtenv_exec
 
+
+
 ####### Define production host
 @task
 def prod():
@@ -35,7 +37,7 @@ def prod():
     """
 
     env.user = 'djkarma'
-    env.hosts = ['beta.karmanotes.org']
+    env.hosts = ['karmanotes.org']
     env.proj_root = '/var/www/karmaworld'
     env.proj_dir = '/var/www/karmaworld'
     env.reqs = 'reqs/prod.txt'
@@ -44,6 +46,23 @@ def prod():
     env.run = virtenv_exec
     env.gunicorn_addr = '127.0.0.1:8000'
 
+####### Define beta host
+@task
+def beta():
+    """                                                                                                                                                                 
+    Connection Information for beta machine                                                                                                                       
+    """
+
+    env.user = 'djkarma'
+    env.hosts = ['beta.karmanotes.org']
+    env.proj_root = '/var/www/karmaworld'
+    env.proj_dir = '/var/www/karmaworld'
+    env.reqs = 'reqs/beta.txt'
+    env.confs = 'confs/beta/'
+    env.branch = 'beta'
+    env.run = virtenv_exec
+    env.gunicorn_addr = '127.0.0.1:8000'
+
 ######## Run Commands in Virutal Environment
 def virtenv_exec(command):
         """
@@ -89,15 +108,92 @@ def make_virtualenv():
        """
 
        run('virtualenv %s/%s' % (env.proj_root, env.branch))
-       env.run('pip install -r %s/reqs/dev.txt' % env.proj_dir )
+       env.run('pip install -r %s/reqs/%s.txt' % (env.proj_dir, env.branch) )
+
+@task
+def start_supervisord():
+    """
+    Starts supervisord
+    """
+    config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
+    env.run('supervisord -c %s' % config_file)
+
+
+@task
+def stop_supervisord():
+    """
+    Restarts supervisord
+    """
+    config_file = '/var/www/karmaworld/confs/prod/supervisord.conf'
+    env.run('supervisorctl -c %s shutdown' % config_file)
+
+
+@task
+def restart_supervisord():
+    """
+    Restarts supervisord
+    """
+    stop_supervisord()
+    start_supervisord()
+
+
+def supervisorctl(action, process):
+    """
+    Takes as arguments the name of the process as is
+    defined in supervisord.conf and the action that should
+    be performed on it: start|stop|restart.
+    """
+    supervisor_conf = '/var/www/karmaworld/confs/prod/supervisord.conf'
+    env.run('supervisorctl -c %s %s %s' % (supervisor_conf, action, process))
+
+
+@task
+def start_celeryd():
+    """
+    Starts the celeryd process
+    """
+    supervisorctl('start', 'celeryd')
+
+
+@task
+def stop_celeryd():
+    """
+    Stops the celeryd process
+    """
+    supervisorctl('stop', 'celeryd')
+
+
+@task
+def restart_celery():
+    """
+    Restarts the celeryd process
+    """
+    supervisorctl('restart', 'celeryd')
+
 
-####### Start Gunicorn
 @task
 def start_gunicorn():
     """
     Starts the gunicorn process
     """
-    env.run('%s/manage.py run_gunicorn -b %s -p %s/var/run/gunicorn.pid --daemon' % (env.proj_dir, env.gunicorn_addr, env.proj_dir))
+    supervisorctl('start', 'gunicorn')
+
+
+@task
+def stop_gunicorn():
+    """
+    Stops the gunicorn process
+    """
+    supervisorctl('stop', 'gunicorn')
+
+
+@task
+def restart_gunicorn():
+    """
+    Restarts the gunicorn process
+    """
+    supervisorctl('restart', 'gunicorn')
+
 
 ####### Update Requirements
 @task