Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working with rbenv/rvm etc? #5

Closed
ledbettj opened this issue Jun 11, 2012 · 28 comments
Closed

working with rbenv/rvm etc? #5

ledbettj opened this issue Jun 11, 2012 · 28 comments

Comments

@ledbettj
Copy link

Hi,

I'm trying to deploy to a server where ruby is installed using rbenv for the deploy user. However, mina doesn't seem to pick it up:

bundle install --without development:test --path "./vendor/bundle" --binstubs bin/ --deployment
bash: line 77: bundle: command not found

I'm never sure which init file gets run on ssh login -- I tried adding the required export PATH=... statements to .bashrc, .bash_profile, and .profile none of which seemed to help. I also tried setting up the PATH manually in the deploy task:

# ...
queue 'export PATH=$HOME/.rbenv/bin:$HOME/.rbenv/shims'
queue 'echo "path=$PATH"' # this doesn't include the paths above :(
invoke :'bundle:install'
# ...

without success (I assume each task runs in a subshell maybe?)

Any advice on how to get this setup working?

Thanks!

@rstacruz
Copy link
Member

Hmm.

I'll issue a fix to make bash commands read .bashrc. This simply means passing -i to any time Mina tries to invoke Bash, and I think it's a sensible default.

You're correct that each queued deploy command is executed in it's own subshell, you can try to do mina deploy --simulate to see. However, you can do:

task :deploy do
  queue "export ..."
  deploy do
    # ...
    # deploy stuff here
  end
end

..and it will be invoked outside the deploy script (not in a subshell).

@ledbettj
Copy link
Author

Sounds good -- thanks! Adding the export statement at the task level did work.

@rstacruz
Copy link
Member

v0.1.2 should now honor .bashrc by default.

I've also introduced a relevant setting bash_options which you can see here.

I'd like to implement better RVM integration in the future. The example @ledbettj cited was for rbenv (which by the way, will not be needed in 0.1.2+), but for RVM it's queue "rvm rvmrc load".

@rstacruz
Copy link
Member

@ledbettj gem install mina --pre (v0.1.2.pre1) -- enjoy.

@mrrooijen
Copy link

Putting queue "rvm rvmrc load" at the Task level didn't work for me using RVM. However I simply added the following to my .bashrc since that's now loaded and it works fine:

source "$HOME/.rvm/scripts/rvm"

Would of course be nice to have this integrated in Mina, but not sure how hard it'd be seeing as you have different kinds of installs (user/system-wide) - not sure if there is a universal way of loading it in. But, sourcing it yourself from the .bashrc works fine seeing as Mina sources it. I'm not an RVM expert though so there might be a convenient/universal way to get RVM (or the Ruby implementations) to be loaded.

@ianmurrays
Copy link

@meskyanichi thanks for the comment there, fixed my issues. Would be nice if mina supported rvm like capistrano does. Keep up the good work!

@mrrooijen
Copy link

@ianmurrays no prob!

@perumal
Copy link

perumal commented Jul 15, 2012

I really love mina.....it is super fast and super simple but
I am still getting this error
bash: line 60: bundle: command not found
Please help me

my rvm path is "/usr/local/rvm/bin"

i have added the below lines to ~/.bashrc
source "/usr/local/rvm/bin"
and added the below lines to my deploy.rb

@bluestrike2
Copy link

@perumal Mina opens up a pseudo-tty connection (ssh -t ...) so make sure you're sourcing all your goodies (rvm, etc.) for your shell appropriately. .bashrc gets loaded for non-login interactive shells.

@perumal
Copy link

perumal commented Jul 15, 2012

The above problem disappeared after tweaking around but i got the following error
When executed as 'deploy' user

  tput: No value for $TERM and no -T specified
  tput: No value for $TERM and no -T specified
  ERRRO: Gem bundler is not installed, run `gem install bundler` first.
   !     ERROR: Deploy failed.

But when executed as 'root'

   Permission denied (publickey).
   fatal: The remote end hung up unexpectedly
   !     ERROR: Deploy failed.

