Sau*_*rav 2 chef-infra chef-recipe
我正在尝试使用bash属性时实现not_if
我正在尝试启动WAS部署管理器,但只有当它没有运行时,我使用一个简单的grep命令来获取正在进行的进程的pid,如下面的日志中所示
#Start the DMGR process
bash "start-dmgr" do
user "root"
code %(#{node[:websphere][:was][:was_installLocation]}/bin/startManager.sh)
not_if ("ps -f|grep dmgr|grep -v grep| awk {'print $2'}")
end
Run Code Online (Sandbox Code Playgroud)
以下是来自Chef客户端的调试日志
当DMGR过程*正在运行*
[2013-06-07T15:13:54-04:00] DEBUG: Skipping bash[was-install-fixpacks] due to not_if command `/apps/websphere/ws70/bin/versionInfo.sh -maintenancePackages | grep `echo /mnt/newInstallers/WAS/APARs/7.0.0.19-WS-WAS-IFPM73674.pak | awk -F '-' '{print $4}' | awk -F '.' '{print $1}'``
Recipe: WAS_NPE::was_startdmgr
* bash[start-dmgr] action run[2013-06-07T15:13:54-04:00] INFO: Processing bash[start-dmgr] action run (WAS_NPE::was_startdmgr line 2)
1973
(skipped due to not_if)
Run Code Online (Sandbox Code Playgroud)
当DMGR过程*未运行时*
[2013-06-07T15:31:03-04:00] DEBUG: Skipping bash[was-install-fixpacks] due to not_if command `/apps/websphere/ws70/bin/versionInfo.sh -maintenancePackages | grep `echo /mnt/newInstallers/WAS/APARs/7.0.0.19-WS-WAS-IFPM73674.pak | awk -F '-' '{print $4}' | awk -F '.' '{print $1}'``
Recipe: WAS_NPE::was_startdmgr
* bash[start-dmgr] action run[2013-06-07T15:31:03-04:00] INFO: Processing bash[start-dmgr] action run (WAS_NPE::was_startdmgr line 2)
(skipped due to not_if)
Run Code Online (Sandbox Code Playgroud)
不管它总是跳过什么情况,我错过了什么
RTM:https://docs.chef.io/resource_common.html
当not_if块返回false时执行资源.在bash中,false表示bash脚本的退出代码不为0.
确保您的bash脚本以不同的退出代码退出.您可以在没有awk的情况下尝试:
ps -f | grep -v grep | grep dmgr
Run Code Online (Sandbox Code Playgroud)
因为当没有找到匹配时,grep以1退出.