How to run shell commands on a server in Capistrano v3?

I am new to Capistrano, and I tried using Capistrano DSL to run shell commands on the server ("run", "run", etc.), but it seems to be out of date. After searching and searching for the functional equivalent, I am still lost.

Current Code:

desc 'Do something' task :do_something execute 'echo sometext' end 

Output:

  cap aborted! undefined method `execute' for main:Object /Users/Justin/Dropbox/xxxx/xxxx/xxxx/Capfile:45:in `block (2 levels) in <top (required)>' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bundler/gems/capistrano-2dc1627838f9/lib/capistrano/application.rb:12:in `run' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bundler/gems/capistrano-2dc1627838f9/bin/cap:3:in `<top (required)>' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `load' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/cap:23:in `<main>' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval' /Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>' Tasks: TOP => deploy:do_something 
+67
ruby capistrano3
Sep 16 '13 at 23:20
source share
1 answer

In Capistrano v3, you must specify where you want to run the code by calling on with a list of host names, for example.

 task :execute_on_server do on "root@example.com" do execute "some_command" end end 

If you have roles installed, you can use the roles method as a convenience:

 role :mailserver, "root@mail.example.com" task :check_mail do on roles(:mailserver) do execute "some_command" end end 

Here is the v3 documentation: http://www.capistranorb.com/

+106
Sep 17 '13 at 1:53 on
source share



All Articles