你知道为什么大厨这个片段失败了吗?
bash "Stopping service" do
user #{user}
cwd "~/"
code <<-EOH
killall -q java
EOH
endStacktrace如下:
================================================================================
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)发布于 2014-02-27 14:39:12
这可能意味着killall没有找到任何要杀死的java进程,并且使用状态代码1退出。
状态代码0表示成功,任何其他代码都是某种类型的失败。
如果您省略了-q标志,您将能够在Chef失败时看到命令的输出(或者您可以登录到该框并手动尝试),可能如下所示:
java: no process killed如果您绝对希望在任何情况下都不会失败,请在脚本的末尾添加一个exit 0:
code <<-EOH
killall java
exit 0
EOH发布于 2014-03-01 20:07:49
可以定义,使用returns参数接受哪些返回代码
bash "Stopping service" do
user #{user}
cwd "~/"
code <<-EOH
killall -q java
EOH
returns [0, 1]
endhttps://stackoverflow.com/questions/22070556
复制相似问题