gextra
gextra

Reputation: 8875

How to restart a service only if the :upgrade option of the package resource is used

Using the package resource in a chef recipe, with the :upgrade option, I want to ensure that my sercvice is restarted only when it is actually upgraded.

It does not appear this is possible. Is there a way to trigger a part of code in that event only?

# installs or updates package blahblah
package 'blahblah' do
  action :upgrade
end

# ensures the service is active
service 'blahblah' do
  action :start
end

# TO BE INVOKED ONLY the package is upgraded <<<============
service 'blahblah' do
  action :restart
end

Upvotes: 0

Views: 568

Answers (2)

gsone
gsone

Reputation: 1231

Have you tried this notifications sequence?

package 'blahblah' do
  action :upgrade
  notifies :restart, "service[blahblah]", :immediately
end

package 'blahblah' do
  action :install
  notifies :start, "service[blahblah]", :immediately
end

service 'blahblah' do
  action :nothing
end

Upvotes: 1

coderanger
coderanger

Reputation: 54191

Use a notification

package 'foo' do
  notifies :restart, 'service[foo]'
end 

Upvotes: 1

Related Questions