djoos-cookbooks / newrelic

Development repository for the newrelic cookbook
https://supermarket.chef.io/cookbooks/newrelic
MIT License
143 stars 245 forks source link

java_agent provider uses invalid setter #190

Closed martinb3 closed 9 years ago

martinb3 commented 9 years ago

It appears to be illegal to set resource values during the provider execution:

================================================================================
    Error executing action `install` on resource 'newrelic_agent_java[Install]'
    ================================================================================

    NoMethodError
    -------------
    undefined method `app_name=' for Chef::Resource::NewrelicAgentJava

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/newrelic/providers/agent_java.rb:66:in `generate_agent_config'
    /var/chef/cache/cookbooks/newrelic/providers/agent_java.rb:20:in `block in class_from_file'

agent_java.rb:66 (second line):

def generate_agent_config
  new_resource.app_name = node['hostname'] if new_resource.app_name.nil?

  template "#{new_resource.install_dir}/newrelic.yml" do
    cookbook new_resource.template_cookbook
    source new_resource.template_source
    owner 'root'
    group 'root'
    mode 0644
    variables(
      :resource => new_resource
    )
    action :create
  end
end
djoos commented 9 years ago

Hi @martinb3,

as the template can handle a nil app_name, I actually wondered why it has to be set to the node['hostname']; there doesn't seem to be any reason for it, so I've taken that logic out. If someone wants app_name to be node['hostname'], they can set it on the LWRP or set the attribute when using the java_agent-recipe...

Hope this helps!

Kind regards, David

murashid786 commented 6 years ago

Hi, I am getting the same error. My environment info is listed below: Centos 7.4 Chef Development Kit Version: 2.4.17 chef-client version: 13.6.4 delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427) berks version: 6.3.1 kitchen version: 1.19.2 inspec version: 1.45.13

I used berks and I am running the java_agent with the following command: sudo chef-client --local-mode --runlist 'recipe[newrelic::java_agent]'

[2018-02-12T20:06:41+00:00] INFO: Running queued delayed notifications before re-raising exception

================================================================================
Error executing action `install` on resource 'newrelic_agent_java[Install]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
execute[newrelic_install_newrelic.jar] (/home/centos/.chef/local-mode-cache/cache/cookbooks/newrelic/providers/agent_java.rb line 110) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of sudo java -jar newrelic.jar -s /opt/newrelic/java install ----
STDOUT:
STDERR: sudo: sorry, you must have a tty to run sudo
---- End output of sudo java -jar newrelic.jar -s /opt/newrelic/java install ----
Ran sudo java -jar newrelic.jar -s /opt/newrelic/java install returned 1

Resource Declaration:
---------------------
# In /home/centos/.chef/local-mode-cache/cache/cookbooks/newrelic/recipes/java_agent.rb

  8: newrelic_agent_java 'Install' do
  9:   license NewRelic.application_monitoring_license(node)
djoos commented 6 years ago

Hi @murashid786,

the error flagged in this thread (NoMethodError - undefined methodapp_name=' for Chef::Resource::NewrelicAgentJava) is not the same as the error you are getting, ie.STDERR: sudo: sorry, you must have a tty to run sudo`... For the issue you are getting, it might be worth looking into how you are handling your sudoers in your setup.

Hope this helps! David