Ask A Question

Notifications

You’re not receiving notifications from this thread.

Ruby issue when doing cap deploy production

Anthony Candaele asked in General

Hi, I'm following the Deploy Rails guide.

However, when I run

cap production deploy

I'm getting this error message:

$cap production deploy
DEBUG[be6b6bd6] Running /usr/bin/env [ -d ~/.rbenv/versions/2.0.0-p451 ] on 95.85.5.6
DEBUG[be6b6bd6] Command: [ -d ~/.rbenv/versions/2.0.0-p451 ]
DEBUG[be6b6bd6] Finished in 1.060 seconds with exit status 1 (failed).
ERRORrbenv: 2.0.0-p451 is not installed or not found in ~/.rbenv/versions/2.0.0-p451
cap aborted!

Not sure what's going on. I guess it has something to do with incompatible versions of Ruby, but is it the Ruby version on my local machine or on the VPS?

thanks for your help,

Anthony

Reply

That error says that on the server the ruby version you have doesn't match the one you set in your Capfile. You'll want to make sure the version in this file matches the version of Ruby on the server.

Reply

I see,

I changed the version in my Capfile to :

set :rbenv_ruby, '2.1.2-p95'

but now, when I run

cap production deploy

I get the error:

$cap production deploy
DEBUG[d2d51431] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.2-p95 ] on 95.85.5.6
DEBUG[d2d51431] Command: [ -d ~/.rbenv/versions/2.1.2-p95 ]
DEBUG[d2d51431] Finished in 0.980 seconds with exit status 1 (failed).
ERRORrbenv: 2.1.2-p95 is not installed or not found in ~/.rbenv/versions/2.1.2-p95
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 95.85.5.6: exit
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in `exit'
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in `block (3 levels) in     <top (required)>'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'

SystemExit: exit
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in exit'
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in
block (3 levels) in '
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in instance_exec'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in
run'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => rbenv:validate
(See full trace by running task with --trace)

I don't understand this, I ran 'ruby -v' on my Digital Ocean vps and it told me the Ruby version is:

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

greetings,

Anthony

Reply

If you type this command, what is the output? ls ~/.rbenv/versions/2.1.2-p95

Also, type which ruby and make sure the output is /home/deploy/.rbenv/shims/ruby

Reply

Hi Chris,

when I run the command as deploy user on the vps

which ~/.rbenv/versions/2.1.2-p95

I get no output, just a new cursor line

when I run

which ruby

I get

/home/deploy/.rbenv/shims/ruby

when I run

ruby -v

I get

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

I also try to solve the issue by changing the line in my Capfile from

set :rbenv_ruby, '2.1.2-p95'

to

set :rbenv_ruby, '2.1.2p95'

but that didn't fix it.

Reply

The second answer is good, shows that it's loaded rbenv correctly.

My bad on that first one, I meant ls ~/.rbenv/versions/2.1.2-p95

Reply

when I run

ls ~/.rbenv/versions/2.1.2-p95

on the vps, I get

ls: cannot access /home/deploy/.rbenv/versions/2.1.2-p95: No such file or directory
Reply

Well hmm, that's potentially your problem. That folder should exist to store your Ruby version in. I'm also running 2.1.2p25 on my machine, but I only have a ~/.rbenv/versions/2.1.2 folder.

Try using this instead:

set :rbenv_ruby, '2.1.2'
Reply

ok,

using

set :rbenv_ruby, '2.1.2'

fixed it.

However now I'm running in this error:

[62800640]  Warning: Permanently added 'github.com,some id' (RSA) to the list of known hosts.
DEBUG[62800640]     Permission denied (publickey).
DEBUG[62800640]     fatal: Could not read from remote repository.
DEBUG[62800640]     
DEBUG[62800640]     Please make sure you have the correct access rights
DEBUG[62800640]     and the repository exists.
DEBUG[62800640] Finished in 0.745 seconds with exit status 128 (failed).
Reply

Cool, so that's fixed. You'll need to check your git repo in the config to make sure it exists and/or add the forward_agent option to use your local keys for grabbing the code to the server from Github.

Reply

ok, again one step further

I ran

ssh-add ~/.ssh/id_rsa

in the terminal

and ran a new

cap deploy production

the deploy proces moved on, but then it failed with

Finished in 0.029 seconds with exit status 1 (failed).
ERRORlinked file /home/deploy/posplus/shared/config/database.yml does not exist on 95.85.5.6

I guess this has to do with the issue about creating the Postgres user which I reported about on this forum under the thread 'setup Postgres user fails'

Reply

You'll need to create the database.yml with a production config on the server in the folder that it mentions there since you don't have it in your repository. And yes, it'll need the configuration to postgres that you mentioned in the other thread.

Reply

Moved on again with the deployment proces, but the deployment still fails. Now there seems to be a problem with the bundle command

DEBUG[020e32cd] Command: cd /home/deploy/posplus/releases/20140904144347 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2    ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/posplus/shared/bin --path /home/deploy/posplus/shared/bundle --without   development test --deployment --quiet )
DEBUG[020e32cd]     rbenv: bundle: command not found

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 95.85.5.6: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: rbenv: bundle: command not found
Reply

Install bundler on the server:

gem install bundler
rbenv rehash
Reply

this is harder then I thought, I installed the bundler gem and now the next error is:

DEBUG[a18e2f6c]     rake aborted!
DEBUG[a18e2f6c]     ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
DEBUG[a18e2f6c]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/execjs-2.2.1/lib/execjs/runtim

Googled this issue, seems I have to install Node.js with:

sudo apt-get install nodejs
Reply

ok, now I guess I ran into the Posgres issue, I reported on:

DEBUG[00c3d123]     rake aborted!
DEBUG[00c3d123]     ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: []

I tried to solve this by adding settings for the production server in my local config.database.yml file

production:
  database: <database>
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <username> 
  password: <password>

but I keep getting the same error message:

rake aborted!
DEBUG[ffcbeda7]     ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: []
DEBUG[ffcbeda7]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/activerecord-    4.1.1/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection'
Reply

I configured the production database and now the capistrano script is passing the production database error.

Now I'm bumping into another error:

rake aborted!
DEBUG[53a69508]     ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[53a69508]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'

I guess this errror is related to the fact that my app is using Carrierwave and Fog and is storing uploaded images to Amazon S3.

Does this errror mean I should create Environment Variables for aws_access_key_id and aws_secret_access_key?

thanks for your help,

Anthony

Reply

I tried to add the environment variables to my vps environment with:

export S3_KEY='my key ...'
export S3_SECRET='my secret key'

but I'm keep getting the same error when I run 'cap production deploy':

DEBUG[4f41f85f]     rake aborted!
DEBUG[4f41f85f]     ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[4f41f85f]     /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'
Reply

If you're using Rails 4.1, you can use secrets.yml to set these variables or you can set them in the nginx configuration: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#about_environment_variables

Reply

thanks Chris, will try this out

greetings,

Anthony

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,842+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.