/
source.rb
170 lines (146 loc) · 4.11 KB
/
source.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#
# Cookbook Name:: nginx
# Recipe:: source
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Joshua Timberman (<joshua@opscode.com>)
#
# 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] = true
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
case node[:nginx][:init_style]
when "runit"
include_recipe "runit"
service "nginx" do
subscribes :restart, resources(:bash => "compile_nginx_source")
end
when "bluepill"
node.set[:nginx][:daemon_disable] = false
include_recipe "bluepill"
template "#{node['bluepill']['conf_dir']}/nginx.pill" do
source "nginx.pill.erb"
mode 0644
variables(
:working_dir => node[:nginx][:install_path],
:src_binary => node[:nginx][:src_binary],
:nginx_dir => node[:nginx][:dir],
:log_dir => node[:nginx][:log_dir]
)
end
bluepill_service "nginx" do
action [ :enable, :load, :start ]
subscribes :restart, resources(:bash => "compile_nginx_source")
end
service "nginx" do
action :nothing
end
else
#install init db script
template "/etc/init.d/nginx" do
source "nginx.init.erb"
owner "root"
group "root"
mode "0755"
end
#install sysconfig file (not really needed but standard)
template "/etc/sysconfig/nginx" do
source "nginx.sysconfig.erb"
owner "root"
group "root"
mode "0644"
end
#register service
service "nginx" do
supports :status => true, :restart => true, :reload => true
action :enable
subscribes :restart, resources(:bash => "compile_nginx_source")
end
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"
notifies :restart, resources(:service => "nginx"), :immediately
end
cookbook_file "#{node[:nginx][:dir]}/mime.types" do
source "mime.types"
owner "root"
group "root"
mode "0644"
notifies :restart, resources(:service => "nginx"), :immediately
end