Unable to run sh script from remote computer - ruby

I'm trying to run the following script from a remote computer on a Linux computer with RVM:
plink.exe -pw root#< Linux ip> /root/script.sh
ERROR: Error installing /usr/local/rvm/gems/ruby-1.9.2-p290/cache/bundler-1.0.22.gem: bundler requires RubyGems version >= 1.3.6
script.sh is a script that runs ruby script.
I think that the problem is caused by some collusion with the RVM or bundler gems on the remote Linux.
Can someone advise?

You need to make sure that the script you are running is using the correct rvm environment. It might be running under the System ruby. Try running a much simpler script that outputs "ruby ---version" and/or "which ruby" first
Edit:
In your bash script, you might need to do something like:
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function
rvm use 1.9.2

Related

how to add rvm to super user

hi i need to execute a ruby program from a init script i need to run the script as
sudo /etc/bin/differ.sh start
but the problem is rvm is not installed on root(super user) . so code in the differ script ruby "filename" wont execute because the gems and rvm is not installed in root.
i need solve how to add rvm and its gems to root (i have not installed by system wide installation).i have even tried the rvmsudo
rvmsudo ruby "filename"
but it's not working in script works good in terminal.
please free to ask any files or outputs i will post along with this question.
This page on integrating RVM with init.d may help: https://rvm.io/integration/init-d

vagrant will not use rbenv ruby version

I'm using the Vagrant box:
https://dl.dropbox.com/u/14292474/vagrantboxes/precise64-ruby-1.9.3-p194.box
It has ruby1.9.3 installed under rbenv. I'm trying to test a rails app and in the chef-solo provisioner I have (among other things), this block:
execute 'install' do
action :run
command "bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"
cwd node.app_name.path
end
rbenv is installed under the vagrant user and instructed to use 1.9.3 globally. For some reason, when bundler is run during vagrant up it still uses 1.8.7 which is only found in /opt/vagrant_ruby.
How can I tell vagrant that I want to use the rbenv ruby to perform all tasks. Do I need to pass something in the env option of the execute block?
First start to get the path of bundle in your server:
$ which bundle
/opt/rbenv/shims/bundle
Then, knowing that in chef when you included the rbenv cookbook, the constant RBENV_ROOT is equal to /opt/rbenv, modify your command like this:
command "#{RBENV_ROOT}/shims/bundle install --path #{node.app_name.lib_path}/vendor/bundle --binstubs"
So you ensure to use the correct version of bundle when installing.
A second thing you can do is to add the path for rbenv (which can be located in /etc/profile.d/rbenv but that depends on your installation) on top of the ~/.bashrc of the user you use with chef-solo
For example, if you are using a use "deployer", edit /home/deployer/.bashrc to have on top of the file:
#Rbenv path for remote shells
source /etc/profile.d/rbenv.sh # <--- adapt this to your installation
# If not running interactively, don't do anything
[ -z "$PS1" ] && return # <--- remote shell (ssh connection) will stop at this line

How to run logstash from exploded jar with JRuby

I'm not very comfortable with jruby and rvm environments, so I have trouble trying to run logstash with it (it is said to be the fastest way to do so).
What I've tryed :
I installed rvm environement (as a side note, the standard install scripts create a new .bash_profile, which disable the standard .bashrc script when you're on Ubuntu. This can confuse new users like me... I was wondering for several hours why my 'll' alias won't work !)
I uncompressed logstash (jar xvf /logstash-1.1.4-monolithic.jar) in a new directory
I've followed the instructions in https://rvm.io/rvm/install/ as rvm install 1.9.2 (albeit I've also made some try/error/redo manipulations, so I can't remember the exact listing of commands)
Then I tried several commands, but none of them worked :
$ ruby logstash.rb
/home/orabig/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- logstash/agent (LoadError)
from /home/orabig/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from logstash.rb:1:in `<main>'
whereas the following line is returning after some seconds :
jruby-1.7.0 logstash.rb agent -f ../etc/inout.config -v
(the inout.config file is working when invoked with the java commandline as in :)
java -jar (...)/logstash-1.1.4-monolithic.jar agent -f ../etc/inout.config -v
So I'm basically stuck now, because the more I will try random things, the more I'm afraid to mess up my configuration...
Update : On the logstash page (https://github.com/logstash/logstash), it looks like it's working with 1.6.8 ruby version (however it's not clear, and I'm not sure if it makes any difference...)
So I also tried :
$ rvm install 1.6.8
(...)
$ rvm use 1.6.8
$ export JRUBY_OPTS=--1.9
$ ruby logstash.rb agent -f ../etc/inout.config -v
$ jruby-1.6.8 logstash.rb agent -f ../etc/inout.config -v
but nothing happens when I run either of the last two lines...
As the rvm tool will let you know: You have to be in a login shell to use rvm like that.
So, either run bash -login or use rvm to select and run your version of ruby like done in the following:
rvm install 1.7.0 # note that 1.7.0 will also work
export JRUBY_OPTS=--1.9
rvm 1.7.0 do bundle install
rvm 1.7.0 do ruby lib/logstash/runner.rb agent -f ../etc/inout.config -v
This will tell rvm to use jruby-1.7.0 to run your logstash agent.

rake sometimes won't work until "rvm use"

I've got Ruby, Rails, Rake and friends all working pretty well using RVM on OSX, but when I start a new shell (new tab in Terminal.app) rake tasks seem to "lose" their environment:
$ rake my_module:my_task
Could not find uglifier-1.2.7 in any of the sources
Run `bundle install` to install missing gems.
If I issue "rvm use" (which, I believe merely prints the current ruby, but does not alter anything) then it works fine:
$ rvm use
Using /Users/username/.rvm/gems/ruby-1.9.3-p194
$ rake my_module:my_task # works fine now!
It seems to happen when a new shell is started. I have rvm installed as a single-user installation, with the following at the bottom of my .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
I've verified that my .bash_profile is in fact executing by putting some echo statements after that line; I see the echo on the command line when I open a new tab, so it seems to be working. Any idea why rake doesn't work without "rvm use"?
Try setting rvm ruby to default ruby
$ rvm use ruby-1.9.3-p194 --default
This should use the rvm ruby-1.9.3-p194 every time as default.

RVM problem with default ruby version

when i execute following command
$ rvm --default use 1.9.2
$ ruby -v
i got following result:
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
i can't understand why is not
ruby 1.9.2p0...
If u installed correctly, most likely its is path problem.
Solution 1: Manually add the ruby1.9.2.p0 path into ur $PATH
Solution 2: Try run:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Type rvm info.
All paths should reflect rvm's installation in your home directory.
If not, odds are good you didn't follow the "Post Install" directions for rvm, and need to go through them, and the troubleshooting section that follows it.
Maybe you should to try
rvm reload
or try to type
rvm info
hope that will help you
Maybe you should invoke
rvm reload
or try to open up a new shell and then again
ruby -v
hope that works for you...
You can try running which ruby to see where your ruby is running from. If you've set up your rvm correctly and followed all the steps, it should look something like /home/username/.rvm/rubies/ruby-1.9.2-p136/bin/ruby. Also, make sure you added the line to your .bashrc file as specified in rvm-install notes.
I've found this rvm setup tutorial to work flawlessly on several different machines: http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you, including Ubuntu, Fedora, and even on a Mac (with a few adjustments).

Resources