通过脚本使用rvm设置EC2服务器 [英] setting up an EC2 server with rvm via scripting
问题描述
我正在寻找一种方法来安装rvm,安装特定的ruby版本(使用rvm)并将此已安装的ruby版本设置为默认版本。在安装rvm之前,我必须安装gcc和一些其他非常基本的软件包。到目前为止,我已经尝试过:
I'm looking for a way to install rvm, install a specific ruby version (using rvm) and set this installed ruby version as default. Before I can install rvm I have to install gcc and some other very basic software packages. What I've tried so far:
1)使用net / ssh
1) Using net/ssh
- 我必须模拟一个伪tty才能对某些命令进行sudo,直到现在,
我还不知道如何从一个不成功的完整命令中判断一个成功的完整命令。 - 安装rvm之后,我偶然发现了使用rvm的问题( rvm不是一个函数,错误消息,导致无法设置默认的ruby版本)。
2)使用capistrano
2) Using capistrano
-
在ssh输出中插入换行符,这样每次都会在新行中打印例如进度条。这是我可以忍受的。
In the ssh output are newlines inserted so that a progress bar for example is been printed in a new line every time, some progress is made. That's something I can live with.
与rmv相同的问题,我能够安装rvm,但无法设置默认值: rvm-默认使用1.9.2
。没有错误消息,但是当我稍后登录时,没有设置默认值,并且 ruby -v
显示旧系统ruby。
Same Problems with rmv, I'm able to install rvm, but I'm unable to set a default: rvm --default use 1.9.2
for example. No error message, but when I've log in later, no default is set and ruby -v
shows the old system ruby.
3)使用capistrano和rvm-capistrano
3) Using capistrano and rvm-capistrano
- 现在我跑了进入这个问题,我尝试在安装rvm之前执行的那个任务失败了,因为似乎有一些魔术在弄乱shell默认设置:
* executing "sudo -p 'sudo password: ' yum install --assumeyes git gcc-c++ autoconf automake make patch zlib-devel libtool bzip2-devel"
servers: ["ec2-54-247-142-214.eu-west-1.compute.amazonaws.com"]
[ec2-54-247-142-214.eu-west-1.compute.amazonaws.com] executing command
** [out :: ec2-54-247-142-214.eu-west-1.compute.amazonaws.com] bash: /home/ec2-user/.rvm/bin/rvm-shell: No such file or directory
command finished in 2094ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'default' -c 'sudo -p '\\''sudo password: '\\'' yum install --assumeyes git gcc-c++ autoconf automake make patch zlib-devel libtool bzip2-devel'" on ec2-54-247-142-214.eu-west-1.compute.amazonaws.com
rake aborted!
这是我发出的安装rvm / ruby的命令:
Here the commands I issue to install rvm/ruby:
run 'curl -L https://get.rvm.io | bash -s stable'
run 'rvm install ruby-1.9.2-p320'
run 'echo "[[ -s \"\$HOME/.rvm/scripts/rvm\" ]] && source \"\$HOME/.rvm/scripts/rvm\"" >> .bashrc'
run 'rvm --default use ruby-1.9.2-p320'
run 'which ruby && ruby -v'
,此处是作为对的响应而发出的错误消息rvm-默认使用1.9.2
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal settings to allow shell login.
Please visit https://rvm.io/workflow/screen/ for example.
4.1)使用capistrano和rvm-capistrano并进行一些黑客攻击
4.1) Using capistrano and rvm-capistrano and hacking a little bit
更新:在RVM聊天中mpapis的帮助下,我现在想出了这个可行的解决方案:
需要 rvm / capistrano
Update: With the help from mpapis at the RVM chat, I was able to come up with this working solution now: require "rvm/capistrano"
role :server, ENV[ 'base_image_setup_server' ] if ENV[ 'base_image_setup_server' ]
default_run_options[:pty] = true
default_run_options[:shell] = :bash
set :rvm_ruby_string, 'ruby-1.9.2-p320'
set :rvm_type, :user
def rvm_bin
'$HOME/.rvm/bin/rvm'
end
namespace :images do
task :install_basics do
run "#{sudo} yum install --assumeyes git gcc-c++ autoconf automake make patch zlib-devel libtool bzip2-devel"
run "#{sudo} yum update --assumeyes"
end
task :install_ruby do
rvm.install_rvm
rvm.install_ruby
run "#{rvm_bin} alias create default #{rvm_ruby_string}"
run 'echo "source ~/.rvm/environments/default" >> $HOME/.bashrc'
run 'which ruby && ruby -v'
end
...
desc 'build the base-image'
task :base_image do
install_basics
install_ruby
install_boost
install_rake_and_rack
install_sioux
test_sioux
end
主要区别是RVM不是用作功能,而是程序直接使用。
The main different is, that RVM is not used as a function, but the program direct.
种类问候,
Torsten
kind regards, Torsten
推荐答案
检查Capistrano集成的RVM站点 https://rvm.io/integration/capistrano
Check RVM site for Capistrano integration https://rvm.io/integration/capistrano
有安装RVM和Ruby的任务:
There are tasks to install RVM and Ruby:
after 'deploy:setup', 'ubuntu:install'
after 'deploy:setup', 'rvm:install_rvm' # do it only with deploy setup
before 'deploy', 'rvm:install_ruby' # do it on every deploy
namespace :ubuntu do
desc "setup ubuntu system"
task :install do
run "apt-get install -y make ...", :shell => "sh"
...
end
end
您运行标准:
cap deploy:setup
cap deploy:cold
另外,您可能还想看看我的示例Rails应用程序,以了解简单而有效的部署脚本: https://github.com/mpapis/ad 和有关它的我的博客文章: http://niczsoft.com/2012/03/fast-deployment-using-capistrano-rvm-and-more/
Also you might want to have a look on my example rails app for simple and working deployment script: https://github.com/mpapis/ad and my blog post about it: http://niczsoft.com/2012/03/fast-deployment-using-capistrano-rvm-and-more/
这篇关于通过脚本使用rvm设置EC2服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!