Switch back to the upstream nginx cookbook
chef_nginx is deprecated
This commit is contained in:
36
cookbooks/nginx/resources/cleanup_runit.rb
Normal file
36
cookbooks/nginx/resources/cleanup_runit.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# Copyright:: 20017-2018, Chef Software, 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.
|
||||
#
|
||||
action :cleanup do
|
||||
# remove old init script link
|
||||
file 'remove symlinked runit init script' do
|
||||
path '/etc/init.d/nginx'
|
||||
manage_symlink_source false # nuke the link not the runit binary
|
||||
action :delete
|
||||
only_if { ::File.exist?('/etc/init.d/nginx') && ::File.symlink?('/etc/init.d/nginx') && ::File.realpath('/etc/init.d/nginx') == '/usr/bin/sv' }
|
||||
end
|
||||
|
||||
execute 'kill old nginx process' do
|
||||
command 'pkill nginx'
|
||||
returns [0, 1] # ignores failures
|
||||
not_if { !::File.exist?('/etc/sv/nginx/supervise/pid') || ::File.zero?('/etc/sv/nginx/supervise/pid') }
|
||||
end
|
||||
|
||||
# remove the old service configs
|
||||
directory '/etc/sv/nginx' do
|
||||
recursive true
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
79
cookbooks/nginx/resources/site.rb
Normal file
79
cookbooks/nginx/resources/site.rb
Normal file
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# Cookbook:: nginx
|
||||
# Resource:: site
|
||||
#
|
||||
# Author:: AJ Christensen <aj@junglist.gen.nz>
|
||||
# Author:: Tim Smith <tsmith@chef.io>
|
||||
#
|
||||
# Copyright:: 2008-2017, Chef Software, 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.
|
||||
#
|
||||
|
||||
property :site_name, String, name_property: true
|
||||
property :variables, Hash, default: {}
|
||||
property :cookbook, String
|
||||
property :template, [String, Array]
|
||||
property :enable, [String, true, false]
|
||||
|
||||
action :enable do
|
||||
# this is pretty evil, but gives us backwards compat with the old
|
||||
# definition where there was an enable property vs a true action
|
||||
if new_resource.enable
|
||||
Chef::Log.warn('The "enable" property in nginx_site is deprecated. Use "action :enable" instead.')
|
||||
elsif new_resource.enable == false || new_resource.enable == 'false'
|
||||
Chef::Log.warn('The "enable" property in nginx_site is deprecated. Use "action :disable" instead.')
|
||||
action_disable
|
||||
return # don't perform the actual enable action afterwards
|
||||
end
|
||||
|
||||
if new_resource.template
|
||||
# use declare_resource so we can have a property also named template
|
||||
declare_resource(:template, "#{node['nginx']['dir']}/sites-available/#{new_resource.site_name}") do
|
||||
source new_resource.template
|
||||
cookbook new_resource.cookbook
|
||||
variables(new_resource.variables)
|
||||
notifies :reload, 'service[nginx]'
|
||||
end
|
||||
end
|
||||
|
||||
execute "nxensite #{new_resource.site_name}" do
|
||||
command "#{node['nginx']['script_dir']}/nxensite #{new_resource.site_name}"
|
||||
notifies :reload, 'service[nginx]'
|
||||
not_if do
|
||||
::File.symlink?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.site_name}") ||
|
||||
::File.symlink?("#{node['nginx']['dir']}/sites-enabled/000-#{new_resource.site_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :disable do
|
||||
execute "nxdissite #{new_resource.site_name}" do
|
||||
command "#{node['nginx']['script_dir']}/nxdissite #{new_resource.site_name}"
|
||||
notifies :reload, 'service[nginx]'
|
||||
only_if do
|
||||
::File.symlink?("#{node['nginx']['dir']}/sites-enabled/#{new_resource.site_name}") ||
|
||||
::File.symlink?("#{node['nginx']['dir']}/sites-enabled/000-#{new_resource.site_name}")
|
||||
end
|
||||
end
|
||||
|
||||
# The nginx.org packages store the default site at /etc/nginx/conf.d/default.conf and our
|
||||
# normal script doesn't disable these.
|
||||
if new_resource.site_name == 'default' && ::File.exist?('/etc/nginx/conf.d/default.conf') # ~FC023
|
||||
execute 'Move nginx.org package default site config to sites-available' do
|
||||
command "mv /etc/nginx/conf.d/default.conf #{node['nginx']['dir']}/sites-available/default"
|
||||
user 'root'
|
||||
notifies :reload, 'service[nginx]'
|
||||
end
|
||||
end
|
||||
end
|
||||
65
cookbooks/nginx/resources/stream.rb
Normal file
65
cookbooks/nginx/resources/stream.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
#
|
||||
# Cookbook:: nginx
|
||||
# Resource:: stream
|
||||
#
|
||||
# Copyright:: 2017-2018, David Sieciński
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
property :stream_name, String, name_property: true
|
||||
property :variables, Hash, default: {}
|
||||
property :cookbook, String
|
||||
property :template, [String, Array]
|
||||
|
||||
action :enable do
|
||||
if new_resource.template
|
||||
# use declare_resource so we can have a property also named template
|
||||
declare_resource(:template, "#{node['nginx']['dir']}/streams-available/#{new_resource.stream_name}") do
|
||||
source new_resource.template
|
||||
cookbook new_resource.cookbook
|
||||
variables(new_resource.variables)
|
||||
notifies :reload, 'service[nginx]'
|
||||
end
|
||||
end
|
||||
|
||||
execute "nxenstream #{new_resource.stream_name}" do
|
||||
command "#{node['nginx']['script_dir']}/nxenstream #{new_resource.stream_name}"
|
||||
notifies :reload, 'service[nginx]'
|
||||
not_if do
|
||||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/#{new_resource.stream_name}") ||
|
||||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/000-#{new_resource.stream_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :disable do
|
||||
execute "nxdisstream #{new_resource.stream_name}" do
|
||||
command "#{node['nginx']['script_dir']}/nxdisstream #{new_resource.stream_name}"
|
||||
notifies :reload, 'service[nginx]'
|
||||
only_if do
|
||||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/#{new_resource.stream_name}") ||
|
||||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/000-#{new_resource.stream_name}")
|
||||
end
|
||||
end
|
||||
|
||||
# The nginx.org packages store the default stream at /etc/nginx/conf.d/default.conf and our
|
||||
# normal script doesn't disable these.
|
||||
if new_resource.stream_name == 'default' && ::File.exist?('/etc/nginx/conf.d/default.conf') # ~FC023
|
||||
execute 'Move nginx.org package default stream config to streams-available' do
|
||||
command "mv /etc/nginx/conf.d/default.conf #{node['nginx']['dir']}/streams-available/default"
|
||||
user 'root'
|
||||
notifies :reload, 'service[nginx]'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user