Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 1.28 KB

Task-Definitions.textile

File metadata and controls

24 lines (18 loc) · 1.28 KB

The simplest Capistrano task would look like this, note there is nothing happening remotely here:

desc "Print out the local time on the system"
task :time do
  puts Time.now.to_s
end

In order to perform a similar action on a remote machine, assuming you have [[everything properly configured]], the same task might look something like this:

set :server_ruby, '/opt/local/bin/ruby' 
desc "Print out the time on the remote servers"
task :remote_time, :roles => :app do
  puts capture("#{server_ruby} -e 'puts Time.now.to_s'")
end

Note that even in this contrived example, there are some important things happening. Firstly we’re setting a configuration variable, simply :server_ruby; this is a great way to ensure that environmental changes on the server to not break deploy scripts. Especially when deploying to production environments you should be certain of the commands which will take place.

We’re also using the capture method, which returns the value of the expression captured within.

Finally, you notice that this task is intended only to run on servers in the :app role.