diff --git a/attributes/default.rb b/attributes/default.rb index 6605984..986806b 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/libraries/provider_td_rubygems.rb b/libraries/provider_td_rubygems.rb index 626484a..23e733b 100644 --- a/libraries/provider_td_rubygems.rb +++ b/libraries/provider_td_rubygems.rb @@ -25,6 +25,9 @@ class Package class TdRubygems < Chef::Provider::Package::Rubygems class TdGemEnvironment < AlternateGemEnvironment + def rubygems_version + Gem::VERSION + end end def initialize(new_resource, run_context = nil) @@ -40,6 +43,39 @@ def td_plugin_name "fluent-plugin-#{@new_resource.package_name}" end + def rubygems_version + 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? + 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 diff --git a/recipes/configure.rb b/recipes/configure.rb index 326b9e8..844ce25 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -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