Skip to content

Instantly share code, notes, and snippets.

@gladson
Created May 28, 2012 22:08
Show Gist options
  • Select an option

  • Save gladson/2821419 to your computer and use it in GitHub Desktop.

Select an option

Save gladson/2821419 to your computer and use it in GitHub Desktop.
gunicorn_clip-2.sh
#! /bin/bash
set -e
LOGFILE=/home/sites-clip/clip-2/logs/gunicorn_clip-2.log
LOGDIR=$(dirname $LOGFILE)
PIDFILE=/home/sites-clip/clip-2/tmp/gunicorn_clip-2.pid
# Number of worker processes.
# Should be no less than the number of cores available and a popular formula
# is 1 + 2 * number of cores.
NUM_WORKERS=3
USER=clips
GROUP=root
IP_FIX=10.2.2.107:8001
cd /home/sites-clip/clip-2
# Activate the virtualenv
. ../clip-2/env-2/bin/activate
cd clip
test -d $LOGDIR || mkdir -p $LOGDIR
# Finally, the invocation
gunicorn_django -w $NUM_WORKERS --preload\
--user=$USER --group=$GROUP --log-level=debug --daemon\
--log-file=$LOGFILE 2>>$LOGFILE --bind=$IP_FIX --pid=$PIDFILE
server {
listen 80;
server_name clip-2.com;
root /home/sites-clip/clip-2/clip/;
access_log /home/sites-clip/clip-2/logs/access.log;
error_log /home/sites-clip/clip-2/logs/error.log;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://10.2.2.107:8001;
}
}
Django==1.3.1
gunicorn==0.14.3
wsgiref==0.1.2
[program:clip-2]
command=/home/sites-clip/clip-2/gunicorn_clip-2.sh
directory=/home/sites-clip/clip-2/
user=clips
autostart=True
autorestart=True
log_stderr=True
logfile=/home/sites-clip/clip-1/logs/supervisor_clip-1.log
@gladson
Copy link
Copy Markdown
Author

gladson commented May 28, 2012

from fabric.api import cd, env, run

import os

env.project_root = '/home/sites-clip/clip-2'
env.app_root = os.path.join(env.project_root, 'clip')
env.virtualenv = '/home/sites-clip/clip-2/env-2'

def pip_install():
run("%(virtualenv)s/bin/pip install -r %(project_root)s/requirements.txt" % env)

def start():
run('%(project_root)s/gunicorn_clip-2.sh' % env)

def reload():
run('kill -HUP cat %(project_root)s/tmp/gunicorn_clip-2.pid' % env)

def stop():
run('kill -9 cat %(project_root)s/tmp/gunicorn_clip-2.pid' % env)

def limpar_pycs():
with cd(env.app_root):
run("find . -name "*.pyc" | xargs rm -f ")

def deploy():
pip_install()
limpar_pycs()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment