Chef Recipe; cannot be found in the resource collection

59 views Asked by At

I need help in resolving the issue with below chef recipe:

application = "edge-api"

remote_file "/usr/local/edge-api/{application}-{application_version}.jar" do
   source "{node.default["thecloud"]["repo_url"]}/{application}/{application}-{application_version}.jar"
   mode "0644"
   checksum application_sha256
   notifies :stop, "service[edge-api]", :delayed
   notifies :start, "service[edge-api]", :delayed
 end

 template "/usr/local/edge-api/application.properties" do
   owner "root"
   group "edge-api"
   mode "0640"
   variables(
     :clouddbIp => node['tcDatabase']['clouddb']['ip'],
     :clouddwhIp => node['tcDatabase']['clouddwh']['ip'],
     :elasticnodes => elasticnodes
   )
   notifies :stop, "service[edge-api]", :delayed
   notifies :start, "service[edge-api]", :delayed
 end

 template "/etc/init/edge-api.conf" do
   owner "root"
   group "edge-api"
   mode "0750"
   variables(
     :application_jar => "{application}-{application_version}.jar",
     :java_home => node['java']['8']['home']
   )
   notifies :stop, "service[edge-api]", :delayed
   notifies :start, "service[edge-api]", :delayed
 end

 template "/usr/local/edge-api/logback.xml" do
   owner "root"
   group "edge-api"
   mode "0640"
 end

 template '/etc/systemd/system/{application}.service' do
 source "{application}.service.erb"
 owner "root"
 group "root"
 mode "0644"
 notifies :run, 'execute[daemon-reload]', :immediately 
 end

 execute 'daemon-reload' do
   command 'systemctl daemon-reload'
   action :nothing
 end

I get this error:

> FATAL: Chef::Exceptions::ResourceNotFound: resource remote_file[/usr/local/edge-api/edge-api-0.1.9.jar] is configured to notify resource service[edge-api] with action stop, but service[edge-api] cannot be found in the resource collection. remote_file[/usr/local/edge-api/edge-api-0.1.9.jar] is defined in /var/chef/cache/cookbooks/edge-api/recipes/default.rb:40:in `from_file'

I am beginner in chef and trying to modify the above recipe. The requirement is to convert upstart to systemd as we are migrating from centos 6 to 7

1

There are 1 answers

1
seshadri_c On

The error is complaining about a missing resource declaration. In the question you have shown 1 resource which will cause the service "edge-api" to stop and start when the remote_file (jar file) changes. From the error it appears that you don't have a declaration for the service.

In that case, the below addition should help.

application = "edge-api"

remote_file "/usr/local/edge-api/#{application}-#{application_version}.jar" do
  source "#{node.default["thecloud"]["repo_url"]}/#{application}/#{application}-#{application_version}.jar"
  mode "0644"
  checksum application_sha256
  notifies :stop, "service[edge-api]", :delayed
  notifies :start, "service[edge-api]", :delayed
end

service application do
  action :nothing
end