我的chef
中有execute
resource
recipe
。当我的chef-client
运行此资源时,我收到错误:
Expected process to exit with [0], but received ''
资源:
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 $?
当我手动运行它(./start.sh; echo $?
)时,它会回显0
,但当chef-client
运行它时,它会失败。
答案 0 :(得分:2)
试试这个:
食谱:
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
资源的execute
属性来更改工作目录。exit $?
,因为脚本的退出状态将自动成为其中最后一个命令的退出状态。