我的情况是,Chef 可能会启动一项服务 (postgres),但随后可能会在带外停止。我想要一个后续的 Chef 运行来导致服务运行。我试过这个:
service "postgresql" do
action :start
end
Run Code Online (Sandbox Code Playgroud)
但它没有效果,(up to date)
大概是因为 Chef 知道它已经启动并且无法判断它已经停止。(可能是由于service ... status
此服务的行为方式?)如果我这样写:
# anti-pattern warning!
execute "force-start-postgresql" do
command "service postgresql start || /etc/init.d/postgresql start"
action :run
end
Run Code Online (Sandbox Code Playgroud)
我得到了想要的行为。也action :restart
让它运行。然而,由于可移植性,这些看起来像是反模式(并且在后一种情况下可能会在再次启动之前停止它)。
那么,我如何告诉 Chef 强制启动该服务,即使它认为它已经在运行呢?
这是使用由 OpsCode 托管的 Chef 11.6 和默认的 postgresql 配方。(注意这很相似,但我认为与如何在 Chef 中强制对“最新”资源执行操作不完全相同?。)
---编辑(在 jtimberland 帖子后澄清)---
在-l debug
这里显示:
DEBUG: service[postgresql] supports status, running
DEBUG: service[postgresql] is running
Run Code Online (Sandbox Code Playgroud)
即使它没有运行。所以这听起来像是一个错误,我对此很感兴趣。但是,我主要对是否有办法告诉厨师“始终调用服务启动命令,跳过状态检查”感兴趣。这就是这里的问题。
(我不是专家,但我认为确保服务运行的最便携方法是启动服务,这几乎总是幂等的。OTOH检查 …