How do I `bundle install` with Chef? - rvm

I am using Chef to provision a CentOS 6.5 box and install my Rails 4.0.4 app.
I installed RVM and Ruby 2.1.1
When I cd my_website, RVM will set the correct ruby version (gemset).
How do I tell Chef to bundle with the correct ruby version
currently I am using this:
execute "bundle-install" do
user "my_user"
cwd "/home/my_user/website/"
command "bundle install"
action :run
end
But that is not enougth, it's still trying to use ruby 1.9.3

RVM is a shell-based Ruby version manager. Since the Chef Client runs as root, it probably isn't executing the login shell. So things like .rvmrc and the actual loading of RVM are ignored. Handling this with Chef is a bit complicated. I would recommend looking at Fletcher's chef-rvm cookbook.

Related

Deploy Rails 3 with Phusion Passenger on Ubuntu WITH ALL GEMS INCLUDED

I need to deploy a Rails 3/Phusion Passenger/Apache2 app to an Ubuntu 12.04 server without installing ANY gems on the server.
I can install any Debian packages.
How can I include all needed gems (including Rails, a couple of gems installed from git projects on github, and a bunch of regular gems installed from rubygems.org) inside my project so that, after deployment, Passenger will find Rails and all the gems and be happy?
(I know many people will probably be curious WHY I would want to do this. I can't talk about that, unfortunately. Sorry.)
Here are some things that have not worked. One of them might work if revised a little, I don't know:
Failed method 1:
On Ubuntu 12.04 dev machine. Ruby 1.9.3. Bundler 1.3.5. bundle package --all. Git commit.
On Ubuntu 12.04 server machine (gem installation from Internet not possible). Deploy project files and install packages (apache2, ruby1.9.3, ruby-bundler, rubygems, libapache2-mod-passenger which brings ruby1.8 with it). bundle -v gives Bundler version 1.0.15 (from ruby-bundler package). Make sure .bundle/config file from dev machine is also deployed. bundle install --local tries to download git gems from github, so fail.
Try using bundle package --all, which should save your gems into ./vendor/cache. You could also unpack the gems on your local environment with gem unpack --target vendor to save them in the vendor directory. Then you can give a location in the Gemfile so that your application can find the gems. Can you just not use the network to install gems, or are you really not allowed to install gems in any way?
Sources:
1,
2
Try using the pkgr tool, which can convert your Rails app and all dependencies into a single installable Debian package.
Download the bundler 1.3.5 gem from http://rubygems.org/downloads/bundler-1.3.5.gem and put it in vendor/
In an Ubuntu 12.04 vm, do bundle package --all. Git commit and push.
Clone on the Ubuntu server.
apt-get install each of apache2, ruby1.9.3, etc. (not rubygems or ruby-bundler. Both provide an old version of Rubygems and Bundler. A newer version of rubygems is included in the ruby1.9.3 package.)
Follow ALL of the instructions in section 2.3 at http://www.modrails.com/documentation/Users%20guide%20Apache.html#install_on_debian_ubuntu
Make sure you have the right Ruby and Rubygems versions set to the ruby and gem commands:
update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.3 200
update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.9.3 200
(Phusion Passenger doesn't care about this, but it's probably a good idea for the gems we are about to install and for debugging stuff with the Rails console or whatever in the future.)
gem install --local vendor/bundler-1.3.5.gem
bundle install --local
Set up all your other Apache config...
service apache2 restart

Passenger on Apache 2 Installation fails with Your RVM wrapper scripts are too old

I'm trying to install passenger on a virtual rootserver (which has multiple user accounts) but running 'passenger-install-apache2-module' results always in the following error:
Your RVM wrapper scripts are too old. Please update them first by running 'rvm get head && rvm reload && rvm repair all'.
Following this given instructions does not take any effect.
Before installing passenger, i installed RVM as multiuser / mixed mode according to https://rvm.io//rvm/install/
After that I did (using a non root-account):
rvmsudo rvm user gemsets
rvm install 1.9.3
gem install rails
gem install passenger
and lastly passenger-install-apache2-module
I searched for hours on this problem but could not find any working solution yet.
Any suggestions ? Thanks in advance!
Try to install passenger-install-apache2-module like this :
rvmsudo passenger-install-apache2-module
I just encountered this very same issue. I'm using ZSH, but switching to Bash also failed on first attempt.
My solution was to switch to Bash with the --login flag:
/bin/bash --login
Then I noticed that my RVM ruby had become unset, so I re-set using:
rvm use ruby-1.9.3 --default
Once this was done, the following worked as expected:
passenger-install-apache2-module
Rich
I have had similar issue and have taken extreme steps on my centos 6.3 system after struggling for days! In specific, I failed to install standalone phusion passenger apache2 module on gemsets other than default and global. I have taken the following steps and now, it works for me:
Login as root (I hope you know what you're dealing with)
To completely uninstall existing rvm, invoke
[root#] rvm implode
Install stable rvm, invoke
[root#] curl -L get.rvm.io | bash -s stable
run rvm shell,
[root#] source /etc/profile.d/rvm.sh
check rvm requirements, invoke
[root#] rvm requirements
and install all requirements.
Install ruby 1.9.3, invoke
[root#] rvm install 1.9.3
Install current rubygems, invoke
rvm rubygems current
Set default to ruby 1.9.3, invoke
[root#] rvm use 1.9.3 --default
Add other users who are using rvm to rvm group, invoke
[root#] usermod -a -G rvm USERNAME
If USERNAME is currently logged in, pls logout so the group add will take effect.
Make sure rvm group added, invoke
[USERNAME#] groups
Create and Switch to a new gemset on ruby 1.9.3, invoke
[USERNAME#] rvm use 1.9.3#mygemset --create
Confirm that you're on the right gemset, invoke
[USERNAME#] rvm gemset name
Install passenger gem, invoke
gem install passenger
To skip gem documentation instead, invoke
[USERNAME#] gem install passenger --no-ri --no-rdoc
or specify them in your .gemrc file
To install apache2 mod, invoke
[USERNAME#] passenger-install-apache2-module
Hope that helps!

Getting Rails working with a JS runtime environment

I'm using Ubuntu 11.10 and the terminal to install and run Rails. Here
is the process I've taken so far to setup Rails:
download and install Ruby 1.9.2 and Rails 3.1.0
-- I did this using sudo apt-get ruby1.9.1 and sudo gem install
rails
I made a new rails app using rails new path/to/app
I went to the new app directory and tried running rails server and got an
error about not having a JS ruby environment
I had to get a JS runtime environment for execjs so I downloaded 'therubyracer'
as well as 'therubyrhino' and added them to my gem file, one at a time like this:
gem
'therubyracer' then ran bundle install
After everything was successful with the install, I ran rails server again
-- with both runtime environments I have had similar errors:
Could not find libv8-3.3.10.4 in any of the sources
Run `bundle install` to install missing gems.
Could not find therubyrhino-1.73.0 in any of the sources
Run `bundle install` to install missing gems.
Bundle knows where these programs live, giving correct pathnames when I
enter bundle show libv8 or bundle show therubyrhino. They are both
in /usr/lib/ruby/gems/1.9.1/gems/_ where all the other gems are
located for the bundle install.
Does anyone know where this exception is coming up in the Rails source
code? Does anyone know how Rails is gathering the gems? Better yet,
anyone had this problem and know how to fix it?
Thanks so much,
Feav
Have you tried starting the server using bundle exec rails server?
This problem has been fixed in a newer version of Rails.

Ubuntu 11.04 Ruby on Rails install write permissions error

I am trying to install rails and have installed rvm and am trying to install rails but it is saying I do not have write permissions.
$ gem install rails --version 3.0.7
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.8 directory.
When I try sudo it give me this error, I know that you can use --no-ri --no-r-doc but even when I did this rails was not installed properly. Does anyone have any ideas?
$ sudo gem install rails --version 3.0.7
Successfully installed rails-3.0.7
1 gem installed
Installing ri documentation for rails-3.0.7...
file 'lib' not found
Installing RDoc documentation for rails-3.0.7...
file 'lib' not found
from my experience with rvm, gems should't stay in /var/lib/
if you didn't specifically asked for this, there might be a problem with your rvm installation
if so, i would definetly recommend a clean rvm install by following ryan bigg's guide of installing rvm. i followed it every time and never ever had the slightest problem after.
hope this helps!

RVM settings lost after every logout

I installed ruby, rails and gemsets using RVM on ubuntu as instructed on :
http://railstutorial.org/ruby-on-rails-tutorial-book#sec:rubygems
Now the problem is that everytime I reboot machine and open console, my RVM and rails settings are lost:
when I try "rails server" - rails is not found and all gems are lost too. I need to install rails and install other gems like heroku again.
Are you sourcing $HOME/.rvm/scripts/rvm into your shell in its .profile or whatever setup?
That would be the first thing to check.
Add this line:
source $HOME/.rvm/scripts/rvm
Try the following
rvm --default use 1.9.3