Showing posts with label capistrano command output. Show all posts
Showing posts with label capistrano command output. Show all posts

Friday, October 9, 2009

How to get the output of Capistrano executed command

Sometimes it is required to get the the output of some executed command in external/deployment server and based on that output you may need to take some decision. Lets say for some reason you are planning for hot deployment to a JBoss application server. So before deployment you want to make sure if the JBoss is running or not. You can do that by following script. Here I am assuming that the JBoss is running at 8080



task :do_something_if_jboss_is_running do
  set :use_sudo, true
  set :user, prompt("User to check jboss running status: ")
  set :is_jboss_running, true

  run "netstat -an | grep -i listen | grep 8080|wc -l" do |ch, stream, data|
    if data.to_i > 0
      set :is_jboss_running, true
    else
      set :is_jboss_running, false
    end
  end
  
  if is_jboss_running 
#do something 
  else
#do some other thing
  end
end