I am trying to deploy rails application but its stuck with the error
DEBUG[1a70ba92] Command: cd /home/deploy/myapp/releases/20140615090226 && ( PATH=$HOME/.rbenv /shims:$HOME/.rbenv/bin:$PATH RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/myapp/shared/bin --path /home/deploy/myapp/shared/bundle --without development test --deployment --quiet )
DEBUG[1a70ba92] rbenv: bundle: command not found
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xx: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: rbenv: bundle: command not found
deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'myapp'
set :repo_url, 'git#bitbucket.org:username/myapp.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/deploy/myapp'
# Default value for :scm is :git
# set :scm, :git
set :branch, "master"
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :default_env, { path: "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
end
desc "Symlink shared config files"
task :symlink_config_files do
run "#{ try_sudo } ln -s #{ deploy_to }/shared/config/database.yml #{ current_path }/config/database.yml"
end
end
capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_ruby, "2.1.2"
Production.rb
set :stage, :production
role :app, %w{deploy#xxx.xxx.xxx.xx}
role :web, %w{deploy#xxx.xxx.xxx.xx}
role :db, %w{deploy#xxx.xxx.xxx.xx}
set :password, ask('Server password', nil)
server 'xxx.xxx.xxx.xx', user: 'deploy', password: fetch(:password), roles: %w{web app}
/etc/nginx/nginx.conf
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com;
passenger_enabled on;
rails_env production;
root /home/deploy/myapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
which ruby
/home/deploy/.rbenv/shims/ruby
ruby -v
ruby 2.1.2p95
It is using right ruby version.But i guess trying to install gems in another folder.How can I fix it?
Have you tried installing the gem "bundler" first on your server? This gem is required to run the bundle command. SSH to your server and run the following command:
gem install bundler
Hope that helps
If you already have bundler installed (bundler -v) give this a try (it worked for me on Ubuntu 12.04 LTS):
1. gem uninstall bundler
2. gem update
3. gem install bundler
4. redeploy
It worked for me. I'm using Ubuntu 16.04.Change user below with your user name.
sudo pico /etc/profile.d/rbenv.sh
#File
export RBENV_ROOT=/home/user/.rbenv
export PATH=$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH
#End File
Update:
I find the reason: my .gemrc include "gem: --user-install", so the bundle not install in rbenv, and then rbenv can't find the bundle binary in 2.1.2 path
remove the --user-install config, and reinstall bundle resovle the problem.
===================================
I found that the RBENV_VERSION env cause bundle failed, but don't known why.
I remove the RBENV_VERSION and exec the cmd on the server, it succeed.
If you look at your .bashrc or .bash_profile, you will see something like that:
case $- in
*i*) ;;
*) return;;
esac
Or:
[ -z "$PS1" ] && return
This prevents everything after this line to be executed if the shell is not interactive.
Capistrano does not open an interactive shell.
If you are using rbenv for example, it adds lines at the end of your .bashrc.
These lines are not executed, so your ruby environment is not loaded.
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
Just move the rbenv lines at the start of your .bashrc, before the return explained above.
Related
I am using:
rails 4.2
unicorn server
nginx web server
capistrano for deployment.
If I am adding a new gem to gemfile it's not reflecting in the application. I tried to check a gem by using Gem.loaded_specs["koala"].full_gem_path but its not showing anywhere. I can see gem being bundled in the log and deployment gets completed successfully. But somewhere in between, I can see one error in Capistrano logs.
NOTE: Bundler is already installed.
cd /home/deploy/bloom/releases/20170516105043 && RAILS_ENV=dev bundle exec honeybadger deploy --environment dev --revision 08e4726 --repository git#bitbucket.org:appster/bloom-ruby.git --user arvindmehra
DEBUG[1450b9f0] **bash: bundle: command not found**
Here is my capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/honeybadger'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/rvm'
require 'whenever/capistrano'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Here is my deployment environment script from dev.rb
set :branch, 'dev'
set :keep_releases, 3
server '66.128.61.239',
user: 'deploy',
roles: %w{web app db},
ssh_options: {
user: 'deploy', # overrides user setting above
keys: %w(~/.ssh/id_rsa),
forward_agent: false,
#auth_methods: %w(publickey)
password: 'password'
}
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command do
on roles(:app), in: :sequence, wait: 1 do
execute "/etc/init.d/bloom-ruby #{command}"
end
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
Here is my deploy.rb
# config valid only for current version of Capistrano
lock '3.3.3'
set :application, 'bloom'
set :repo_url, 'git#bitbucket.org:appster/bloom-ruby.git'
set :deploy_to, '/home/deploy/bloom'
#set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Define which type of RVM the server is using
set :rvm_type, :user
set :rvm_ruby_version, '2.2.2#bloom'
# Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/secrets.yml config/settings.yml config/providers.yml config/stripe.yml}
# Default value for linked_dirs is []
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/identicons public/uploads public/images}
Deployment is in production mode.
RAILS_ENV=production bundle install
I'm having issues with running ruby gem commands while using Capistrano 3 with capistrano-rbenv (I'm assuming it can't find the ruby interpreter), specifically delayed_job. I've posted the necessary files associated with the issue:
`require': no such file to load -- rubygems (LoadError)
Any assistance would be greatly appreciated.
Gemfile
gem 'capistrano', "~> 3.6"
gem 'capistrano-rbenv', '~> 2.0'
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require "capistrano/rbenv"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
deploy.rb
# config valid only for current version of Capistrano
lock '3.6.1'
set :application, 'youtube_rank_tracker'
set :repo_url, './.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/dogecoin'
# Default value for :scm is :git
set :scm, :git
# Default value for :format is :airbrussh.
set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
# Default value for default_env is {}
# set :default_env, { path: '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH' }
# Default value for keep_releases is 5
set :keep_releases, 5
# set :default_env, { path: "$HOME/.rbenv/bin:$PATH" }
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all) do |host|
execute :mkdir, "-p #{release_path}/tmp"
execute :touch, release_path.join('tmp/restart.txt')
execute "cd #{release_path} && RAILS_ENV=production bin/delayed_job restart;"
# execute "cd #{release_path} && bundle exec rake -T"
end
end
end
after 'deploy:publishing', 'deploy:restart'
Error
he deploy has failed with an error: Exception while executing as root#.....: cd /.... && RAILS_ENV=production bin/delayed_job restart; exit status: 1
cd /.... && RAILS_ENV=production bin/delayed_job restart; stdout: /usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
from /usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:2
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:1:in `require'
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:1
Short answer
Instead of writing it yourself, use the semi-official Capistrano 3 Delayed Job integration Gem: https://github.com/AgileConsultingLLC/capistrano3-delayed-job
Long answer
If you were to actually write this yourself, capistrano-rbenv only affects a small default list of commands, as seen here: https://github.com/capistrano/rbenv/blob/master/lib/capistrano/tasks/rbenv.rake#L47
In this case, you'd probably want something like the following:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all) do |host|
within release_path do
execute :ruby, "bin/delayed_job", 'restart'
end
end
end
end
Instead of creating the tmp/ directory, add it to :linked_dirs in your config.
Also, it looks like you are touching tmp/restart.txt to restart Passenger. Alternatively, use the capistrano-passenger gem to do that. It can run in a newer mode which uses the passenger commands to restart your app, or you can tell it to use the touch file mechanism.
Finally, instead of using cd ${release_path}, use the within DSL method. That will accomplish the same thing and not break the command map.
I am trying to use capistrano (for the first time) to deploy my rails app. First the essentials, I am using:
ruby 1.9.3p362
Rails 3.2.13
rvm 1.24.7
Capistrano 3.0.1
Phusion Passenger 4.0.26
Ubuntu 12.04 LTS
I get the following error when attempting to run cap production deploy
DEBUG [679a47be] fatal: No remote configured to list refs from.
My full cap production deploy output is included below
INFO [488ba755] Running /usr/bin/env mkdir -p /tmp/AppName/ on sub.example.com
DEBUG [488ba755] Command: /usr/bin/env mkdir -p /tmp/AppName/
INFO [488ba755] Finished in 1.730 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/AppName/git-ssh.sh 0.0%
INFO Uploading /tmp/AppName/git-ssh.sh 100.0%
INFO [c895f068] Running /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh on sub.example.com
DEBUG [c895f068] Command: /usr/bin/env chmod +x /tmp/AppName/git-ssh.sh
INFO [c895f068] Finished in 0.217 seconds with exit status 0 (successful).
DEBUG [679a47be] Running /usr/bin/env git ls-remote on sub.example.com
DEBUG [679a47be] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/AppName/git-ssh.sh /usr/bin/env git ls-remote )
DEBUG [679a47be] fatal: No remote configured to list refs from.
DEBUG [679a47be] Finished in 1.775 seconds with exit status 128 (failed).
Gemfile
# Deploy with Capistrano
gem 'capistrano', '~> 3.0.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'rvm1-capistrano3', require: false
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy.rb
I have altered this file to add my git url, the app name, the deploy_to path, and the tasks inside task :restart as directed to restart Phusion Passenger.
set :application, 'AppName'
set :deploy_to, '/var/www/appname'
set :repository, "git#github.com:username/appname.git" # Your clone URL
set :scm, "git"
set :user, "my-github-deploy-user" # The server's user for deploys
set :scm_passphrase, "correct-password" # The deploy user's password
set :branch, "master"
set :deploy_via, :remote_cache
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :ssh_options, {
verbose: :debug
}
set :format, :pretty
set :log_level, :debug
# set :pty, true
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
within release_path do
execute :rake, 'cache:clear'
end
end
end
after :finishing, 'deploy:cleanup'
end
I tried to included all necessary information, please let me know if there is anything else I can add, thanks for any help you can provide!
In Capistrano 3, you use repo_url instead of repository
So in your deploy.rb, try replacing
set :repository, "git#github.com:username/appname.git" # Your clone URL
with
set :repo_url, "https://github.com/username/appname.git" # Your clone URL
Hopefully this helps.
Update: The ssh URL needs a key; the https URL does not. It's worked for me.
This is the first time I am deploying and getting errors.
here is my deploy.rb file
require 'bundler/capistrano'
set :application, "app"
set :scm, :git
set :repository, "git#github.com:myname/#{application}.git"
set :branch, "master"
server "198.12.78.92", :web, :app, :db, primary: true
set :user, "myname"
set :deploy_to, "/home/#{user}/public_html/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
Here is the error I am getting.
*** [deploy:update_code] rolling back
* executing "rm -rf /home/myname/public_html/app/releases/20130313073408; true"
servers: ["198.12.78.92"]
[198.12.78.92] executing command
command finished in 891ms
failed: "sh -c 'cp -RPp /home/myname/public_html/app/shared/cached-copy /home/myname/public_html/app/releases/20130313073408 && (echo dd92017bc8bb7f951df52d6a14c933e3033fd24b > /home/myname/public_html/app/releases/20130313073408/REVISION)'" on 198.12.78.92
EDIT - I have commented "set :deploy_via, :remote_cache" and now getting bundle: not found error though
OK It seems the answer is (see my comment to your question):
Have a recent rvm installed on both your workstation and the server (I have 1.17.1).
add:
gem 'rvm-capistrano'
to your Gemfile (inside group :development as the capistrano gem)
add:
require "rvm/capistrano"
require "bundler/capistrano"
to your config/deploy.rb
That should do it
If using rbenv put this in .bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
before the following line to capistrano load the environment even if connect with non-interactive shell
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
probably will also work also with rvm initialization
I've had the same problems. Below is solution for RBenv and RVM.
RBENV
Install correctly RBenv. Install bundler gem. Pefrorm 'rbenv rehash'.
Add to deploy.rb or deploy/.rb
set :default_environment, { 'PATH' => '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH' }
RVM
Install correctly RVM. Install bundler gem.
gem 'rvm-capistrano'
deloy.rb or deploy/.rb
require 'rvm/capistrano'
set :rvm_ruby_string, 'ruby-2.0.0-p247' # Change to your ruby version
set :rvm_type, :system # :user if RVM installed in $HOME
For further configuration info read: https://github.com/wayneeseguin/rvm-capistrano
Good luck.
I'm trying to deploy my first app to a VPS ubuntu 12.10, using capsitrano, and following the RailsCasts "Deploying to a VPS" videocast.
One more question, i haven't added an nginx config, nor a unicorn config file. Can i go without them? ( I will want to config nginx trough console.)
My deploy.rb file
require "bundler/capistrano"
set :application, "picurwebaruhaz"
set :scm, "git"
set :repository, "git://github.com/gwuix2/picurwebaruhaz.git"
set :branch, "master"
set :user, "gwuix2"
set :deploy_to, "/home/#{user}/#{application}"
default_run_options[:pty] = true
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
role :web, "198.211.117.84" # Your HTTP server, Apache/etc
role :app, "198.211.117.84" # This may be the same as your `Web` server
role :db, "198.211.117.84", :primary => true # This is where Rails migrations will run
role :db, "198.211.117.84"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
I get the following error:
* executing "cd /home/gwuix2/picurwebaruhaz/releases/20130322113243 && bundle install --gemfile /home/gwuix2/picurwebaruhaz/releases/20130322113243/Gemfile --path /home/gwuix2/picurwebaruhaz/shared/bundle --deployment --quiet --without development test"
servers: ["198.211.117.84"]
[198.211.117.84] executing command
** [out :: 198.211.117.84] sh: 1: bundle: not found
command finished in 357ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/gwuix2/picurwebaruhaz/releases/20130322113243; true"
servers: ["198.211.117.84"]
[198.211.117.84] executing command
command finished in 384ms
failed: "sh -c 'cd /home/gwuix2/picurwebaruhaz/releases/20130322113243 && bundle install --gemfile /home/gwuix2/picurwebaruhaz/releases/20130322113243/Gemfile --path /home/gwuix2/picurwebaruhaz/shared/bundle --deployment --quiet --without development test'" on 198.211.117.84
Edit:
Here is my app:
APP ON GITHUB https://github.com/gwuix2/picurwebaruhaz
Edit_2:
If I SSH into the server and run $ gem install bundler, it installs, but when I run:
gwuix2#picurbolt:~$ sudo gem install bundler sudo: gem: command not
found
any suggestions?
Can't figure it out myself.
deploy.rb needs:
require "rvm/capistrano"
require "bundler/capistrano"
Try running bundler command without sudo:
gwuix2#picurbolt:~$ gem install bundler sudo: gem: command not found