How to start a Capistrano task based on environment or server properties?

I have a namespace and several tasks in the namespace that start after deployment: updated. Here is an example:

namespace :myservice do task :start do on roles(:app) do sudo :start, "my/application" end end end 

I would like one of these tasks to work only in a specific environment or as a host. How can i do this?

I would like to be able to filter in an environment, for example:

 namespace :myservice do task :start do on roles(:app), env(:vagrant) do sudo :start, "my/application" end end end 

What is the best way to do this?

+8
capistrano capistrano3
source share
1 answer

A multi-stage capistrano seems to help you. https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

Essentially, you will have a step called vagrant where you can define configuration variables that will then reference your main deploy.rb script and act.

Here is a conceptual example,

 # config/deploy/production.rb set :should_start_my_application, false # config/deploy/vagrant.rb set :should_start_my_application, true # config/deploy.rb namespace :myservice do task :start do on roles(:app) do if should_start_application then sudo :start, "my/application" end end end end 
+1
source share

All Articles