This is part of my deploy.rb code

  task :env      do                                                                                                                                                                                                
    queue %{
      echo "-----> Loading environment"
      #{echo_cmd %[source ~/.bashrc]}
    }
  end

  desc "Deploys the current version to the server."
  task :afterdeploy do
    queue "export PATH=$PATH:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-1.9.2-p290/bin/bundle"
    queue 'source "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin"'
    queue "rvm rvmrc load"
    invoke :env
    deploy do
      # Put things that will set up an empty directory into a fully set-up
      # instance of your project.
      invoke :'git:clone'
      invoke :'bundle:install'
      #invoke :'rails:db_migrate'
      #invoke :'rails:assets_precompile'

      to :launch do
    #queue 'touch tmp/restart.txt'
      end
    end
  end  

@bluestrike2
Copy link

Assuming you setup your box as most people do, you won't be able to ssh in directly as root (nor should you or even need to). So that second response isn't a big deal. Anyhow, can can you scrub out any private details (if you have any in there) from your dotfiles (really just ~/.bashrc) and throw it up as a gist so I can take a peek and see what's going on?

You really shouldn't have to worry about invoking environment details like that from your scripts -- it can be bad enough in general, but it gets really untenable when you're dealing with a team and/or multiple servers.

@perumal
Copy link

perumal commented Jul 17, 2012

Hi bluestrike,

sorry to ask this basic question but I am not an expert in ubuntu

i am getting this following error

deploy@peru:~$ ~/.bashrc
-bash: /home/deploy/.bashrc: Permission denied
deploy@peru:~$ sudo ~/.bashrc
[sudo] password for deploy: 
sudo: /home/deploy/.bashrc: command not found

@rstacruz
Copy link
Member

@perumal if you want to execute your bashrc, try source ~/.bashrc.

