Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
passenger-nginx default recipe
default[:ree][:version] = "1.8.7-2011.03"
default[:nginx][:version] = "1.1.10"
default[:passenger][:version] = "3.0.11"
case platform
when "debian","ubuntu"
set[:nginx][:dir] = "/etc/nginx"
set[:nginx][:log_dir] = "/var/log/nginx"
set[:nginx][:user] = "www-data"
set[:nginx][:binary] = "/usr/sbin/nginx"
else
set[:nginx][:dir] = "/etc/nginx"
set[:nginx][:log_dir] = "/var/log/nginx"
set[:nginx][:user] = "www-data"
set[:nginx][:binary] = "/usr/sbin/nginx"
end
default[:nginx][:gzip] = "on"
default[:nginx][:gzip_http_version] = "1.0"
default[:nginx][:gzip_comp_level] = "2"
default[:nginx][:gzip_proxied] = "any"
default[:nginx][:gzip_types] = [
"text/plain",
"text/html",
"text/css",
"application/x-javascript",
"text/xml",
"application/xml",
"application/xml+rss",
"text/javascript"
]
default[:nginx][:keepalive] = "on"
default[:nginx][:keepalive_timeout] = 65
default[:nginx][:worker_processes] = cpu[:total]
default[:nginx][:worker_connections] = 2048
default[:nginx][:server_names_hash_bucket_size] = 64
#
# Cookbook Name:: passenger-nginx
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
include_recipe "build-essential"
include_recipe "runit"
ree_version = node[:ree][:version]
nginx_version = node[:nginx][:version]
passenger_version = node[:passenger][:version]
log "using passenger version #{passenger_version}..."
remote_file "/tmp/ruby-enterprise-#{ree_version}.tar.gz" do
source "http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-#{ree_version}.tar.gz"
action :create_if_missing
end
node.set[:ree][:src_binary] = "/opt/ruby-enterprise-#{ree_version}/bin/ree-version"
node.set[:ruby_enterprise][:install_path] = "/opt/ruby-enterprise-#{ree_version}"
node.set[:nginx][:src_binary] = "/opt/nginx-#{nginx_version}/sbin/nginx"
node.set[:nginx][:daemon_disable] = true
log "node app environment: #{node.app_environment}"
if ["edge"].include?(node.app_environment)
['libssl-dev', 'libreadline6-dev', 'libcurl4-openssl-dev', 'libcurl4-gnutls-dev'].each do |pkg|
package pkg
end
else
['libssl-dev', 'libreadline5-dev', 'libcurl4-openssl-dev', 'libcurl4-gnutls-dev'].each do |pkg|
package pkg
end
end
bash "compile_ree_source" do
cwd "/tmp"
code <<-EOH
tar zxf ruby-enterprise-#{ree_version}.tar.gz
cd ruby-enterprise-#{ree_version} && ./installer -a /opt/ruby-enterprise-#{ree_version} --dont-install-useful-gems
EOH
creates node[:ree][:src_binary]
end
passenger_version = node[:passenger][:version]
ree_gem "passenger", :version => passenger_version
remote_file "/tmp/nginx-#{nginx_version}.tar.gz" do
source "http://nginx.org/download/nginx-#{nginx_version}.tar.gz"
action :create_if_missing
end
bash "install_passenger_nginx" do
cwd "/tmp"
code <<-EOH
tar zxf "nginx-#{nginx_version}.tar.gz"
cd /opt/ruby-enterprise-#{ree_version}/bin
./passenger-install-nginx-module --nginx-source-dir=/tmp/nginx-#{nginx_version} --auto --prefix=/opt/nginx-#{nginx_version} --extra-configure-flags='--prefix=/opt/nginx-#{nginx_version} --conf-path=/etc/nginx/nginx.conf --with-http_ssl_module --with-http_gzip_static_module'
EOH
creates "/opt/nginx-#{nginx_version}/sbin/nginx"
end
directory node[:nginx][:log_dir] do
mode 0755
owner node[:nginx][:user]
action :create
end
directory node[:nginx][:dir] do
owner "root"
group "root"
mode "0755"
end
directory "#{node[:nginx][:dir]}/conf.d" do
owner "root"
group "root"
mode "0755"
end
template "#{node[:nginx][:dir]}/conf.d/passenger.conf" do
source "passenger.conf.erb"
owner "root"
group "root"
mode "0755"
variables :ree_version => ree_version, :passenger_version => passenger_version
end
%w{ sites-available sites-enabled conf.d }.each do |dir|
directory "#{node[:nginx][:dir]}/#{dir}" do
owner "root"
group "root"
mode "0755"
end
end
%w{nxensite nxdissite}.each do |nxscript|
template "/usr/sbin/#{nxscript}" do
source "#{nxscript}.erb"
mode "0755"
owner "root"
group "root"
end
end
template "nginx.conf" do
path "#{node[:nginx][:dir]}/nginx.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode "0644"
end
cookbook_file "#{node[:nginx][:dir]}/mime.types" do
source "mime.types"
owner "root"
group "root"
mode "0644"
end
runit_service "nginx"
service "nginx" do
reload_command "sv hup nginx"
subscribes :restart, resources(:bash => "install_passenger_nginx")
subscribes :restart, resources(:cookbook_file => "#{node[:nginx][:dir]}/mime.types")
subscribes :reload, resources(:template => "nginx.conf")
subscribes :reload, resources(:template => "#{node[:nginx][:dir]}/conf.d/passenger.conf")
end
passenger_root /opt/ruby-enterprise-<%= @ree_version %>/lib/ruby/gems/1.8/gems/passenger-<%= @passenger_version %>;
passenger_ruby /opt/ruby-enterprise-<%= @ree_version %>/bin/ruby;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment