0

I am trying to install a jmeter service using nssm through cookbook.

but while running chef converge I am getting below error

FATAL: NoMethodError: undefined method `nssm' for cookbook: (chef-apply cookbook), recipe: (chef-apply recipe) :Chef::Recipe

here is the code

first I have installed the nssm to my local VM using below command in chef

  chocolatey_package 'nssm' do
    action    :install
    version  '2.24.101.20180116'
  end

then wants to install the jmeter service using nssm in chef

nssm 'jmeter_service' do
    program 'C:\ProgramData\chocolatey\lib\jmeter\tools\apache-jmeter-5.2.1\bin\jmeter-server.bat'
    parameters(
      AppDirectory: 'C:\ProgramData\chocolatey\lib\jmeter\tools\apache-jmeter-5.2.1\bin',
      AppStdout: 'C:\ProgramData\chocolatey\lib\jmeter\tools\apache-jmeter-5.2.1\bin\output.log',
      AppStderr: 'C:\ProgramData\chocolatey\lib\jmeter\tools\apache-jmeter-5.2.1\bin\error.log',
      #AppRotateFiles: 1
    )
    action %i[install start]
  end

Thanks in advance

Roshani
  • 51
  • 1
  • 8
  • Can you include relevant code from the cookbook/recipe in your question? A [minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) would be ideal. – seshadri_c Oct 11 '21 at 14:02
  • 1
    edit the question with the code – Roshani Oct 11 '21 at 14:41

1 Answers1

0

You seem to be using nssm supermarket cookbook, and the failure seems to indicate that you are running chef-apply, that can only run a single recipe.

But since you are trying to use a custom resource from another cookbook, you need to:

  1. Have a cookbook of your own
  2. Have the nssm (and its dependent windows cookbook) locally or on Chef server
  3. Define the dependency for the nssm cookbook in your cookbooks metadata.rb
  4. The chocolatey_package will install the nssm binary, which is different from nssm 'something' do

For an example of local setup:

  1. Download the nssm and windows cookbooks from Supermarket to cookbooks path

  2. Create another simple cookbook (e.g. mycookbook) with your recipe and metadata.rb

  3. Define dependency in metadata.rb:

    depends 'nssm', '~> 4.0.1'
    
  4. Optionally remove the chocolatey_package resource

  5. Run your cookbook with chef-client or chef-zero

    chef-client -z -r recipe[mycookbook]
    
seshadri_c
  • 6,906
  • 2
  • 10
  • 24