最小化从厨师通知中重新启动服务? [英] Minimize service restarts from chef notifications?

查看:46
本文介绍了最小化从厨师通知中重新启动服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的配方具有重要的属性,其结构如下:

Currently my recipe with attributes that matter is structured like this:

service 'myservice' do
  action :nothing
  supports :status => true, :start => true, :stop => true, :restart => true
end

package 'packagename' do
  ...
end

template 'configfile1'
  notifies :restart, 'service[myservice]'
end
...
template 'configfileN'
  notifies :restart, 'service[myservice]'
end

execute "a command from package which generates and enables the init script" do
  notifies :start, 'service[myservice]', :immediately
end

execute "a command that should run once every time, that requires service to be running"

这样做,我们确保服务的初始启动具有配置文件,在每次运行期间,该服务均在第二个执行块中运行,并且如果有任何配置文件发生更改,我们将重新启动服务以获取更改.

By doing this, we ensure that the initial start of the service has the config files, during every run the service is running for the second execute block, and if any config file changes, we restart the service to pick up the changes.

但是,如果厨师运行发生在服务的初始状态停止的位置(例如,在第一次运行时或发生了某些不良情况),并且配置文件已更改(特别是在第一次运行时,但是其他情况下可能会更改)运行),第一个execute块将使服务以正确的配置文件启动,然后在运行结束时,服务将不必要地重新启动.(当然,假设初始启动后的资源不会导致服务重启)

However, If a chef run occurs where the initial state of the service is stopped, (such as on the first run or if something bad happened), and config files have changed (notably on the first run, but possible for other runs), the first execute block will cause the service to start with the correct configuration files already in place, then at the end of the run, the service will restart unnecessarily. (Assume of course that resources after the initial start do not cause a restart of the service)

更改通知的目标操作似乎不起作用(因为立即通知仍会立即发生,然后延迟通知仍会发生),而且除此之外也不正确.

Changing the target action of notifications doesn't seem to work (as immediate notifications will still happen immediately, then delayed notifications still happen), and besides wouldn't be correct.

我们也不能将第二个执行订阅到服务启动,因为如果它已经在运行,我们最终将不执行它.

Also we can't subscribe the 2nd execute to the service start since if it's already running, we would wind up not executing it.

这是非常挑剔的,但是有没有可以遵循的更好的模式来最大程度地减少服务在初次运行时的重启?还是一种在采取特定措施时取消延迟通知的机制?

It is very nit picky, but is there a better pattern that could be followed to minimize restarts of a service for the initial run? Or a mechanism to cancel delayed notifications when a particular action is taken?

推荐答案

我使用了一个标志文件来实现这一目标.

I used a flag file to achieve this.

像下面的"apt-get update"一样,不会执行一次.

Like below "apt-get update" is not executed once.

cookbook_file '/etc/apt/sources.list.d/maven.list' do
  source "repo_files/ubuntu_maven.list"
  cookbook "fluig-files"
  mode 0644
  notifies :run, "execute[should_update_repo]", :immediately
end

cookbook_file '/etc/apt/sources.list.d/couchbase.list' do
  source "repo_files/ubuntu_couchbase.list"
  cookbook "fluig-files"
  mode 0644
  notifies :run, "execute[should_update_repo]", :immediately
end

execute "apt-key couchbase" do
  command "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A3FAA648D9223EDA"
  action :run
  not_if "apt-key list | grep couchbase"
  notifies :run, "execute[should_update_repo]", :immediately
end

execute "should_update_repo" do
  command "touch /tmp/should_update_repo"
  action :nothing
end

# Update system
execute "apt-get update" do
  command "rm -rf /tmp/should_update_repo && apt-get update"
  action :run
  only_if "test -f /tmp/should_update_repo"
end

这篇关于最小化从厨师通知中重新启动服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