# # Cookbook Name:: nginx # Recipe:: source # # Author:: Adam Jacob () # Author:: Joshua Timberman () # Author:: Alex Redington () # # Copyright 2009-2011, Opscode, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # include_recipe "build-essential" 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 nginx_version = node[:nginx][:version] node.set[:nginx][:install_path] = "/opt/nginx-#{nginx_version}" node.set[:nginx][:src_binary] = "#{node[:nginx][:install_path]}/sbin/nginx" node.set[:nginx][:daemon_disable] = false node.set[:nginx][:configure_flags] = [ "--prefix=#{node[:nginx][:install_path]}", "--conf-path=#{node[:nginx][:dir]}/nginx.conf", "--with-http_ssl_module", "--with-http_gzip_static_module" ] configure_flags = node[:nginx][:configure_flags].join(" ") remote_file "#{Chef::Config[:file_cache_path]}/nginx-#{nginx_version}.tar.gz" do source "http://nginx.org/download/nginx-#{nginx_version}.tar.gz" action :create_if_missing end bash "compile_nginx_source" do cwd Chef::Config[:file_cache_path] code <<-EOH tar zxf nginx-#{nginx_version}.tar.gz cd nginx-#{nginx_version} && ./configure #{configure_flags} make && make install EOH creates node[:nginx][:src_binary] end user node[:nginx][:user] do system true shell "/bin/false" home "/var/www" 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 template "/etc/init.d/nginx" do source "nginx.init.erb" owner "root" group "root" mode "0755" end #register service service "nginx" do supports :status => true, :restart => true, :reload => true action :enable 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" notifies :start, resources(:service => "nginx"), :immediately end