Question

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.

Was it helpful?

Solution

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
  1. You should better use cwd attribute of execute resource to change working directory.
  2. Changed script to "bash" and added "-e" for it to fail on the first error it encounters.
  3. You don't need exit $? at the end as exit status of the script will automatically be the exit status of last command in it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top