server_maint 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/.gitignore +17 -0
  2. data/.gitmodules +6 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/lib/cookbooks/nginx/.gitignore +4 -0
  8. data/lib/cookbooks/nginx/CHANGELOG.md +63 -0
  9. data/lib/cookbooks/nginx/CONTRIBUTING +29 -0
  10. data/lib/cookbooks/nginx/Gemfile +3 -0
  11. data/lib/cookbooks/nginx/LICENSE +201 -0
  12. data/lib/cookbooks/nginx/README.md +211 -0
  13. data/lib/cookbooks/nginx/attributes/default.rb +70 -0
  14. data/lib/cookbooks/nginx/attributes/echo.rb +3 -0
  15. data/lib/cookbooks/nginx/attributes/geoip.rb +30 -0
  16. data/lib/cookbooks/nginx/attributes/naxsi.rb +24 -0
  17. data/lib/cookbooks/nginx/attributes/passenger.rb +7 -0
  18. data/lib/cookbooks/nginx/attributes/source.rb +37 -0
  19. data/lib/cookbooks/nginx/attributes/upload_progress.rb +23 -0
  20. data/lib/cookbooks/nginx/definitions/nginx_site.rb +35 -0
  21. data/lib/cookbooks/nginx/files/default/mime.types +73 -0
  22. data/lib/cookbooks/nginx/files/default/naxsi_core.rules +70 -0
  23. data/lib/cookbooks/nginx/files/default/tests/minitest/default_test.rb +12 -0
  24. data/lib/cookbooks/nginx/files/default/tests/minitest/helpers.rb +7 -0
  25. data/lib/cookbooks/nginx/files/default/tests/minitest/source_test.rb +9 -0
  26. data/lib/cookbooks/nginx/metadata.rb +95 -0
  27. data/lib/cookbooks/nginx/recipes/authorized_ips.rb +41 -0
  28. data/lib/cookbooks/nginx/recipes/commons.rb +23 -0
  29. data/lib/cookbooks/nginx/recipes/commons_conf.rb +39 -0
  30. data/lib/cookbooks/nginx/recipes/commons_dir.rb +39 -0
  31. data/lib/cookbooks/nginx/recipes/commons_script.rb +28 -0
  32. data/lib/cookbooks/nginx/recipes/default.rb +42 -0
  33. data/lib/cookbooks/nginx/recipes/http_echo_module.rb +46 -0
  34. data/lib/cookbooks/nginx/recipes/http_geoip_module.rb +117 -0
  35. data/lib/cookbooks/nginx/recipes/http_gzip_static_module.rb +23 -0
  36. data/lib/cookbooks/nginx/recipes/http_realip_module.rb +46 -0
  37. data/lib/cookbooks/nginx/recipes/http_ssl_module.rb +23 -0
  38. data/lib/cookbooks/nginx/recipes/http_stub_status_module.rb +36 -0
  39. data/lib/cookbooks/nginx/recipes/naxsi_module.rb +53 -0
  40. data/lib/cookbooks/nginx/recipes/ohai_plugin.rb +32 -0
  41. data/lib/cookbooks/nginx/recipes/passenger.rb +51 -0
  42. data/lib/cookbooks/nginx/recipes/source.rb +182 -0
  43. data/lib/cookbooks/nginx/recipes/upload_progress_module.rb +47 -0
  44. data/lib/cookbooks/nginx/templates/debian/nginx.init.erb +97 -0
  45. data/lib/cookbooks/nginx/templates/default/default-site.erb +11 -0
  46. data/lib/cookbooks/nginx/templates/default/modules/authorized_ip.erb +6 -0
  47. data/lib/cookbooks/nginx/templates/default/modules/http_geoip.conf.erb +4 -0
  48. data/lib/cookbooks/nginx/templates/default/modules/http_realip.conf.erb +4 -0
  49. data/lib/cookbooks/nginx/templates/default/modules/nginx_status.erb +14 -0
  50. data/lib/cookbooks/nginx/templates/default/modules/passenger.conf.erb +3 -0
  51. data/lib/cookbooks/nginx/templates/default/nginx.conf.erb +48 -0
  52. data/lib/cookbooks/nginx/templates/default/nginx.init.erb +92 -0
  53. data/lib/cookbooks/nginx/templates/default/nginx.pill.erb +15 -0
  54. data/lib/cookbooks/nginx/templates/default/nginx.sysconfig.erb +1 -0
  55. data/lib/cookbooks/nginx/templates/default/nxdissite.erb +29 -0
  56. data/lib/cookbooks/nginx/templates/default/nxensite.erb +38 -0
  57. data/lib/cookbooks/nginx/templates/default/plugins/nginx.rb.erb +66 -0
  58. data/lib/cookbooks/nginx/templates/default/sv-nginx-log-run.erb +2 -0
  59. data/lib/cookbooks/nginx/templates/default/sv-nginx-run.erb +3 -0
  60. data/lib/cookbooks/nginx/templates/ubuntu/nginx.init.erb +97 -0
  61. data/lib/cookbooks/nginx/test/kitchen/Kitchenfile +5 -0
  62. data/lib/cookbooks/sanitize/.gitignore +1 -0
  63. data/lib/cookbooks/sanitize/CHANGELOG.md +10 -0
  64. data/lib/cookbooks/sanitize/README.md +65 -0
  65. data/lib/cookbooks/sanitize/attributes/default.rb +1 -0
  66. data/lib/cookbooks/sanitize/libraries/default.rb +8 -0
  67. data/lib/cookbooks/sanitize/metadata.rb +12 -0
  68. data/lib/cookbooks/sanitize/recipes/default.rb +113 -0
  69. data/lib/cookbooks/sanitize/templates/default/port_ssh.erb +2 -0
  70. data/lib/server_maint/version.rb +3 -0
  71. data/lib/server_maint.rb +7 -0
  72. data/server_maint.gemspec +33 -0
  73. metadata +155 -0
