Pergunta

Any ideas on why this snippet in Chef fails?

bash "Stopping service" do
  user #{user}
  cwd "~/"
  code <<-EOH
    killall -q java
  EOH
end

Stacktrace below:

================================================================================
Error executing action `run` on resource 'bash[Stopping service]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" ----
STDOUT: 
STDERR: 
---- End output of "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" ----
Ran "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" returned 1


Resource Declaration:
---------------------
# In /home/mcamilleri/cookbooks/stuff/recipes/deploy_jar.rb

 13: bash "Stopping service" do
 14:   user #{user}
 15:   cwd "~/"
 16:   code <<-EOH
 17:     killall -q java
 18:   EOH
 19: end
 20: 



Compiled Resource:
------------------
# Declared in /home/mcamilleri/cookbooks/stuff/recipes/deploy_jar.rb:13:in `from_file'

bash("Stopping service") do
  cookbook_name :stuff
  action "run"
  retry_delay 2
  recipe_name "deploy_jar"
  interpreter "bash"
  code "    killall -q java\n"
  backup 5
  retries 0
  command "\"bash\"  \"/tmp/chef-script20140227-3331-1te6gkd-0\""
  cwd "~/"
  returns 0
end




Running handlers:
[2014-02-27T05:16:17-08:00] ERROR: Running exception handlers
Running handlers complete

[2014-02-27T05:16:17-08:00] ERROR: Exception handlers complete
[2014-02-27T05:16:17-08:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 0.629887 seconds
[2014-02-27T05:16:17-08:00] ERROR: bash[Stopping service] (stuff::deploy_jar line 13) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" ----
STDOUT: 
STDERR: 
---- End output of "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" ----
Ran "bash"  "/tmp/chef-script20140227-3331-1te6gkd-0" returned 1
[2014-02-27T05:16:17-08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Foi útil?

Solução

It probably means that killall didn't find any java processes to kill, and exited with status code 1.

Status code 0 means success, any other code is some sort of failure.

If you omit the -q flag you'll be able to see the output of the command when Chef fails (or you can login to the box and try it manually), probably something like:

java: no process killed

If you absolutely want this not to fail in any circumstance, add a exit 0 to the end of your script:

code <<-EOH
  killall java
  exit 0
EOH

Outras dicas

You can define, what return codes are accepted using the returns parameter

bash "Stopping service" do
  user #{user}
  cwd "~/"
  code <<-EOH
    killall -q java
  EOH
  returns [0, 1]
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top