Skip to content

Commit

Permalink
Use a proper name property instead of modify the name property
Browse files Browse the repository at this point in the history
Chef gets kinda made when you try to override the name directly.

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Feb 19, 2018
1 parent b2c7051 commit 9e2c641
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Enable or disable a Stream Block in `#{node['nginx']['dir']}/streams-available`

### Properties:

- `name` - (optional) Name of the stream to enable.
- `stream_name` - (optional) Name of the stream to enable.
- `template` - (optional) Path to the source for the `template` resource.
- `variables` - (optional) Variables to be used with the `template` resource

Expand Down
21 changes: 11 additions & 10 deletions resources/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,45 @@
# 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.name}") do
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.name}" do
command "#{node['nginx']['script_dir']}/nxenstream #{new_resource.name}"
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.name}") ||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/000-#{new_resource.name}")
::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.name}" do
command "#{node['nginx']['script_dir']}/nxdisstream #{new_resource.name}"
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.name}") ||
::File.symlink?("#{node['nginx']['dir']}/streams-enabled/000-#{new_resource.name}")
::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.name == 'default' && ::File.exist?('/etc/nginx/conf.d/default.conf') # ~FC023
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'
Expand Down

0 comments on commit 9e2c641

Please sign in to comment.