Reputation: 8118
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.
Upvotes: 3
Views: 8989
Reputation: 21226
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.Upvotes: 3