0

关于为什么厨师中的这个片段失败的任何想法?

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

下面的堆栈跟踪:

================================================================================
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)
4

2 回答 2

2

可以定义returns,使用参数接受哪些返回码

bash "Stopping service" do
  user #{user}
  cwd "~/"
  code <<-EOH
    killall -q java
  EOH
  returns [0, 1]
end
于 2014-03-01T20:07:49.787 回答
2

这可能意味着killall没有找到任何java要杀死的进程,并以状态码退出1

状态代码0表示成功,任何其他代码都是某种失败。

如果您省略该-q标志,您将能够在 Chef 失败时看到命令的输出(或者您可以登录到该框并手动尝试),可能类似于:

java: no process killed

如果您绝对希望这在任何情况下都不会失败,exit 0请在脚本末尾添加 a:

code <<-EOH
  killall java
  exit 0
EOH
于 2014-02-27T14:39:12.797 回答