Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
Added the very skeleton of a Chef config as an example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobian committed Mar 10, 2011
1 parent ad99e43 commit c5d24b4
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 22 deletions.
10 changes: 1 addition & 9 deletions apache/apache2.conf
Expand Up @@ -66,12 +66,4 @@ DocumentRoot "/home/web/static"
# And finally the app config.
#

WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"








WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"
70 changes: 70 additions & 0 deletions chef/cookbooks/web/files/default/apache2.conf
@@ -0,0 +1,70 @@
# Apache conf (/etc/apache2/apache2.conf)

#
# Basic server setup
#
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
ServerTokens ProductOnly
ServerAdmin someone@example.com

# Standalone server.
Listen *:80

#
# Worker MPM features
#

Timeout 60
StartServers 2
ServerLimit 5
MinSpareThreads 2
MaxSpareThreads 4
ThreadLimit 10
ThreadsPerChild 10
MaxClients 50
MaxRequestsPerChild 10000

#
# Modules
#

LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

#
# Logging
#

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined

#
# Default HTTP features
#

AddDefaultCharset utf-8
DefaultType text/plain
TypesConfig /etc/mime.types

#
# Basic document root and directory perms.
#

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

DocumentRoot "/home/web/static"

#
# And finally the app config.
#

WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"

16 changes: 16 additions & 0 deletions chef/cookbooks/web/recipes/default.rb
@@ -0,0 +1,16 @@
package "git-core"
package "python-dev"
package "python-setuptools"
package "postgresql-dev"
package "postgresql-client"
package "build-essential"
package "libpq-dev"
package "subversion"
package "mercurial"

cookbook_file "/etc/apache2/apache2.conf" do
source "apache2.conf"
owner "root"
group "root"
mode "644"
end
3 changes: 3 additions & 0 deletions chef/node.json
@@ -0,0 +1,3 @@
{
"run_list": ["web::default"]
}
3 changes: 3 additions & 0 deletions chef/solo.rb
@@ -0,0 +1,3 @@
log_level :info
cookbook_path "/etc/chef/cookbooks"
json_attribs "/etc/chef/node.json"
29 changes: 23 additions & 6 deletions fabfile.py
@@ -1,13 +1,18 @@
"""
The tutorial's first fabfile: automate deployment onto a single server.
The tutorial's fabfile.
This starts out pretty simple -- just automating deployment on a single
server with a few commands. Then it gets a bit more complex (a basic
provisioning example).
"""

import os
from fabric.api import *
import contextlib
from fabric.api import env, run, cd, sudo, put, require, settings, hide, puts
from fabric.contrib import project, files

# This is a bit more complicated than needed because I'm using Vagrant
# for the examples.
env.hosts = ['pycon-web1']
env.hosts = ['pycon-web2']
env.user = 'vagrant'
env.key_filename = '/Library/Ruby/Gems/1.8/gems/vagrant-0.7.2/keys/vagrant'

Expand Down Expand Up @@ -39,6 +44,11 @@ def reload():
"Reload Apache to pick up new code changes."
sudo("invoke-rc.d apache2 reload")

#
# OK, simple stuff done. Here's a more complex example: provisioning
# a server the simplistic way.
#

def setup():
"""
Set up (bootstrap) a new server.
Expand Down Expand Up @@ -77,5 +87,12 @@ def setup():

# Now do the normal deploy.
deploy()




def run_chef():
"""
Run Chef-solo on the remote server
"""
project.rsync_project(local_dir='chef', remote_dir='/tmp', delete=True)
sudo('rsync -ar --delete /tmp/chef/ /etc/chef/')
sudo('chef-solo')
9 changes: 4 additions & 5 deletions nginx/nginx.conf
Expand Up @@ -33,10 +33,9 @@ http {
include /etc/nginx/mime.types;

# HTTP upstream for load balancers.
# Replace the IPs below with IPs (or names) of your upstream Apaches
upstream fumblerooski {
server 10.X.X.X:8000;
server 10.X.X.X:8000;
upstream mingus {
server 33.33.33.10:8000;
#server 33.33.33.11:8000;
}

# The actual HTTP sever.
Expand All @@ -55,7 +54,7 @@ http {

# Proxy everything else to the backend
location / {
proxy_pass http://fumblerooski;
proxy_pass http://mingus;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Handled-By $upstream_addr;
}
Expand Down
42 changes: 40 additions & 2 deletions notes/pycon2011/script.txt
Expand Up @@ -145,11 +145,49 @@ While it runs talk about configuration management a bit.
6. Load balancers
-----------------

Set up Nginx on web1::

web1$ aptitude install nginx
web1$ cd /etc/nginx/
web1$ rm -rf conf.d/ fastcgi_params koi-* nginx.conf sites-* win-utf
web1$ ln -s /home/web/django-deployment-workshop/nginx/nginx.conf .

Edit Apache conf to listen on port 8000::

web1$ vim /etc/apache2/apache2.conf
web1$ invoke-rc.d apache2 restart

Edit Nginx to point to correct backend - just web1 for now::

web1$ vim /etc/nginx/nginx.conf
web1$ invoke-rc.d nginx start

Check it out::

local$ curl -I http://pycon-web1/

Edit Apache on web2 for port 8000::

web2$ vim /etc/apache2/apache2.conf
web2$ invoke-rc.d apache2 restart

Edit Nginx to point to both backends::

web1$ vim /etc/nginx/nginx.conf
web1$ invoke-rc.d nginx restart

Check it out, looking at ``X-Handled-By``::

local$ curl -I http://pycon-web1/

7. Connection middleware
------------------------

8. Next steps.
--------------
Just look at the pgpool conf.

BONUS: Configuration management
-------------------------------

Look at the Chef config. Then::

local$ fab run_chef

0 comments on commit c5d24b4

Please sign in to comment.