Skip to content

Commit

Permalink
added nginx cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel McNevin committed Dec 6, 2011
1 parent 6ddf2a3 commit b319913
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
.vagrant
gitlab/config/gitlab.yml
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -33,7 +33,7 @@ On your local machine, update /etc/hosts and add:

Connect to the site

http://gitlab.local:3000
http://gitlab.local

Login with:

Expand Down
10 changes: 10 additions & 0 deletions chef/cookbooks/gitlab/recipes/nginx.rb
@@ -0,0 +1,10 @@
template "#{node[:nginx][:conf_d]}/gitlab.conf" do
source "nginx.gitlab.conf.erb"
variables(
:base_port => 3000,
:server_count => 1,
:hostname => node[:gitlab][:hostname]
)
action :create
notifies :restart, "service[nginx]"
end
18 changes: 18 additions & 0 deletions chef/cookbooks/gitlab/templates/default/nginx.gitlab.conf.erb
@@ -0,0 +1,18 @@
upstream gitlab-web {
<% (@base_port..(@base_port + (@server_count - 1))).each do |port| %>
server 127.0.0.1:<%= port %>;
<% end %>
}

## HTTP Server
server {
server_name <%= @hostname %>;
listen 80;

location / {
proxy_pass http://gitlab-web;
proxy_buffering off;
proxy_buffer_size 16k;
proxy_buffers 8 16k;
}
}
8 changes: 8 additions & 0 deletions chef/cookbooks/nginx/README.rdoc
@@ -0,0 +1,8 @@
= DESCRIPTION:

= REQUIREMENTS:

= ATTRIBUTES:

= USAGE:

12 changes: 12 additions & 0 deletions chef/cookbooks/nginx/attributes/default.rb
@@ -0,0 +1,12 @@
default[:nginx][:install_path] = "/usr/local/nginx"
default[:nginx][:version] = '1.0.9'
default[:nginx][:url] = "http://nginx.org/download/nginx-#{nginx[:version]}.tar.gz"
# default[:nginx][:mam_path] = "/home/mam/src/mam"
default[:nginx][:conf_d] = "#{nginx[:install_path]}/conf.d"

default[:nginx][:nginx_name] = "nginx"
default[:nginx][:base_path] = "/usr/local/nginx"
default[:nginx][:log_path] = "#{nginx[:base_path]}/logs"
# default[:nginx][:proxy_cache_path] = "#{nginx[:base_path]}/proxy_cache_path"
# default[:nginx][:proxy_temp_path] = "#{nginx[:base_path]}/proxy_temp_path"
default[:nginx][:pid_path] = "/var/run"
87 changes: 87 additions & 0 deletions chef/cookbooks/nginx/recipes/default.rb
@@ -0,0 +1,87 @@
#
# Cookbook Name:: nginx
# Recipe:: default
#
# Copyright 2011, Gobbler
#
# All rights reserved - Do Not Redistribute
#

packages = value_for_platform(
["centos","redhat","fedora"] => {'default' => ['pcre-devel', 'openssl-devel']},
"default" => ['libpcre3', 'libpcre3-dev', 'libssl-dev']
)

packages.each do |devpkg|
package devpkg
end

tar_file = "nginx-#{node[:nginx][:version]}.tar.gz"

remote_file "/tmp/#{tar_file}" do
source "#{node[:nginx][:url]}"
not_if { ::File.exists?("/tmp/#{tar_file}") }
end

bash "Install Nginx" do
cwd "/tmp"
code <<-EOH
tar zxf #{tar_file}
cd nginx-#{node[:nginx][:version]}
./configure --prefix=#{node[:nginx][:install_path]}
make install
EOH
not_if do
::File.exists?("#{node[:nginx][:install_path]}/sbin/nginx") &&
system("#{node[:nginx][:install_path]}/sbin/nginx -v 2>&1 | grep -q '#{node[:nginx][:version]}$'")
end
end

base_path = node[:nginx][:base_path]

directory node[:nginx][:log_path] do
owner "root"
group "root"
mode "0755"
recursive true
action :create
end

directory node[:nginx][:conf_d] do
owner "root"
group "root"
mode "0755"
action :create
end

template "/etc/init/nginx.conf" do
source "upstart.nginx.conf.erb"
owner "root"
group "root"
mode "0755"
variables(
:path => node[:nginx][:install_path],
:pid_path => node[:nginx][:pid_path]
)
action :create
end

template "#{node[:nginx][:install_path]}/conf/nginx.conf" do
source "nginx.conf.erb"
owner "root"
group "root"
mode "0644"
variables(
:log_path => node[:nginx][:log_path],
:pid_path => node[:nginx][:pid_path],
:conf_d => node[:nginx][:conf_d]
)
action :create
notifies :restart, "service[nginx]"
end

service "nginx" do
provider Chef::Provider::Service::Upstart
supports :start => true, :restart => true, :stop => true
action [:enable, :start]
end
40 changes: 40 additions & 0 deletions chef/cookbooks/nginx/templates/default/nginx.conf.erb
@@ -0,0 +1,40 @@
#user nobody;
worker_processes 1;

error_log <%= @log_path %>/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid <%= @pid_path %>/nginx.pid;


events {
worker_connections 1024;
}


http {

include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

# sendfile on;
# tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

## Include all sub-configs
include <%= @conf_d %>/*.conf;



}
26 changes: 26 additions & 0 deletions chef/cookbooks/nginx/templates/default/upstart.nginx.conf.erb
@@ -0,0 +1,26 @@
# nginx

description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

env DAEMON=<%= @path %>/sbin/nginx
env PID=<%= @pid_path %>/nginx.pid

expect fork
respawn

pre-start script
$DAEMON -t
if [ $? -ne 0 ]
then exit $?
fi
end script

post-stop script
start-stop-daemon --stop --pidfile $PID --name nginx --exec $DAEMON --signal TERM
end script

exec $DAEMON

0 comments on commit b319913

Please sign in to comment.