I have created a LWRP (my first time) but it doesn’t seem to work as required. I am not sure if I am missing something or did something wrong. The opscode documentation is horrible. I have show my code below:
Provider
puts "FOO"
def restart_process
@svc = Chef::Resource::RestartProcesses.new(new_resource.name)
Chef::Log.debug("Restarting services according to the box")
notifies :run, resources(:execute => 'restart-storm')
end
puts "BAR"
action :restart do
execute 'restart-process' do
command <<-EOH
echo "-------Executing restart process--------"
#Some bash code
EOH
end
end
Resource
actions :restart
attribute :name, :kind_of => String, :name_attribute => true
def initialize(*args)
super
@action = :restart
end
Recipe from which the resource is called
template "#{install_dir}/####Something" do
source "someSource.erb"
variables(
###Some variables
)
notifies :run, 'nameOfCookbook_nameOfResource[process]'
end
nameOfCookbook_nameOfResource "process" do
action :nothing
end
The chef output shows FOO BAR but it doesn’t print anything inside my bash script. So it doesn’t run the bash. Any pointers?
Don’t you need to tell the instance to run the action :restart
like
I know you’ve set the initialize to say restart but I think passing action :nothing overwrites that so either force it to run when you want by following the above example or within the template part notify the actual action you want as such
By running this myself I saw an action of :nothing executed on the resource only. Not the default behaviour which in my case would have been :stop
By changing the notification to :stop it had the expected behaviour.
My understanding from the log is you have told your resource to run but it’s action is :nothing so it does nothing.