From 1d3f4feffc12cb0882554d8d99feb7ae42a72619 Mon Sep 17 00:00:00 2001 From: bobcall Date: Wed, 3 Jul 2013 13:23:23 -0400 Subject: [PATCH] Latest changes to fabfile.py and confs/prod/supervisord.conf --- confs/prod/supervisord.conf | 9 ++-- fabfile.py | 104 ++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 10 deletions(-) diff --git a/confs/prod/supervisord.conf b/confs/prod/supervisord.conf index 5cd2bd2..a116ed4 100644 --- a/confs/prod/supervisord.conf +++ b/confs/prod/supervisord.conf @@ -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 diff --git a/fabfile.py b/fabfile.py index c366099..8a748d6 100644 --- a/fabfile.py +++ b/fabfile.py @@ -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 -- 2.25.1