You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lee Hambley edited this page Oct 4, 2010
·
12 revisions
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 :approle.