Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
}
default["td_agent"]["yum_amazon_releasever"] = "$releasever"
default['td_agent']['skip_repository'] = false
if node["td_agent"]["version"].to_i < 4
default["td_agent"]["restart_command"] = "sudo /etc/init.d/td-agent restart || sudo /etc/init.d/td-agent start"
end
36 changes: 36 additions & 0 deletions libraries/provider_td_rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Package
class TdRubygems < Chef::Provider::Package::Rubygems

class TdGemEnvironment < AlternateGemEnvironment
def rubygems_version
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get your intention to override the inherited rubygems_version here 🤔

https://github.com/chef/chef/blob/3f35e622fd9fc612bff3e5403e737f012aa9bd66/lib/chef/provider/package/rubygems.rb#L304-L306

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in chef12 doesn't exists (still used by AWS Opsworks service)

Gem::VERSION
end
end

def initialize(new_resource, run_context = nil)
Expand All @@ -40,6 +43,39 @@ def td_plugin_name
"fluent-plugin-#{@new_resource.package_name}"
end

def rubygems_version
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have to have this method definition if we use TdGemEnvironment properly 🤔 I couldn't get your intention to define multiple rubygems_version in multiple places.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not expert, maybe for the same reason because in old chef version doesn't exists? but i'm opened to changes

shell_out!("#{gem_binary_path} --version").stdout.chomp
end

def install_via_gem_command(name, version)
Chef::Log.debug("Using #{rdoc_string}")
if @new_resource.source =~ /\.gem$/i
name = @new_resource.source
elsif @new_resource.clear_sources
src = " --clear-sources"
src << (@new_resource.source && " --source=#{@new_resource.source}" || "")
else
src = @new_resource.source && " --source=#{@new_resource.source} --source=#{Chef::Config[:rubygems_url]}"
end
if !version.nil? && version.length > 0
shell_out_with_timeout!("#{gem_binary_path} install #{name} -q #{rdoc_string} -v \"#{version}\"#{src}#{opts}", :env => nil)
else
shell_out_with_timeout!("#{gem_binary_path} install \"#{name}\" -q #{rdoc_string} #{src}#{opts}", :env => nil)
end
end

def rdoc_string
if needs_nodocument?
"--no-document"
else
"--no-rdoc --no-ri"
end
end

def needs_nodocument?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your intention to override needs_nodocument here? The only difference between 2 implementations are use of rubygems_version vs. gem_env.rubygems_version. This could mean that if TdGemEnvironment defines proper rubygems_version, we don't have to override this method here as per my understanding.

https://github.com/chef/chef/blob/3f35e622fd9fc612bff3e5403e737f012aa9bd66/lib/chef/provider/package/rubygems.rb#L633-L635

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason this doesn't exists on chef 12/13

Gem::Requirement.new(">= 3.0.0.beta1").satisfied_by?(Gem::Version.new(rubygems_version))
end

def td_gem_binary_path
if major && major != '1'
# td-agent 2.x or later works with /opt
Expand Down
2 changes: 1 addition & 1 deletion recipes/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

service "td-agent" do
supports :restart => true, :reload => (reload_action == :reload), :status => true
restart_command "/etc/init.d/td-agent restart || /etc/init.d/td-agent start"
restart_command node["td_agent"]["restart_command"]
action [ :enable, :start ]
end

Expand Down