In Capistrano 2.x you could simply add :on_error => :continue like this:
task :bad_script, :on_error => :continue do
    my_error = capture('/path/to/tomcat/shutdown.sh')
end
I don't see any way to do this in Capistrano 3.x or ssh-kit (the underlying communication.) Any help would be appreciated.
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
I've tried surrounding the new way in begin/rescue blocks but that only stops it from erroring but it does not return the output from the error.
I'd still like to know how to do this but I figured out a way around needing it for my one case and that is to just set server is down if it fails.
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
This is assuming that it only errors when the shutdown takes place.
You can suppress the error and redirects stderr to a variable like this:
capture('output_from_tomcat_shutdown=`/path/to/tomcat/shutdown.sh 2>&1` || echo $output_from_tomcat_shutdown')
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With