I'm deploying to a VPS using capistrano, based on the guide at RailsCasts.
http://railscasts.com/episodes/335-deploying-to-a-vps?view=asciicast
It's failing on the deploy:cold command, with a conflict with Ruby. I actually can't see what the problem is, as when I shell into the same user the Ruby version looks correct.
$ cap shell
cap> which ruby
[establishing connection(s) to 192.xxx.xxx.xxx]
** [out :: 192.xxx.xxx.xxx] /home/deployer/.rbenv/shims/ruby
cap> ruby -v
** [out :: 192.xxx.xxx.xxx ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
This is the error:
command finished in 655ms
* 2013-07-01 16:40:39 executing `bundle:install'
* executing "cd /home/deployer/rails/assay/releases/20130701144038 && bundle install -- gemfile /home/deployer/rails/assay/releases/20130701144038/Gemfile --path /home/deployer/rails/assay/shared/bundle --deployment --quiet --without development test"
servers: ["192.xxx.xxx.xxx"]
[192.xxx.xxx.xxx] executing command
** [out :: 192.xxx.xxx.xxx] rbenv: version `1.9.3' is not installed
command finished in 662ms
*** [deploy:update_code] rolling back
My question is: how can I debug this? When I read the deploy.rb file I can't see where it even references the Ruby version. Pretty frustrating, I am about ready to ftp the repo up, which is not ideal obviously.
Well I finally got to the bottom of the issue - a mismatch between ruby versions use by Capistrano and what was actually on the server.
To debug Capistrano run it like this:
cap deploy:cold -d
That was you can step through the commands and access the temporary directories on the remote server before they are deleted.
I just had similar issue, the reason was .ruby-version file pointing at 1.9.3 (file was generated by rails-composer), while there was 1.9.3-p392 installed via rbenv on remote machine.
Debug info of capistrano can be shown by tail -f log/capistrano.log.
Related
I have a previously deployed Ruby on Rails API that I wanted to add some additional seed data to.
I am getting the following error when I deploy from either the Heroku CLI or from the web interface:
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.5
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
Bundler Output: bash: /tmp/build_9062c7d5995d7f7c573d9509eb8f19d5/bin/bundle: cannot execute binary file: Exec format error
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
I am not sure what the issue is. I have tried:
Deploying to a brand new Heroku application
Adding a Procfile
Adding a Ruby build pack
Resolving some outstanding security warnings from Github by running Bundle update locally and getting the new gemfile into my repo, prior to this there were no new Gem changes
None of these has changed the error I am getting.
If I clone the repo from github into a new folder on my Macbook I am able to get it up and running locally.
I have the following on my Macbook:
Ruby Version 2.6.5p114
Rails Version 6.0.3.2
Google does not seem to be turning up much, aside from some references to CPU architecture which I assume I have no control of in the Heroku environment.
My feeling is that it is related to bash being unable to execute bin/bundle but I've no idea why or how to resolve.
I vaguely recall having issues previously on this app, in that I was not able to run heroku run rake commands, possibly getting a similar error message, but to resolve I think I was able to simply run heroku run bin/rake
I believe the original rails new command was run on Windows 10 WSL environment in case that is relevant.
EDIT: I'm able to recreate a similar issue with rake, but the fix for rake does not work for bundle and I'm not even sure if it would help with the deployment issue.
➜ appbackend git:(master) heroku run rake
Running rake on ⬢ heroku-name-40049... up, run.8396 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/rake
Running bin/rake on ⬢ heroku-name-40049... up, run.5201 (Hobby)
Abort testing: Your Rails environment is running in production mode!
➜ appbackend git:(master)
➜ appbackend git:(master) heroku run bundle install
Running bundle install on ⬢ heroku-name-40049... up, run.7746 (Hobby)
bash: /app/bin/bundle: cannot execute binary file: Exec format error
➜ appbackend git:(master) heroku run bin/bundle install
Running bin/bundle install on ⬢ heroku-name-40049... up, run.4632 (Hobby)
bash: bin/bundle: cannot execute binary file: Exec format error
Turns out it was exactly as the error message stated Exec format error.
The bundle file in the bin directory was not the right format. Not sure how I managed to deploy in the first place (the history of this file has only 2 version in the repo, the first commit, and now the fix).
I was able to resolve by overwriting the bundle file from a different working rails install. Appreciated the help provided.
EDIT:
The issue here was that I used RVM on my local machine and rbenv on the server. This is highly not recommended, if you're managing several ruby installation (or upgrading your ruby version but do not want to change the system's) use either RVM or rbenv on all environments!
/EDIT
So I'll start with a bit history:
I'm in the process of upgrading our rails2 website to rails3. Most of the things are working properly by now, except Capistrano's deploy script.
The current setup I have is:
RVM (1.14.1) installed locally
ruby-1.9.3-p194 (set to the project's folder)
Capistrano v2.12.0 (upgraded from 2.6.0, but it doesn't work on 2.6.0 as well) installed as an RVM gem
rvm-capistrano (1.2.2), added to the Gemfile (after doing some reading online and on SO)
rbenv (with ruby 1.9.3p194 used globally) installed on the server
(by now if you see anything that doesn't make sense, please let me know)
Nothing changed in the deploy script, yet when I try to deploy to my testing server (let's call it beta) I get this error:
* executing `deploy:restart'
* executing "cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers"
servers: ["208.0..."]
[208.0...] executing command
*** [err :: 208.0...] rake aborted!
*** [err :: 208.0...] no such file to load -- bundler/setup
*** [err :: 208.0...] /home/foo/bar/releases/20120630161947/Rakefile:5
*** [err :: 208.0...] (See full trace by running task with --trace)
** [out :: 208.0...] (in /home/foo/bar/releases/20120630161947)
command finished in 1183ms
failed: "sh -c 'cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers'" on 208.0...
The relevant part on deploy.rb looks like this:
task :restart do
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} queue:restart_workers"
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} db:migrate"
run "touch #{deploy_to}/current/tmp/restart.txt"
end
Needless to say, rake RAILS_ENV=beta queue:restart_workers' works perfectly when run manually on the server. Also, the application gets deployed (the code was copied from git, it's just the last part of the deploy fails).
Lastly, the error didn't change since before I installed rvm-capistrano and added to the Gemfile, so I'm not even sure it's related to rvm, I'm just guessing from looking online.
Thanks
In order to work correctly, rbenv must override all the ruby and gem-related executables with the shims it provides.
Usually this is done with a startup script (this is why it works when you login to your server) but Capistrano logs in without shell and thus does not run those scripts.
You must add the following to your deploy.rb :
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
and do not use anything rvm related on your server, rbenv and rvm really do not like each other
PS : a little more explanation on this topic : http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/
Made a large update last night and my site is currently down. I used cap deploy:rollback with no luck. The error logs aren't telling me much. The last error I saw when trying to deploy was:
** [out :: website.com] You are trying to install in deployment mode after changing
** [out :: website.com] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: website.com] updated Gemfile.lock to version control.
** [out :: website.com]
** [out :: website.com] You have deleted from the Gemfile:
** [out :: website.com] * asset_sync
command finished in 934ms
My cap tail just says the following with no errors:
Migrating to AddSessionsTable (20120722094547)
Migrating to AddSlugToUserProjects (20120723204816)
Migrating to AddSlugIndexToUserProjects (20120723205558)
Migrating to CreateFriendlyIdSlugs (20120723210904)
Migrating to AddNameToUsers (20120723221700)
Migrating to AddSlugToUsers (20120723222456)
Migrating to CreateComments (20120724203252)
Any help?
Run bundle install on your development server, then cap deploy. Another possible solution: add asset_sync back to your Gemfile.
As last resort, you can run cap -d deploy. It will run deployment step-by-step, asking you for continue on each step. Login to production server in separate shell and do some adjustments between steps manually.
It looks like the Gemfile change didn't go well. How it was fixed:
logged into server, there were 6 ruby processes that were taking all available things. This is almost certainly the unicorn processes trying to start and couldn't… killall -9 ruby
cd into the app's current directory
RAILS_ENV=production bundle exec rake assets:precompile
service unicorn_whimseybox start
It looks like (in the unicorn.log), the error was:
E, [2012-07-26T17:27:10.552912 #24818] ERROR -- : uninitialized constant AssetSync (NameError)
I had the same error after converting some Gemfile source lines into blocks.
The error was due an old Bundler version on production (1.7.3) vs 1.8.3 on development.
I'm getting this error when running this capistrano task (my own - cap deploy:show_pointers):
* executing `deploy:show_pointers'
* executing "cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers"
servers: ["mydomain.net"]
[mydomain.net] executing command
** [out :: mydomain.net] (in /home/mydomain/public_html/site_folders/rails/releases/20120521025150)
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
command finished in 1584ms
failed: "sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers'" on mydomain.net
However when I run
sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers
manually from the same dir that capistrano logs into, it works. I have capistrano set to NOT USE sudo, so that shouldn't be the issue, but it sounds like it might be, since the above command fails with sudo. I think this is a user issue, or maybe an environment var issue. Or I'm not sure what.
Any suggestsions. This is a task that is already a rake task, but it will help me not to have to log into the server every time I run it (and about 10 more like it).
Appreciate any help on this.
manually from the same dir that capistrano logs into, it works.
That doesn't say anything, Capistrano creates a non-login tty, which means that your profile, dot-files, etc are not run.
ssh root#example.de -t /bin/sh
This is a more reliable way to compare environments to Capistrano, (although, even this is a little more full-featured than what Capistrano is using.
Given these error messages, I have a couple ideas:
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
The app can't find the rake command. Have you tried to run bundle install on the remote machine as its recommending?
Another option might be to change the command to
cd /home/mydomain/public_html/site_folders/rails/current; bundle exec rake app:show_pointers
Using bundle exec might be recommended in front of the command depending on the ruby environment on the remote servers.
#dbra over on stack overflow has pointed out that I need the full path to rake.
I am running into an issue when trying to run migrations from capistrano (cap deploy:migrate).
latest => /var/www/site/releases/20110108002015
* executing "cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate"
servers: ["www.site.com"]
[www.site.com] executing command
** [out :: www.site.com] (in /var/www/site/releases/20110108002015)
** [out :: www.site.com] Could not find treetop-1.4.9 in any of the sources
** [out :: www.site.com] Try running `bundle install`.
command finished
failed: "sh -c 'cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate'" on www.site.com
The facts;
Rails 3.0.0
Ruby 1.9.2 via rvm
The treetop gem is installed, and if I ssh into the remote server and run the command that capistrano is attempting manually, it works without issue.
Anyone else run into this or a similar issue?
When you ssh onto the server and run the command, is it using the same user capistrano is deploying as? Often issues like this are due to the deploy users path not including the same folders as your path might.
Try using cap shell to run the command, then you can test it under the same conditions cap is under.