Reputation: 424
I am trying to implement not_if when using a bash attribute
I am trying to start the WAS Deployment manager but only if its not running, i am using a simple grep command to get the pid of the process which is wokring as you can see in the log below
#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
Below are the debug logs from chef client
When the DMGR process is *running*
[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)
When the DMGR process is *NOT running*
[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)
No matter what the case its always skipping, what is that i am missing out
Upvotes: 2
Views: 7775
Reputation: 21206
RTM: https://docs.chef.io/resource_common.html
The resource is executed when not_if block returns false. In bash world false means that the exit code of bash script is not 0.
Make sure your bash script exits with different exit codes. You may try it without awk:
ps -f | grep -v grep | grep dmgr
Because grep exits with 1, when no match is found.
Upvotes: 9