74

I'm new to Capistrano and I've tried using Capistrano's DSL to run shell commands on the server ('run', 'execute', etc.), but it appears that it was deprecated. After searching and searching for a functional equivalent, I still am 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
4

1 回答 1

118

在 Capistrano v3 中,您必须通过调用on主机名列表来指定要在何处运行代码,例如

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

如果您设置了角色,则可以使用该roles方法方便:

role :mailserver, "root@mail.example.com"

task :check_mail do
  on roles(:mailserver) do
    execute "some_command"
  end
end

这里有一些 v3 文档:http: //www.capistranorb.com/

于 2013-09-17T01:53:43.370 回答