Browse files

added nginx cookbook

  • Loading branch information...
1 parent 6ddf2a3 commit b319913a31773f786c468766b233a1713241d0f2 Daniel McNevin committed Dec 5, 2011
View
1 .gitignore
@@ -1 +1,2 @@
.vagrant
+gitlab/config/gitlab.yml
View
2 README.md
@@ -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:
View
10 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
View
18 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;
+ }
+ }
View
8 chef/cookbooks/nginx/README.rdoc
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
View
12 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"
View
87 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
View
40 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;
+
+
+
+}
View
26 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.