Ric*_*ich 5 ruby deployment capistrano capistrano3 sshkit
在Capistrano 2.x中你可以简单地添加:on_error =>:像这样继续:
task :bad_script, :on_error => :continue do
my_error = capture('/path/to/tomcat/shutdown.sh')
end
Run Code Online (Sandbox Code Playgroud)
我没有看到任何方法在Capistrano 3.x或ssh-kit(底层通信)中做到这一点.任何帮助将不胜感激.
task :bad_script do
server_is_down
on roles :all do
begin
server_is_down = capture('/path/to/tomcat/shutdown.sh')
rescue
#do something if server_is_down has the correct text
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我已尝试在开始/救援块中包围新方法,但这只会阻止它出错,但它不会返回错误的输出.
我仍然想知道如何做到这一点,但我想出了一个方法来解决我的一个案例,那就是如果失败就设置服务器.
task :bad_script do
server_is_down = false
on roles :all do
begin
execute('/path/to/tomcat/shutdown.sh')
rescue
server_is_down = true
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
这假设它只在关闭发生时出错.
capture
仅当该方法没有失败时才会返回输出。如果它引发异常,它就无法返回值(因为异常处理将占据控制权)。因此,为了从捕获命令获得一些响应,您需要它返回所需的值作为引发的异常的一部分,或者不引发异常,而只返回错误代码(加上您需要的数据)需要获取)。
归档时间: |
|
查看次数: |
2103 次 |
最近记录: |