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

时间:2022-09-06 18:25:13

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.

我是Capistrano的新手,我尝试过使用Capistrano的DSL在服务器上运行shell命令('run', 'execute',等等),但它似乎被废弃了。在搜索和搜索一个功能对等物之后,我仍然迷失了方向。

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

1 个解决方案

#1


109  

In Capistrano v3, you must specify where you want to run the code by calling on with a list of hostnames, e.g.

在Capistrano v3中,您必须通过调用一个主机名列表来指定您想要运行代码的位置。

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.capiorb.com/。

#1


109  

In Capistrano v3, you must specify where you want to run the code by calling on with a list of hostnames, e.g.

在Capistrano v3中,您必须通过调用一个主机名列表来指定您想要运行代码的位置。

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.capiorb.com/。