Capistrano can not read ENV variables - ruby-on-rails

I'm using Capistrano for deploying my Rails app. and now Im facing error below when I enter commandcap production deploy` :
✔ 02 deploy#82.196.13.29 0.475s
04:44 webpacker:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber
(Backtrace restricted to imported tasks)
cap aborted!
Errno::ENOENT: No such file or directory - ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber )
Tasks: TOP => webpacker:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: No such file or directory - ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.5" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rails webpacker:clobber )
And this is my deploy.rb file:
lock "~> 3.11.0"
set :application, "appName"
set :repo_url, "git#github.com:githubusername/appName"
# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"
set :default_env, {
'RBENV_ROOT' => '$HOME/.rbenv',
'RBENV_VERSION' => '2.5.5',
'RAILS_ENV' => 'production'
}
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# Only keep the last 5 releases to save disk space
set :keep_releases, 5
before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
desc 'Run rake yarn:install'
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install")
end
end
end
end
after 'deploy:updated', 'webpacker:precompile'
I'm using Rails 5.2.3 and Ruby 2.5.5 in this application. I also have a file .rbenv in /home/deploy/appName and contains these variables:
RAILS_MASTER_KEY=ohai
SECRET_KEY_BASE=1234567890
STRIPE_PUBLIC_KEY=x
STRIPE_PRIVATE_KEY=y
How can I fix this problem?

Related

cannot load such file -- rspec/core/rake_task with capistrano

