仅当使用包资源的:upgrade选项时如何重新启动服务

时间:2017-03-17 08:56:31

标签: chef

使用:升级选项中的资源,我希望确保我的服务重新启动仅适用于它实际上已升级。

这似乎不可能。有没有办法在该事件中触发部分代码?

# 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

2 个答案:

答案 0 :(得分:1)

使用通知

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

答案 1 :(得分:1)

您是否尝试过此通知顺序?

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