Ruby 如何在CapistranoV3中的服务器上运行shell命令?
我是Capistrano的新手,我曾尝试使用Capistrano的DSL在服务器上运行shell命令(“run”、“execute”等),但它似乎已被弃用。在一次又一次地寻找功能等价物之后,我仍然迷路了 当前代码:Ruby 如何在CapistranoV3中的服务器上运行shell命令?,ruby,capistrano3,Ruby,Capistrano3,我是Capistrano的新手,我曾尝试使用Capistrano的DSL在服务器上运行shell命令(“run”、“execute”等),但它似乎已被弃用。在一次又一次地寻找功能等价物之后,我仍然迷路了 当前代码: desc 'Do something' task :do_something execute 'echo sometext' end 输出: cap aborted! undefined method `execute' for main:Object
desc 'Do something'
task :do_something
execute 'echo sometext'
end
输出:
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
cap中止!
main:Object的未定义方法“execute”
/Users/Justin/Dropbox/xxxx/xxxx/xxxx/Capfile:45:在“块(2级)中”
/Users/Justin/.rvm/gems/ruby-2.0.0-p247/bundler/gems/capistrano-2dc1627838f9/lib/capistrano/application.rb:12:在“运行”中
/Users/Justin/.rvm/gems/ruby-2.0.0-p247/bundler/gems/capistrano-2dc1627838f9/bin/cap:3:in`'
/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`'
/Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/ruby\u noexec\u包装:14:in'eval'
/Users/Justin/.rvm/gems/ruby-2.0.0-p247/bin/ruby\u noexec\u包装:14:in`'
任务:TOP=>deploy:do\u某事
在Capistrano v3中,您必须通过使用主机名列表调用来指定要在何处运行代码,例如
task :execute_on_server do
on "root@example.com" do
execute "some_command"
end
end
如果设置了角色,可以使用角色
方法作为方便:
role :mailserver, "root@mail.example.com"
task :check_mail do
on roles(:mailserver) do
execute "some_command"
end
end
这里有一些v3文档:Awesome,我希望他们在演练中能更清楚地说明这一点。他们只使用测试、信息等。Capistrano
execute
方法依赖于sshkit
中的实现。现在您可以在这里找到有关execute
的更多信息:Capistrano 3文档仍然不完整。@KitHo是的,您可以使用sudo,就像手动ssh连接一样。当我在“info”和“error”方法上遇到同样的问题时,我使用run_local{…}
而不是on。。。{…}
。这会让您在不连接远程框的情况下进入SSHKit上下文。我对方法“info”和“error”有完全相同的问题——同样的问题,因为这些方法属于SSHKit,并且必须位于SSHKit块中。