I'm not ruby on rails. When I launch :
cap integration deploy
I get an error :
INFO [90feb630] Running /usr/local/rvm/bin/rvm ruby-2.4.0#myproject_gemset do bundle exec rake assets:precompile as myproject#myproject-server.com
DEBUG [90feb630] Command: cd /home/myproject/myproject_rails/releases/20170703135523 && ( export RAILS_ENV="staging" RAILS_GROUPS="" ; /usr/local/rvm/bin/rvm ruby-2.4.0#myproject_gemset do bundle exec rake assets:precompile )
DEBUG [90feb630] rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
Here my capistrano config file for deploying :
set :user, 'myproject'
server 'myproject-server.com',
user: fetch(:user),
roles: %w{web app db},
ssh_options: {forward_agent: true}
set :deploy_to, "/home/#{fetch(:user)}/#{fetch(:application)}"
set :rails_env, 'staging'
set :conditionally_migrate, true
set :keep_releases, 2
set :branch, 'master'
set :app_version, '0.1'
Edit
The issue is from the file /lib/tasks/integration.rake :
require 'rspec/core/rake_task'
namespace :integration do
desc 'integration test the JSON API endpoints'
RSpec::Core::RakeTask.new(:test) do |t|
# set the RAILS_ENV such that :integration tagged
# specs are run
ENV['RAILS_ENV'] = 'test'
# only run those files in the 'integration' directory
t.pattern = './spec/integration{,/*/**}/*_spec.rb'
end
end
The gem 'rspec-core' where only installed in dev / test env.
So it was missing.
Putting
gem 'rspec-core', '~> 3.4'
Out of
group :development, :test do
Solved my issue
I needed to do gem install rspec-core

Capistrano doesn't install

Whenever I try to run cap production deploy it fails at the following command
[ebbf9fde] Command: cd /var/www/apps/my_app/releases/20150803171251 && /usr/local/rvm/bin/rvm 2.2.2 do bundle install --path /var/www/apps/my_app/shared/bundle --without development test --deployment --quiet
DEBUG [ebbf9fde] /usr/local/rvm/scripts/set: line 19: exec: bundle: not found
I have a added a user 'deploy' to do this deployment, the ouput of rvm list is
$ rvm list
rvm rubies
=* ruby-2.2.2 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Further running gem list the output is
$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.6)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.3)
json (1.8.1)
minitest (5.4.3)
passenger (5.0.15)
power_assert (0.2.2)
psych (2.0.8)
rack (1.6.4)
rake (10.4.2)
rdoc (4.2.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (3.0.8)
My Capfile contents are
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Finally my deploy.rb contains the following data.
lock '3.4.0'
set :app_host, 'ip-address-here'
set :application, 'my_app'
set :repo_url, 'git#example.com:<not_right>/my_app.git'
set :rvm_type, :system
set :rvm_ruby_version, '2.2.2'
set :passenger_rvm_ruby_version, '2.2.2'
set :rbenv_ruby, '2.2.2'
set :deploy_to, '/var/www/apps/my_app'
set :scm, :git
set :format, :pretty
set :log_level, :debug
set :pty, true
set :conditionally_migrate, true
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :keep_releases, 5
set :migrate_env, "#{ fetch(:stage) }"
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:web), in: :sequence, wait: 5 do
execute :mkdir, '-p', release_path.join('tmp')
execute :touch, release_path.join('tmp/restart.txt')
end
end
task :httpd_graceful do
on roles(:web), in: :sequence, wait: 5 do
execute :sudo, "service httpd graceful"
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
namespace :deploy_prepare do
desc 'Configure virtual host'
task :create_vhost do
on roles(:web), in: :sequence, wait: 5 do
vhost_redirect_config = <<-EOF
Redirect permanent /#{ fetch(:application) } http://#{ fetch(:app_host) }/#{ fetch(:application) }/
EOF
vhost_location_config = <<-EOF
Alias /#{fetch(:application)} #{fetch(:deploy_to)}/current/public
<Location /#{fetch(:application)}>
PassengerBaseURI /#{ fetch(:application) }
PassengerAppRoot #{ fetch(:deploy_to) }/current/
PassengerRuby /usr/local/rvm/wrappers/ruby-#{ fetch(:rvm_ruby_version) }/ruby
RailsEnv #{ fetch(:stage) }
</Location>
<Directory #{ fetch(:deploy_to) }/current/public >
Allow from all
Options -MultiViews
</Directory>
EOF
execute :echo, "\"#{ vhost_redirect_config }\"", ">", "/etc/httpd/conf.d/redirects/#{ fetch(:application) }.conf"
execute :echo, "\"#{ vhost_location_config }\"", ">", "/etc/httpd/conf.d/apps/#{ fetch(:application) }.conf"
end
end
end
after "deploy:updated", "deploy:cleanup"
after "deploy:finished", "deploy_prepare:create_vhost"
after "deploy_prepare:create_vhost", "deploy:httpd_graceful"
after "deploy:httpd_graceful", "deploy:restart"
I am getting the following error
DEBUG [298e6d4e] Command: cd /var/www/apps/oxygen/releases/20150803172155 && /usr/local/rvm/bin/rvm 2.2.2 do bundle install --path /var/www/apps/oxygen/shared/bundle --without development test --deployment --quiet
DEBUG [298e6d4e] /usr/local/rvm/scripts/set: line 19: exec: bundle: not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer#162.243.131.67: bundle exit status: 127
bundle stdout: /usr/local/rvm/scripts/set: line 19: exec: bundle: not found
bundle stderr: Nothing written
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: /usr/local/rvm/scripts/set: line 19: exec: bundle: not found
bundle stderr: Nothing written
Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer#162.243.131.67: bundle exit status: 127
bundle stdout: /usr/local/rvm/scripts/set: line 19: exec: bundle: not found
bundle stderr: Nothing written
Just try gem install bundler on the server once to install bundler into the rvm gemset, as its not in the list of your gem list.
In general try to ensure that the bundle command runs when you log into your server via ssh. Capistrano doesn't do magic, it just logs in via ssh and issues commands. You can always see what commands capistrano issues, like in your example cd /var/www/apps/oxygen/releases/20150803172155 && /usr/local/rvm/bin/rvm 2.2.2 do bundle install --path /var/www/apps/oxygen/shared/bundle --without development test --deployment --quiet and try them yourself when something fails.
Be sure you have bundler installed in the correct gemset.
I got this error and was scratching my head because bundler was installed in the default gemset, but it was not in the one I was using for my rails application.
When I realized it I was like, "doh!"
Just thought I would post this here, hopefully it will help someone else.
This didnt work for me, gem install bundler
I realized I didn't set my deploy.rb file correctly.
So because I am using RVM, I checked the rvm list for the ruby version
jruby-1.7.19 [ x86_64 ]
=* ruby-2.2.1 [ x86_64 ]
then config my deploy.rb file to set :rvm_ruby_version, 'ruby-2.2.1'
On your server
rvm 2.2.2#gemset-name do gem install bundler
Source: https://github.com/capistrano/rvm/issues/65#issuecomment-94108188

