简体   繁体   English

如何在Capistrano v3中的服务器上运行shell命令?

[英]How to run shell commands on server in Capistrano v3?

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. 我是Capistrano的新手,我曾尝试使用Capistrano的DSL在服务器上运行shell命令(“运行”,“执行”等),但似乎已弃用。 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

In Capistrano v3, you must specify where you want to run the code by calling on with a list of hostnames, eg 在Capistrano的V3,你必须指定要运行的代码调用on与主机名的列表,如

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

If you have roles set up, you can use the roles method as a convenience: 如果您设置了角色,则可以方便地使用roles方法:

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

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

There is some v3 documentation here: http://www.capistranorb.com/ 这里有一些v3文档: http : //www.capistranorb.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM