1

我正在尝试进行设置,以便当我有新服务器时,而不是使用图像,我可以进行 capistrano 部署设置。

我的问题很多,我认为这是由于我使用 Capistrano V3。例如,我的第一个想法是使用 rvm-capistrano gem,但我遇到了以下问题。我确实在我的 deploy.rb 文件和 capfile 中都包含了 require "rvm/capistrano" 以确保。

cap staging rvm:install_rvm
cap aborted!
Don't know how to build task 'rvm:install_rvm'

所以然后我环顾四周,结果发现有一个 capistrano-rvm gem 显然是专门为 capistrano v3 设计的,但它似乎没有开发并且有同样的问题,capistrano 不理解 rvm:install_rvm。

所以后来我决定尝试在任务本身中安装 rvm,做

sudo "apt-get -y install curl"
execute "\curl -L https://get.rvm.io | bash"
execute "source ~/.rvm/scripts/rvm"
execute "rvm requirements"
execute "rvm install ruby"
execute "rvm use ruby --default"
execute "rvm rubygems current"
execute "gem install rails"

但我明白了,不知道为什么 curl 中的字母 cu 消失了:

INFO [7e26eda7] Running /usr/bin/env rl -L https://get.rvm.io | bash on 192.168.1.126
DEBUG [7e26eda7] Command: rl -L https://get.rvm.io | bash
DEBUG [7e26eda7]        bash: $'\025rl': command not found
DEBUG [7e26eda7]
 INFO [7e26eda7] Finished in 0.006 seconds command successful.
 INFO [14e12c80] Running /usr/bin/env source ~/.rvm/scripts/rvm on 192.168.1.126
DEBUG [14e12c80] Command: source ~/.rvm/scripts/rvm
 INFO [14e12c80] Finished in 0.153 seconds command successful.
 INFO [a501984d] Running /usr/bin/env rvm requirements on 192.168.1.126
DEBUG [a501984d] Command: rvm requirements
cap aborted!
rvm requirements stdout: Nothing written
rvm requirements stderr: Nothing written
/home/hak8or/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-0.0.34/lib/sshkit/command.rb:94:in `exit_status='
/home/hak8or/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-0.0.34/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'

所以经过一些谷歌搜索后,我尝试

execute "curl -L get.rvm.io | bash -s stable --auto"

但作为回报我得到

 INFO [0e84ae63] Running /usr/bin/env source ~/.rvm/scripts/rvm on 192.168.1.126
DEBUG [0e84ae63] Command: source ~/.rvm/scripts/rvm
 INFO [0e84ae63] Finished in 0.139 seconds command successful.
 INFO [9e5a9f02] Running /usr/bin/env rvm requirements on 192.168.1.126
DEBUG [9e5a9f02] Command: rvm requirements
cap aborted!
rvm requirements stdout: Nothing written
rvm requirements stderr: Nothing written
/home/hak8or/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-0.0.34/lib/sshkit/command.rb:94:in `exit_status='
/home/hak8or/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-0.0.34/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'

以及来自 curl 命令的大量垃圾。我假设 RVM 没有正确安装。

如果我让 capistrano 运行一个包含所有这些命令的脚本,我的终端窗口中也会出现大量垃圾。当我在本地运行它时,这意味着我进入机器并运行

\curl -L https://get.rvm.io | bash
rvm requirements

我没有问题。我认为这与它通过专门与 Capistrano 的 ssh 连接运行有关,但不知道。我在完全更新的 ubuntu 服务器上的部署用户上运行所有这些,并且出于测试目的,我向部署用户授予了完整的无密码 sudo。

4

2 回答 2

2
  1. 报告 rvm/capistrano 的错误 => https://github.com/wayneeseguin/rvm-capistrano/issues

  2. 您在 ruby​​ 字符串中使用了 escape 这会造成垃圾,要使用 shell 转义,您需要在 ruby​​ 中对其进行转义,因此命令将是:

     execute "\\curl -L https://get.rvm.io | bash"
    
于 2013-09-26T03:22:51.043 回答
2

这是我用来构建詹金斯服务器的完整安装 Ruby 函数。请记住,我使用 Capistrano V2。享受。

task :install_ruby, roles => :app  do
  run "yum --exclude=*.i386 --exclude=*.i586 install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel libxml2-devel libxslt-devel"
  run "bash -s stable < <(curl -k -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)"
  run "source /etc/profile"  
  run "rvm install 1.9.3 --autolibs=enabled"
  run "rvm use 1.9.3 --default"   
  run "gem install capistrano", { :shell => 'bash'}
  run "gem install railsless-deploy", { :shell => 'bash'}
  run "gem install ntlm-http; true", { :shell => 'bash'}
  run "gem install domain_name", { :shell => 'bash'}
  run "gem install webrobots", { :shell => 'bash'}
  run "gem install mechanize", { :shell => 'bash'}
end
于 2013-09-27T19:28:37.653 回答