I have a chef execute resource in my recipe. When my chef-client runs this resource I get the error :
Expected process to exit with [0], but received ''
The resource :
execute "startHAPROXY" do
command "cd /home/#{node["haproxyUser"]}/haproxy && ./start.sh"
action :nothing
end
start.sh :
#!/bin/sh
kill -9 `ps -ef | grep haproxy | grep -v grep | awk '{print $2}'`
cd /home/lb/haproxy
/home/lb/haproxy/haproxy -f /home/lb/haproxy/haproxy.cfg
exit $?
when I run it manually (./start.sh; echo $?) it echos 0 but still when chef-client runs it, it fails.
Try this:
the recipe:
execute "startHAPROXY" do
command "./start.sh"
cwd "/home/#{node["haproxyUser"]}/haproxy"
action :nothing
end
start.sh:
#!/bin/bash -e
kill -9 `ps -ef | grep haproxy | grep -v grep | awk '{print $2}'`
cd /home/lb/haproxy
/home/lb/haproxy/haproxy -f /home/lb/haproxy/haproxy.cfg
cwd attribute of execute resource to change working directory.exit $? at the end as exit status of the script will automatically be the exit status of last command in it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With