@@ -0,0 +1,28 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: common/script
4
+ # Author:: AJ Christensen <aj@junglist.gen.nz>
5
+ #
6
+ # Copyright 2008-2012, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ %w(nxensite nxdissite).each do |nxscript|
22
+ template "/usr/sbin/#{nxscript}" do
23
+ source "#{nxscript}.erb"
24
+ mode "0755"
25
+ owner "root"
26
+ group "root"
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: default
4
+ # Author:: AJ Christensen <aj@junglist.gen.nz>
5
+ #
6
+ # Copyright 2008-2012, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ include_recipe 'nginx::ohai_plugin'
22
+
23
+ case node['nginx']['install_method']
24
+ when 'source'
25
+ include_recipe 'nginx::source'
26
+ when 'package'
27
+ case node['platform']
28
+ when 'redhat','centos','scientific','amazon','oracle'
29
+ include_recipe 'yum::epel'
30
+ end
31
+ package 'nginx'
32
+ service 'nginx' do
33
+ supports :status => true, :restart => true, :reload => true
34
+ action :enable
35
+ end
36
+ include_recipe 'nginx::commons'
37
+ end
38
+
39
+ service 'nginx' do
40
+ supports :status => true, :restart => true, :reload => true
41
+ action :start
42
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_echo_module
4
+ #
5
+ # Author:: Danial Pearce (<danial@cushycms.com>)
6
+ #
7
+ # Copyright 2012, CushyCMS
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ echo_src_filename = "echo-nginx-module-v#{node['nginx']['echo']['version']}.tar.gz"
23
+ echo_src_filepath = "#{Chef::Config['file_cache_path']}/#{echo_src_filename}"
24
+ echo_extract_path = "#{Chef::Config['file_cache_path']}/nginx_echo_module/#{node['nginx']['echo']['checksum']}"
25
+
26
+ remote_file echo_src_filepath do
27
+ source node['nginx']['echo']['url']
28
+ checksum node['nginx']['echo']['checksum']
29
+ owner 'root'
30
+ group 'root'
31
+ mode 0644
32
+ end
33
+
34
+ bash 'extract_http_echo_module' do
35
+ cwd ::File.dirname(echo_src_filepath)
36
+ code <<-EOH
37
+ mkdir -p #{echo_extract_path}
38
+ tar xzf #{echo_src_filename} -C #{echo_extract_path}
39
+ mv #{echo_extract_path}/*/* #{echo_extract_path}/
40
+ EOH
41
+
42
+ not_if { ::File.exists?(echo_extract_path) }
43
+ end
44
+
45
+ node.run_state['nginx_configure_flags'] =
46
+ node.run_state['nginx_configure_flags'] | ["--add-module=#{echo_extract_path}"]
@@ -0,0 +1,117 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_geoip_module
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ if node['platform'] == 'ubuntu'
23
+ package 'libtool'
24
+ end
25
+
26
+ country_dat = "#{node['nginx']['geoip']['path']}/GeoIP.dat"
27
+ country_src_filename = ::File.basename(node['nginx']['geoip']['country_dat_url'])
28
+ country_src_filepath = "#{Chef::Config['file_cache_path']}/#{country_src_filename}"
29
+ city_dat = nil
30
+ city_src_filename = ::File.basename(node['nginx']['geoip']['city_dat_url'])
31
+ city_src_filepath = "#{Chef::Config['file_cache_path']}/#{city_src_filename}"
32
+ geolib_filename = ::File.basename(node['nginx']['geoip']['lib_url'])
33
+ geolib_filepath = "#{Chef::Config['file_cache_path']}/#{geolib_filename}"
34
+
35
+ remote_file geolib_filepath do
36
+ source node['nginx']['geoip']['lib_url']
37
+ checksum node['nginx']['geoip']['lib_checksum']
38
+ owner "root"
39
+ group "root"
40
+ mode 0644
41
+ end
42
+
43
+ bash "extract_geolib" do
44
+ cwd ::File.dirname(geolib_filepath)
45
+ code <<-EOH
46
+ tar xzvf #{geolib_filepath} -C #{::File.dirname(geolib_filepath)}
47
+ cd GeoIP-#{node['nginx']['geoip']['lib_version']}
48
+ which libtoolize && libtoolize -f
49
+ ./configure
50
+ make && make install
51
+ EOH
52
+
53
+ creates "/usr/local/lib/libGeoIP.so.#{node['nginx']['geoip']['lib_version']}"
54
+ subscribes :run, resources(:remote_file => geolib_filepath)
55
+ end
56
+
57
+ directory node['nginx']['geoip']['path'] do
58
+ owner "root"
59
+ group "root"
60
+ mode 0755
61
+ end
62
+
63
+ remote_file country_src_filepath do
64
+ not_if do
65
+ File.exists?(country_src_filepath) &&
66
+ File.mtime(country_src_filepath) > Time.now - 86400
67
+ end
68
+ source node['nginx']['geoip']['country_dat_url']
69
+ checksum node['nginx']['geoip']['country_dat_checksum']
70
+ owner "root"
71
+ group "root"
72
+ mode 0644
73
+ end
74
+
75
+ bash "gunzip_geo_lite_country_dat" do
76
+ code <<-EOH
77
+ gunzip -c #{country_src_filepath} > #{country_dat}
78
+ EOH
79
+ creates country_dat
80
+ end
81
+
82
+ if node['nginx']['geoip']['enable_city']
83
+ city_dat = "#{node['nginx']['geoip']['path']}/GeoLiteCity.dat"
84
+
85
+ remote_file city_src_filepath do
86
+ not_if do
87
+ File.exists?(city_src_filepath) &&
88
+ File.mtime(city_src_filepath) > Time.now - 86400
89
+ end
90
+ source node['nginx']['geoip']['city_dat_url']
91
+ checksum node['nginx']['geoip']['city_dat_checksum']
92
+ owner "root"
93
+ group "root"
94
+ mode 0644
95
+ end
96
+
97
+ bash "gunzip_geo_lite_city_dat" do
98
+ code <<-EOH
99
+ gunzip -c #{city_src_filepath} > #{city_dat}
100
+ EOH
101
+ creates city_dat
102
+ end
103
+ end
104
+
105
+ template "#{node['nginx']['dir']}/conf.d/http_geoip.conf" do
106
+ source "modules/http_geoip.conf.erb"
107
+ owner "root"
108
+ group "root"
109
+ mode "0644"
110
+ variables(
111
+ :country_dat => country_dat,
112
+ :city_dat => city_dat
113
+ )
114
+ end
115
+
116
+ node.run_state['nginx_configure_flags'] =
117
+ node.run_state['nginx_configure_flags'] | ["--with-http_geoip_module", "--with-ld-opt='-Wl,-R,/usr/local/lib -L /usr/local/lib'"]
@@ -0,0 +1,23 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_gzip_static_module
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ node.run_state['nginx_configure_flags'] =
23
+ node.run_state['nginx_configure_flags'] | ["--with-http_gzip_static_module"]
@@ -0,0 +1,46 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_realip_module
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ # Documentation: http://wiki.nginx.org/HttpRealIpModule
23
+
24
+ # Currently only accepts X-Forwarded-For or X-Real-IP
25
+ node.default['nginx']['realip']['header'] = "X-Forwarded-For"
26
+ node.default['nginx']['realip']['addresses'] = ["127.0.0.1"]
27
+
28
+ service "nginx" do
29
+ supports :status => true, :restart => true, :reload => true
30
+ end
31
+
32
+ template "#{node['nginx']['dir']}/conf.d/http_realip.conf" do
33
+ source "modules/http_realip.conf.erb"
34
+ owner "root"
35
+ group "root"
36
+ mode "0644"
37
+ variables(
38
+ :addresses => node['nginx']['realip']['addresses'],
39
+ :header => node['nginx']['realip']['header']
40
+ )
41
+
42
+ notifies :reload, resources(:service => "nginx")
43
+ end
44
+
45
+ node.run_state['nginx_configure_flags'] =
46
+ node.run_state['nginx_configure_flags'] | ["--with-http_realip_module"]
@@ -0,0 +1,23 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_ssl_module
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ node.run_state['nginx_configure_flags'] =
23
+ node.run_state['nginx_configure_flags'] | ["--with-http_ssl_module"]
@@ -0,0 +1,36 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: http_stub_status_module
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ include_recipe "nginx::authorized_ips"
23
+
24
+ template "nginx_status" do
25
+ path "#{node['nginx']['dir']}/sites-available/nginx_status"
26
+ source "modules/nginx_status.erb"
27
+ owner "root"
28
+ group "root"
29
+ mode "0644"
30
+ notifies :reload, resources(:service => "nginx")
31
+ end
32
+
33
+ nginx_site "nginx_status"
34
+
35
+ node.run_state['nginx_configure_flags'] =
36
+ node.run_state['nginx_configure_flags'] | ["--with-http_stub_status_module"]
@@ -0,0 +1,53 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: naxsi_module
4
+ #
5
+ # Author:: Artiom Lunev (<artiom.lunev@gmail.com>)
6
+ #
7
+ # Copyright 2012, Artiom Lunev
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ cookbook_file "#{node['nginx']['dir']}/naxsi_core.rules" do
23
+ source "naxsi_core.rules"
24
+ owner "root"
25
+ group "root"
26
+ mode "0644"
27
+ notifies :reload, 'service[nginx]'
28
+ end
29
+
30
+ naxsi_src_filename = ::File.basename(node['nginx']['naxsi']['url'])
31
+ naxsi_src_filepath = "#{Chef::Config['file_cache_path']}/#{naxsi_src_filename}"
32
+ naxsi_extract_path = "#{Chef::Config['file_cache_path']}/nginx-naxsi-#{node['nginx']['naxsi']['version']}"
33
+
34
+ remote_file naxsi_src_filepath do
35
+ source node['nginx']['naxsi']['url']
36
+ checksum node['nginx']['naxsi']['checksum']
37
+ owner "root"
38
+ group "root"
39
+ mode 0644
40
+ end
41
+
42
+ bash "extract_naxsi_module" do
43
+ cwd ::File.dirname(naxsi_src_filepath)
44
+ code <<-EOH
45
+ mkdir -p #{naxsi_extract_path}
46
+ tar xzf #{naxsi_src_filename} -C #{naxsi_extract_path}
47
+ EOH
48
+
49
+ not_if { ::File.exists?(naxsi_extract_path) }
50
+ end
51
+
52
+ node.run_state['nginx_configure_flags'] =
53
+ ["--add-module=#{naxsi_extract_path}/naxsi-#{node['nginx']['naxsi']['version']}/naxsi_src"] | node.run_state['nginx_configure_flags']
@@ -0,0 +1,32 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: ohai_plugin
4
+ #
5
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
6
+ #
7
+ # Copyright 2012, Riot Games
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ template "#{node['ohai']['plugin_path']}/nginx.rb" do
23
+ source "plugins/nginx.rb.erb"
24
+ owner "root"
25
+ group "root"
26
+ mode 0755
27
+ variables(
28
+ :nginx_bin => node['nginx']['binary']
29
+ )
30
+ end
31
+
32
+ include_recipe "ohai"
@@ -0,0 +1,51 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: Passenger
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ #package 'libcurl4-openssl-dev' do
19
+ package 'ruby-devel' do
20
+ action :install
21
+ end
22
+
23
+ gem_package 'passenger' do
24
+ action :install
25
+ version node["nginx"]["passenger"]["version"]
26
+ end
27
+
28
+ node.default["nginx"]["passenger"]["version"] = "3.0.12"
29
+ node.default["nginx"]["passenger"]["root"] = "/usr/lib/ruby/gems/1.8/gems/passenger-3.0.12"
30
+ node.default["nginx"]["passenger"]["ruby"] = %x{which ruby}.chomp
31
+ node.default["nginx"]["passenger"]["max_pool_size"] = 10
32
+
33
+ service "nginx" do
34
+ supports :status => true, :restart => true, :reload => true
35
+ end
36
+
37
+ template "#{node["nginx"]["dir"]}/conf.d/passenger.conf" do
38
+ source "modules/passenger.conf.erb"
39
+ owner "root"
40
+ group "root"
41
+ mode "0644"
42
+ variables(
43
+ :passenger_root => node["nginx"]["passenger"]["root"],
44
+ :passenger_ruby => node["nginx"]["passenger"]["ruby"],
45
+ :passenger_max_pool_size => node["nginx"]["passenger"]["max_pool_size"]
46
+ )
47
+ notifies :reload, resources(:service => "nginx")
48
+ end
49
+
50
+ node.run_state[:nginx_configure_flags] =
51
+ node.run_state[:nginx_configure_flags] | ["--add-module=#{node["nginx"]["passenger"]["root"]}/ext/nginx"]
@@ -0,0 +1,182 @@
1
+ #
2
+ # Cookbook Name:: nginx
3
+ # Recipe:: source
4
+ #
5
+ # Author:: Adam Jacob (<adam@opscode.com>)
6
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
7
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
8
+ #
9
+ # Copyright 2009-2012, Opscode, Inc.
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+
24
+
25
+ nginx_url = node['nginx']['source']['url'] ||
26
+ "http://nginx.org/download/nginx-#{node['nginx']['version']}.tar.gz"
27
+
28
+ unless(node['nginx']['source']['prefix'])
29
+ node.set['nginx']['source']['prefix'] = "/opt/nginx-#{node['nginx']['version']}"
30
+ end
31
+ unless(node['nginx']['source']['conf_path'])
32
+ node.set['nginx']['source']['conf_path'] = "#{node['nginx']['dir']}/nginx.conf"
33
+ end
34
+ unless(node['nginx']['source']['default_configure_flags'])
35
+ node.set['nginx']['source']['default_configure_flags'] = [
36
+ "--prefix=#{node['nginx']['source']['prefix']}",
37
+ "--conf-path=#{node['nginx']['dir']}/nginx.conf"
38
+ ]
39
+ end
40
+ node.set['nginx']['binary'] = "#{node['nginx']['source']['prefix']}/sbin/nginx"
41
+ node.set['nginx']['daemon_disable'] = true
42
+
43
+ include_recipe "nginx::ohai_plugin"
44
+ include_recipe "nginx::commons_dir"
45
+ include_recipe "build-essential"
46
+
47
+ src_filepath = "#{Chef::Config['file_cache_path'] || '/tmp'}/nginx-#{node['nginx']['version']}.tar.gz"
48
+ packages = value_for_platform(
49
+ ["centos","redhat","fedora"] => {'default' => ['pcre-devel', 'openssl-devel']},
50
+ "default" => ['libpcre3', 'libpcre3-dev', 'libssl-dev']
51
+ )
52
+
53
+ packages.each do |devpkg|
54
+ package devpkg
55
+ end
56
+
57
+ remote_file nginx_url do
58
+ source nginx_url
59
+ checksum node['nginx']['source']['checksum']
60
+ path src_filepath
61
+ backup false
62
+ end
63
+
64
+ user node['nginx']['user'] do
65
+ system true
66
+ shell "/bin/false"
67
+ home "/var/www"
68
+ end
69
+
70
+ node.run_state['nginx_force_recompile'] = false
71
+ node.run_state['nginx_configure_flags'] =
72
+ node['nginx']['source']['default_configure_flags'] | node['nginx']['configure_flags']
73
+
74
+ node['nginx']['source']['modules'].each do |ngx_module|
75
+ include_recipe "nginx::#{ngx_module}"
76
+ end
77
+
78
+ configure_flags = node.run_state['nginx_configure_flags']
79
+ nginx_force_recompile = node.run_state['nginx_force_recompile']
80
+
81
+ bash "compile_nginx_source" do
82
+ cwd ::File.dirname(src_filepath)
83
+ code <<-EOH
84
+ tar zxf #{::File.basename(src_filepath)} -C #{::File.dirname(src_filepath)}
85
+ cd nginx-#{node['nginx']['version']} && ./configure #{node.run_state['nginx_configure_flags'].join(" ")}
86
+ make && make install
87
+ rm -f #{node['nginx']['dir']}/nginx.conf
88
+ EOH
89
+
90
+ not_if do
91
+ nginx_force_recompile == false &&
92
+ node.automatic_attrs['nginx'] &&
93
+ node.automatic_attrs['nginx']['version'] == node['nginx']['version'] &&
94
+ node.automatic_attrs['nginx']['configure_arguments'].sort == configure_flags.sort
95
+ end
96
+ end
97
+
98
+ node.run_state.delete(:nginx_configure_flags)
99
+ node.run_state.delete(:nginx_force_recompile)
100
+
101
+ case node['nginx']['init_style']
102
+ when "runit"
103
+ node.set['nginx']['src_binary'] = node['nginx']['binary']
104
+ include_recipe "runit"
105
+
106
+ runit_service "nginx"
107
+
108
+ service "nginx" do
109
+ supports :status => true, :restart => true, :reload => true
110
+ reload_command "[[ -f #{node['nginx']['pid']} ]] && kill -HUP `cat #{node['nginx']['pid']}` || true"
111
+ end
112
+ when "bluepill"
113
+ include_recipe "bluepill"
114
+
115
+ template "#{node['bluepill']['conf_dir']}/nginx.pill" do
116
+ source "nginx.pill.erb"
117
+ mode 0644
118
+ variables(
119
+ :working_dir => node['nginx']['source']['prefix'],
120
+ :src_binary => node['nginx']['binary'],
121
+ :nginx_dir => node['nginx']['dir'],
122
+ :log_dir => node['nginx']['log_dir'],
123
+ :pid => node['nginx']['pid']
124
+ )
125
+ end
126
+
127
+ bluepill_service "nginx" do
128
+ action [ :enable, :load ]
129
+ end
130
+
131
+ service "nginx" do
132
+ supports :status => true, :restart => true, :reload => true
133
+ reload_command "[[ -f #{node['nginx']['pid']} ]] && kill -HUP `cat #{node['nginx']['pid']}` || true"
134
+ action :nothing
135
+ end
136
+ else
137
+ node.set['nginx']['daemon_disable'] = false
138
+
139
+ template "/etc/init.d/nginx" do
140
+ source "nginx.init.erb"
141
+ owner "root"
142
+ group "root"
143
+ mode "0755"
144
+ variables(
145
+ :src_binary => node['nginx']['binary'],
146
+ :pid => node['nginx']['pid']
147
+ )
148
+ end
149
+
150
+ defaults_path = case node['platform']
151
+ when 'debian', 'ubuntu'
152
+ '/etc/default/nginx'
153
+ else
154
+ '/etc/sysconfig/nginx'
155
+ end
156
+ template defaults_path do
157
+ source "nginx.sysconfig.erb"
158
+ owner "root"
159
+ group "root"
160
+ mode "0644"
161
+ end
162
+
163
+ service "nginx" do
164
+ supports :status => true, :restart => true, :reload => true
165
+ action :enable
166
+ end
167
+ end
168
+
169
+ include_recipe "nginx::commons_script"
170
+ include_recipe "nginx::commons_conf"
171
+
172
+ cookbook_file "#{node['nginx']['dir']}/mime.types" do
173
+ source "mime.types"
174
+ owner "root"
175
+ group "root"
176
+ mode "0644"
177
+ notifies :reload, 'service[nginx]', :immediately
178
+ end
179
+
180
+ service "nginx" do
181
+ action :start
182
+ end