"bash: bundle: command not found" - cap aborted

here is my deployment.rb file.
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git#github.com:narhamah/gobgob-ror.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, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# 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
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('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" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
Now I did bundle exec cap production deploy. And after huge log I got the below error.
DEBUG [cced60a1] bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
SSHKit::Command::Failed: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
[arup#gobgob-ror (master)]$
Looks like the bundler gem is not installed on your server. It should be installed and the bundle executable should be available in $PATH.
Try executing the bundle --version directly on the server to ascertain that bundler is actually missing.
If that is case, install the bundler gem and you should be good to go. Or to actually keep things automated you can define a capistrano task to check if the bundle executable is available or not and install the bundler gem if it is not available. You can execute this task before the bundler:install task.
UPDATE : If you are using some ruby manager like rvm or chruby or anything like that, the bundle executable might not be available to your Capistrano deploy task. In that case you have to make sure your deploy task gets a login shell so that all those shell scripts are executed.
Here is what I have now which resolved the issue. I got help from Rustam A. Gasanov to make it working. Thanks a lot!!
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git#github.com:narhamah/gobgob-ror.git'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.2#gobgob'
set :rvm_binary, '~/.rvm/bin/rvm'
# 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, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# 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
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('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" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
Last output which confirmed it works..
INFO [12d4a428] Running /usr/bin/env cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2#gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart on xx.xx.xxx.xxx
DEBUG [12d4a428] Command: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2#gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart
DEBUG [12d4a428] Command restart sent success
DEBUG [12d4a428]
INFO [12d4a428] Finished in 1.379 seconds with exit status 0 (successful).
[arup#gobgob-ror (master)]$

Capistrano deploy - assets precompile error

I am deploying with Capistrano to my new VPS. After the first deploy(cap deploy) everything was OK (site was running), but the second deploy failed on assets:precompile error.
I am running rails 3.2.13, ruby 2.0.0, rvm.
error:
* executing "cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile"
servers: ["IP"]
[IP] executing command
*** [err :: IP] bash: line 1: 23406 Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
command finished in 84187ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/rails/releases/20140116121250; true"
servers: ["IP"]
[IP] executing command
command finished in 519ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd -- /home/rails/releases/20140116121250 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'" on IP
deploy.rb file:
set :application, "app_name"
set :repository, "git_repository"
role :web, "IP"
role :app, "IP"
role :db, "IP", :primary => true
set :user, "rails"
set :password, "password"
set :use_sudo, false
set :deploy_to, "/home/rails/"
set :deploy_via, :copy
set :normalize_asset_timestamps, false
require 'bundler/capistrano'
require "rvm/capistrano"
set :rvm_type, :system
Capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
I am quite new to Capistrano, so please try to explain the solution clearly. Thank You for your support!
It seems as you have low operation memory size on your vpn server. (Vpn supplies without memory-swap for now) thus operation system kills your deploy process.
The solution is to compile assets locally (on your development machine)
Add deploy:assets:precompile task to your deploy.rb file (this is for Capistrano 2)
namespace :deploy do
. . .
namespace :assets do
task :precompile, :roles => :web do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
end
end
Then just redeploy you app
$ bundle exec cap deploy
wish it helps

How do I configure remote refs for git + capistrano 3 in ROR deployment?

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.

Resources