Bringing ch08 up to date
authorLorin Hochstein <lhochstein@netflix.com>
Mon, 9 Jan 2017 00:56:55 +0000 (16:56 -0800)
committerLorin Hochstein <lhochstein@netflix.com>
Mon, 9 Jan 2017 00:56:55 +0000 (16:56 -0800)
ch08/playbooks/group_vars/all
ch08/playbooks/roles/mezzanine/tasks/django.yml
ch08/playbooks/roles/mezzanine/tasks/main.yml
ch08/playbooks/roles/mezzanine/templates/nginx.conf.j2
ch08/playbooks/roles/mezzanine/templates/supervisor.conf.j2
ch08/playbooks/roles/mezzanine/vars/main.yml
ch08/playbooks/scripts/setadmin.py
ch08/playbooks/scripts/setsite.py

index 6fa89ab..26f54fe 100644 (file)
@@ -1,3 +1,4 @@
-mezzanine_proj_name: mezzanine_example
+mezzanine_proj_app: mezzanine_example
+mezzanine_proj_name: "{{ mezzanine_proj_app }}"
 locale: en_US.UTF-8
 database_port: 5432
index 19d453d..61eea8e 100644 (file)
@@ -1,11 +1,18 @@
+- name: create a logs directory
+  file: path="{{ ansible_env.HOME }}/logs" state=directory
 - name: check out the repository on the host
   git: repo={{ mezzanine_repo_url }} dest={{ mezzanine_proj_path }} accept_hostkey=yes
+- name: install Python requirements globally via pip
+  pip: name={{ item }} state=latest
+  with_items:
+    - pip
+    - virtualenv
+    - virtualenvwrapper
 - name: install required python packages
   pip: name={{ item }} virtualenv={{ mezzanine_venv_path }}
   with_items:
     - gunicorn
     - setproctitle
-    - south
     - psycopg2
     - django-compressor
     - python-memcached
     virtualenv={{ mezzanine_venv_path }}
 - name: generate the settings file
   template: src=local_settings.py.j2 dest={{ mezzanine_proj_path }}/local_settings.py
-- name: sync the database, apply migrations, collect static content
+- name: apply migrations to create the database, collect static content
   django_manage:
     command: "{{ item }}"
     app_path: "{{ mezzanine_proj_path }}"
     virtualenv: "{{ mezzanine_venv_path }}"
   with_items:
-    - syncdb
     - migrate
     - collectstatic
 - name: set the site id
   environment:
     PATH: "{{ mezzanine_venv_path }}/bin"
     PROJECT_DIR: "{{ mezzanine_proj_path }}"
+    PROJECT_APP: "{{ mezzanine_proj_app }}"
     WEBSITE_DOMAIN: "{{ live_hostname }}"
 - name: set the admin password
   script: scripts/setadmin.py
   environment:
     PATH: "{{ mezzanine_venv_path }}/bin"
     PROJECT_DIR: "{{ mezzanine_proj_path }}"
+    PROJECT_APP: "{{ mezzanine_proj_app }}"
     ADMIN_PASSWORD: "{{ admin_pass }}"
 - name: set the gunicorn config file
   template: src=gunicorn.conf.py.j2 dest={{ mezzanine_proj_path }}/gunicorn.conf.py
index 975a15e..0f3fa57 100644 (file)
@@ -7,7 +7,7 @@
     - libjpeg-dev
     - libpq-dev
     - memcached
-    - nginx
+    - postgresql
     - python-dev
     - python-pip
     - python-psycopg2
index 80accd4..ed85645 100644 (file)
@@ -1,5 +1,5 @@
 upstream {{ mezzanine_proj_name }} {
-    server 127.0.0.1:{{ mezzanine_gunicorn_port }};
+    server unix:{{ mezzanine_proj_path }}/gunicorn.sock fail_timeout=0;
 }
 
 server {
index f49cffb..e2c1102 100644 (file)
@@ -1,11 +1,9 @@
-[group: {{ mezzanine_proj_name }}]
-programs=gunicorn_{{ mezzanine_proj_name }}
-
-[program:gunicorn_{{ mezzanine_proj_name }}]
-command={{ mezzanine_venv_path }}/bin/gunicorn_django -c gunicorn.conf.py -p gunicorn.pid
+[program:{{ mezzanine_gunicorn_procname }}]
+command={{ mezzanine_venv_path }}/bin/gunicorn -c gunicorn.conf.py -p gunicorn.pid {{ mezzanine_proj_app }}.wsgi:application
 directory={{ mezzanine_proj_path }}
 user={{ mezzanine_user }}
 autostart=true
+stdout_logfile = /home/{{ mezzanine_user }}/logs/{{ mezzanine_proj_name }}_supervisor
 autorestart=true
 redirect_stderr=true
 environment=LANG="{{ locale }}",LC_ALL="{{ locale }}",LC_LANG="{{ locale }}"
index 657d868..f530907 100644 (file)
@@ -10,3 +10,4 @@ mezzanine_conf_path: /etc/nginx/conf
 mezzanine_python: "{{ mezzanine_venv_path }}/bin/python"
 mezzanine_manage: "{{ mezzanine_python }} {{ mezzanine_proj_path }}/manage.py"
 mezzanine_num_workers: "multiprocessing.cpu_count() * 2 + 1"
+mezzanine_gunicorn_procname: gunicorn_mezzanine
index 7800302..4ddba5b 100644 (file)
@@ -3,6 +3,7 @@
 # Assumes two environment variables
 #
 # PROJECT_DIR: the project directory (e.g., ~/projname)
+# PROJECT_APP: name of the project app
 # ADMIN_PASSWORD: admin user's password
 
 import os
@@ -12,10 +13,11 @@ import sys
 proj_dir = os.path.expanduser(os.environ['PROJECT_DIR'])
 sys.path.append(proj_dir)
 
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-
-
-from mezzanine.utils.models import get_user_model
+proj_app = os.environ['PROJECT_APP']
+os.environ['DJANGO_SETTINGS_MODULE'] = proj_app + '.settings'
+import django
+django.setup()
+from django.contrib.auth import get_user_model
 User = get_user_model()
 u, _ = User.objects.get_or_create(username='admin')
 u.is_staff = u.is_superuser = True
index 9455624..83e3d8b 100644 (file)
@@ -2,9 +2,9 @@
 # A script to set the site domain
 # Assumes two environment variables
 #
-# PROJECT_DIR: the project directory (e.g., ~/projname)
 # WEBSITE_DOMAIN: the domain of the site (e.g., www.example.com)
-
+# PROJECT_DIR: root directory of the project
+# PROJECT_APP: name of the project app
 import os
 import sys
 
@@ -12,11 +12,12 @@ import sys
 proj_dir = os.path.expanduser(os.environ['PROJECT_DIR'])
 sys.path.append(proj_dir)
 
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+proj_app = os.environ['PROJECT_APP']
+os.environ['DJANGO_SETTINGS_MODULE'] = proj_app + '.settings'
+import django
+django.setup()
 from django.conf import settings
 from django.contrib.sites.models import Site
-
 domain = os.environ['WEBSITE_DOMAIN']
 Site.objects.filter(id=settings.SITE_ID).update(domain=domain)
 Site.objects.get_or_create(domain=domain)
-