如何从Chef和Vagrant调试RVM设置?

时间:2013-03-08 15:32:20

标签: rvm chef vagrant

我在Vagrant虚拟机上使用Chef-solo进行了RVM设置就好了,但我很困惑为什么在rails项目中找不到bundler

因此,在配置后我看到:

Last login: Thu Oct  4 15:23:58 2012 from 10.0.2.2
vagrant@vm:~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
vagrant@vm:~$ gem list

*** LOCAL GEMS ***

bigdecimal (1.1.0)
bundler (1.3.2)
daemon_controller (1.1.1)
fastthread (1.0.7)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
passenger (3.0.18)
rack (1.5.2)
rake (10.0.3, 0.9.2.2)
rdoc (3.9.4)
rubygems-bundler (1.1.1)
rvm (1.11.3.6)

转到项目目录,我看到:

vagrant@vm:~$ cd /www/vm/rails/current/
==============================================================================
= NOTICE                                                                     =
==============================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands.       =
=                                                                            =
= Examine the contents of this file carefully to be sure the contents are    =
= safe before trusting it! ( Choose v[iew] below to view the contents )      =
==============================================================================
Do you wish to trust this .rvmrc file? (/www/vm/rails/current/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied
gemset vm is not existing, creating.
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327@vm': Permission denied

但是现在,无法再找到bundle了,我也有问题激活RVM ......有什么想法可以调试吗?

$ rvm use ruby-1.9.3-p327
Please note that `rvm gem ...` was removed, try `gem  ` or `rvm all do gem  ` instead. ( see: 'rvm usage' )

PS我的节点json基本上是这样的:https://github.com/mulderp/chef-rails-stack

1 个答案:

答案 0 :(得分:1)

为了进行调试,我使用https://github.com/mpapis/rvm-binary/blob/master/cookbooks/binary/recipes/default.rb#L11

class Chef::Resource::Script
  def log_code command
    if Chef::Config[:log_level] == :debug
      code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 |
tee /var/log/#{@command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}"
    else
      code command
    end
  end
end

然后代替code使用log_code,它会将日志保存在/var/log/#{@command.to_s.gsub(/ /,"_")}.log

关于RVM与Chef check https://gist.github.com/sevos/5076747

的轻松集成
deploy_user = node[:deploy][:user]
deploy_user_home = File.join('/', 'home', deploy_user)
rvm_version = "head"

execute "install_rvm_for_deploy_user" do
  user deploy_user
  command "curl -L https://get.rvm.io | bash -s #{rvm_version}"
  environment "HOME" => deploy_user_home
  creates "#{deploy_user_home}/.rvm"
end

node['buildpack']['ruby_versions'].each do |ruby_version|
  execute "install_rvm_ruby_#{ruby_version}" do
    user deploy_user
    environment "HOME" => deploy_user_home
    command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
  end
end

file "#{deploy_user_home}/.rvmrc" do
  content 'export rvm_trust_rvmrcs_flag=1'
  owner deploy_user
  mode 0644
end