But @bluestrike2 is looking for you to paste the contents of the file to him (ie, open it in a text editor and copying the contents to http://gist.github.com). Be use to scrub any personal details if any, like he said.

@rstacruz
Copy link
Member

Anyway: I've ran into a similar problem before, and I would venture to guess this is a multi-user RVM installation. Did you install RVM with sudo? When you type which rvm, does it say /usr/local/bin/rvm?

If so, you're running a multi-user, system-wide RVM installation. The best solution probably is to load the RVM environment manually:

  task :env do                                                                                                                                                                                                
    queue %{
      echo "-----> Loading environment"
      #{echo_cmd %[source "/usr/local/rvm/environments/ruby-1.9.3-p135@gemset"]}
    }
  end

Please ignore this advice if you're not using a multi-user RVM installation.

@perumal
Copy link

perumal commented Jul 17, 2012

Hi rstacruz,

You are right, I am using multi-user RVM installation I confirmed this by running the following command
deploy@peru:~$ which rvm
/usr/local/rvm/bin/rvm

But when i tired your above task :env code i got this error
deploy@peru:~$ source "/usr/local/rvm/environments/ruby-1.9.3-p135@gemset"
-bash: /usr/local/rvm/environments/ruby-1.9.3-p135@gemset: No such file or directory

Here is my deploy.rb code
https://gist.github.com/3129672

my $rvm info command shows following information

rvm:
    version:      "rvm 1.10.2 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]"
    updated:      "4 months 23 days 7 hours 3 minutes 20 seconds ago"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.3p125"
    date:         "2012-02-16"
    platform:     "i686-linux"
    patchlevel:   "2012-02-16 revision 34643"
    full_version: "ruby 1.9.3p125 (2012-02-16 revision 34643) [i686-linux]"

  homes:
    gem:          "/usr/local/rvm/gems/ruby-1.9.3-p125"
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p125"

  binaries:
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby"
    irb:          "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/irb"
    gem:          "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/gem"
    rake:         "/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake"

  environment:
    PATH:         "/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
    GEM_HOME:     "/usr/local/rvm/gems/ruby-1.9.3-p125"
    GEM_PATH:     "/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global"
    MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p125"
    IRBRC:        "/usr/local/rvm/rubies/ruby-1.9.3-p125/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

@perumal
Copy link

perumal commented Jul 17, 2012

Also Please guide me on how to avoid multi-user RVM installation.
What is the right way of installing to avoid these issues in future.
Thank you.

@rstacruz
Copy link
Member

Change the: ruby-1.9.3-p135@gemset ...to be the actual RVM env you wanna use

@hovsater
Copy link

Am I missing something crucial here? @rstacruz implemented the ability to define bash options through :bash_options, correct? The default value is for this setting is -i, which means the shell is an interactive one.

Although this setting is applied, executing mina deploy resulting in ~/.bashrc being read and return immediately due to the following.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

How come the shell executed isn't running interactively as one would expect?

I probably missing something here, so I would love if someone could clarify this issue.

@rstacruz rstacruz mentioned this issue Aug 7, 2012
@rstacruz
Copy link
Member

rstacruz commented Aug 7, 2012

@KevinSjoberg The easy fix now is to put the RVM invocation in your .bashrc on top of the $PS1 check you pasted.

@rstacruz rstacruz reopened this Aug 7, 2012
@rstacruz
Copy link
Member

rstacruz commented Aug 7, 2012

Anyway, reopening because I want explicit rbenv/rvm support implemented. This is a common hurdle people are running into and I want the experience to be as smooth as possible.

@perumal
Copy link

perumal commented Aug 7, 2012

+1 for reopening this issue.
Good to hear that this issue is reopened because I love mina and it's simplicity. Solving this one issue would help many, including me.
Thanks @rstacruz

@rstacruz
Copy link
Member

rstacruz commented Sep 8, 2012

@rstacruz rstacruz closed this as completed Sep 8, 2012
@edipofederle
Copy link

Still don't works!

@nanounanue
Copy link

Same problem ...

If I uncomment the line invoke :'rbenv:load' in config/deploy.rb I got this error:

-----> Loading rbenv
       $ export PATH="/usr/local/rbenv/bin/rbenv/bin:$PATH"
 !     rbenv not found
 !     If rbenv is installed, check your :rbenv_path setting.

 !     Command failed.
       Failed with status 1
vagrant@vagrant-ubuntu-saucy-64:~$  if ! which rbenv >/dev/null; then echo "! rbenv not found"; echo "! If rbenv is installed, check your :rbenv_path setting."; exit 1; fi
vagrant@vagrant-ubuntu-saucy-64:~$ 

i.e. rbenv is installed and working...

But if I leave the line commented (i.e. # invoke :'rbenv:load)

If I log in into the Vagrant box and execute the mina deploy --trace, the following happens:

    $ bundle install --without development:test --path "./vendor/bundle" --binstubs bin/ --deployment
       bash: line 97: bundle: command not found
 !     ERROR: Deploy failed.

@gpolyn
Copy link

gpolyn commented Apr 15, 2014

Similar problem, in Ubuntu 12.04...

 # ruby.deploy
  ...
  require 'mina/rbenv' 
  ...
  task :environment do
     invoke :'rbenv:load' 
  end
  ...

...results in the following failure:

-----> Installing gem dependencies using Bundler
       $ mkdir -p "/srv/www/app1/shared/bundle" 
       $ mkdir -p "./vendor" 
       $ ln -s "/srv/www/app1/shared/bundle" "./vendor/bundle" 
       $ bundle install --without development:test --pat       sh: 94: bundle: not found
       $ bundle install --without development:test --path "./vendor/bundle" --binstubs bin/ --deployment

Whereas, logged in as the same user, I can succeed in executing the problematic command manually:

bundle install --without development:test --path "./vendor/bundle" --binstubs bin/ --deployment

@syamilmj
Copy link

Try changing the SSH user shell to bash

chsh -s /bin/bash your_user

@Seaborg
Copy link

Seaborg commented Sep 10, 2014

Still a problem here! Ubuntu 14.
Ahh:
gem install bundler
sorted the problem actually

@born4new
Copy link

Hi there,

I just started using Mina, and I'm not using rbenv nor RVM at the moment.

I believe there has been some kind of regression here because I have the same initial problem of this thread: my bashrc is not taken into account. The export clauses fixed it aswell.

Thanks!

Edit: Not loading etc/profile either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests