From af7effb9cb6a6e98b0aaedc53dfc8d7f07e3959e Mon Sep 17 00:00:00 2001 From: pwhipp Date: Thu, 10 Jul 2014 17:42:07 +1000 Subject: [PATCH] Added deployment information for production site --- deploy/gunicorn.conf.py | 31 +++++++++++++++++++++++++++ deploy/production/nginx.conf | 34 ++++++++++++++++++++++++++++++ deploy/production/service_demon.sh | 10 +++++++++ deploy/production/upstart.conf | 10 +++++++++ mayan/settings/production.py | 14 +++++++++++- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 deploy/gunicorn.conf.py create mode 100644 deploy/production/nginx.conf create mode 100755 deploy/production/service_demon.sh create mode 100644 deploy/production/upstart.conf diff --git a/deploy/gunicorn.conf.py b/deploy/gunicorn.conf.py new file mode 100644 index 0000000000..7e3916f474 --- /dev/null +++ b/deploy/gunicorn.conf.py @@ -0,0 +1,31 @@ +# invoke gunicorn using +# 'gunicorn -c .wsgi:application +import os +import multiprocessing + +from django.conf import settings + +bind = settings.GUNICORN_BIND +workers = multiprocessing.cpu_count() * 2 + 1 + +preload_app = True + +chdir = settings.BASE_DIR + +user = settings.PROCESS_USER +group = user + +log_dir = os.path.join( + os.path.dirname(settings.BASE_DIR), 'gunicorn_logs', settings.PROCESS_NAME) +if not os.path.isdir(log_dir): + os.makedirs(log_dir) + import pwd + import grp + os.chown(log_dir, + pwd.getpwnam(user).pw_uid, + grp.getgrnam(group).gr_gid) + +accesslog = os.path.join(log_dir, 'access.log') +errorlog = os.path.join(log_dir, 'error.log') + +proc_name = settings.PROCESS_NAME \ No newline at end of file diff --git a/deploy/production/nginx.conf b/deploy/production/nginx.conf new file mode 100644 index 0000000000..dfc719ae8c --- /dev/null +++ b/deploy/production/nginx.conf @@ -0,0 +1,34 @@ +server { + listen 80; + server_name mayan.crossculturalconsult.com www.mayan.crossculturalconsult.com; + + access_log /var/log/nginx/mayan.crossculturalconsult.com.access.log; + error_log /var/log/nginx/mayan.crossculturalconsult.com.error.log; + root /home/mayan/production/; + + location /static/ { + alias /home/mayan/production/static_collected/; + } + + location /media/ { + alias /home/mayan/production/media/; + } + + location = /favicon.ico { + alias /home/mayan/production/media/favicon.ico; + } + + location = /robots.txt { + alias /home/mayan/production/media/robots.txt; + } + + location / { + proxy_pass http://127.0.0.1:8731; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + client_max_body_size 10m; + } + allow all; +} \ No newline at end of file diff --git a/deploy/production/service_demon.sh b/deploy/production/service_demon.sh new file mode 100755 index 0000000000..8d591edc3d --- /dev/null +++ b/deploy/production/service_demon.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Run the gunicorn service + +# Make sure we're in the right virtual env and location +source /home/mayan/.virtualenvs/production/bin/activate +source /home/mayan/.virtualenvs/production/bin/postactivate + +cd /home/mayan/production + +exec gunicorn -c /home/mayan/production/deploy/gunicorn.conf.py mayan.wsgi:application \ No newline at end of file diff --git a/deploy/production/upstart.conf b/deploy/production/upstart.conf new file mode 100644 index 0000000000..261d408b83 --- /dev/null +++ b/deploy/production/upstart.conf @@ -0,0 +1,10 @@ +start on started rc +stop on stopped rc + +respawn +respawn limit 3 5 + +setuid mayan +setgid mayan + +exec /home/mayan/production/deploy/production/service_demon.sh \ No newline at end of file diff --git a/mayan/settings/production.py b/mayan/settings/production.py index e5f50a7de3..4c3b69ff43 100644 --- a/mayan/settings/production.py +++ b/mayan/settings/production.py @@ -5,4 +5,16 @@ from .includes.common import * DEBUG = False TEMPLATE_DEBUG = DEBUG -ALLOWED_HOSTS = ['.crossculturalconsult.com'] \ No newline at end of file +ALLOWED_HOSTS = ['.crossculturalconsult.com'] + + +################### +# DEPLOY SETTINGS # +################### + +GUNICORN_BIND = "127.0.0.1:8731" +PROCESS_USER = 'mayan' +PROCESS_NAME = 'mayan_production' +SITE_TITLE = 'Mayan CCCS' +SITE_TAGLINE = None +VIRTUALENV = 'production' \ No newline at end of file