关于为什么这个Chef片段失败的想法?
bash "Stopping service" do
user #{user}
cwd "~/"
code <<-EOH
killall -q java
EOH
end
下面的Stacktrace:
================================================================================
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)
答案 0 :(得分:3)
您can define,使用returns
参数
bash "Stopping service" do
user #{user}
cwd "~/"
code <<-EOH
killall -q java
EOH
returns [0, 1]
end
答案 1 :(得分:2)
这可能意味着killall
没有找到要杀死的java
个进程,并退出状态代码1
。
状态代码0
表示成功,任何其他代码都是某种失败。
如果省略-q
标志,当Chef失败时您可以看到命令的输出(或者您可以登录该框并手动尝试),可能是这样的:
java: no process killed
如果您绝对希望在任何情况下都不会失败,请在脚本的末尾添加exit 0
:
code <<-EOH
killall java
exit 0
EOH