I am following this tutorial for setting up a webserver for a simple rails app: https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma with nginx and capistrano.
my deploy.rb file:
# Change these
server '45.33.11.11', port: 22, roles: [:web, :app, :db], primary: true
set :repo_url, 'git#bitbucket.org:slucha/supplement.git'
set :application, 'supplementtests'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
# set :log_level, :debug
# set :keep_releases, 5
## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
and Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
require "capistrano/scm/git"
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
install_plugin Capistrano::Puma
install_plugin Capistrano::SCM::Git
Nginx is installed, ssh keys are set up for both bitbucket ssh and deploy keys for the repo and rvm ist also installed on the server
The cap staging deploy:check command passes without errors but when I try to run cap production deploy:initial I get the following error
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env
** Invoke rvm:hook (first_time)
** Execute rvm:hook
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as root#45.79.147.60: Net::SSH::ConnectionTimeout
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:90:in `rescue in initialize'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:57:in `initialize'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `new'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `start'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `call'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `with'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:176:in `with_ssh'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:129:in `execute_command'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `tap'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:55:in `test'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:21:in `block (3 levels) in <top (required)>'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `run'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Errno::ETIMEDOUT: Connection timed out - connect(2) for 45.79.147.60:22
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:65:in `connect'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:65:in `connect_internal'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:140:in `connect'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:338:in `block in tcp'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:232:in `each'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:232:in `foreach'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/2.2.0/socket.rb:328:in `tcp'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh/transport/session.rb:70:in `initialize'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `new'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/net-ssh-4.2.0/lib/net/ssh.rb:237:in `start'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `call'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/connection_pool.rb:59:in `with'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:176:in `with_ssh'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/netssh.rb:129:in `execute_command'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `tap'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:55:in `test'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:21:in `block (3 levels) in <top (required)>'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/backends/abstract.rb:29:in `run'
/home/jan/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sshkit-1.15.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => rvm:hook
Any ideas why there is a timeout?
UPDATE
ssh -T git#bitbucket.org gives message:
logged in as slucha.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
ssh -T deploy#45.33.95.53 gives
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.9.64-x86_64-linode88 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The problem was that I had two conflicting settings between the deploy.rb and production.rb
make sure that your settings in both files are correct.
in my production.rb I had the following line:
server '53.33.95.53', user: 'deploy', roles: %w{web app}
Which was overwriting the current ip address and was causing the timeout.
Related
I'm trying to deploy my Ruby app using capistrano (repository is on gitlab) and I get this error:
>> cap production deploy
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Net::SSH::AuthenticationFailed: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer>
My ~/.ssh/config:
Host gitlab.com
IdentityFile ~/.ssh/id_rsa
User git
PreferredAuthentications publickey
ForwardAgent yes
My deploy.rb:
set :branch, ENV['BRANCH'] || 'master'
set :application, 'example'
set :repo_url, 'ssh://git#gitlab.com/xxxx/xxxxxxxxx.git'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'
set :deploy_to, '/home/deployer/example'
set :scm, :git
set :log_level, :debug
set :linked_files, %w{config/database.yml config/initializers/s3.rb config/redis.yml config/skylight.yml config/sunspot.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads solr}
set :keep_releases, 10
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :whenever_roles, :app
namespace :deploy do
desc 'Compile assets'
task :gulp_build do
on roles(:app) do
within "#{release_path}/app/assets/javascripts/app" do
with bower_registry: 'http://registry.bower.io' do
execute :bower, 'install -s'
end
end
within release_path do
execute :npm, 'install --silent'
execute :bundle, 'exec gulp build --production'
end
end
end
%i(start stop restart force_stop reload).each do |task_name|
namespace :unicorn do
task task_name do
invoke "unicorn:#{task_name}"
end
end
end
%i(start stop restart).each do |task_name|
namespace :solr do
task task_name do
invoke "solr:#{task_name}"
end
end
end
after :publishing, 'deploy:gulp_build'
after :publishing, 'deploy:unicorn:restart'
end
set :unicorn_conf_path, "#{release_path}/config/unicorn/#{fetch(:stage)}.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
namespace :unicorn do
def run_unicorn
execute :bundle, 'exec unicorn', '-c', fetch(:unicorn_conf_path), '-E', fetch(:rails_env), '-D'
end
desc 'Start unicorn'
task :start do
on roles(:app) do
within current_path do
run_unicorn
end
end
end
desc 'Stop unicorn'
task :stop do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-QUIT `cat #{fetch(:unicorn_pid_path)}`"
end
end
end
end
desc 'Force stop unicorn (kill -9)'
task :force_stop do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-9 `cat #{fetch(:unicorn_pid_path)}`"
execute :rm, fetch(:unicorn_pid_path)
end
end
end
end
desc 'Restart unicorn; use this when preload_app: true'
task :restart do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-USR2 `cat #{fetch(:unicorn_pid_path)}`"
else
run_unicorn
end
end
end
end
desc 'Restart unicorn; use this when preload_app: false'
task :reload do
on roles(:app) do
within current_path do
if test "[ -f #{fetch(:unicorn_pid_path)} ]"
execute :kill, "-HUP `cat #{fetch(:unicorn_pid_path)}`"
else
run_unicorn
end
end
end
end
end
namespace :solr do
%i(start stop).each do |task_name|
desc "Sunspot solr #{task_name}"
task task_name do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env, 'production') do
execute :bundle, 'exec', :rake, "sunspot:solr:#{task_name}"
end
end
end
end
end
desc "Sunspot solr restart"
task :restart do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env, 'production') do
execute :bundle, 'exec', :rake, "sunspot:solr:stop"
sleep 5
execute :bundle, 'exec', :rake, "sunspot:solr:start"
end
end
end
end
end
My production:
set :rails_env, :production
set :application, 'example-production'
set :rbenv_ruby, '2.2.10'
set :branch, 'api'
set :deploy_to, '/home/deployer/api'
set :unicorn_conf_path, "#{release_path}/config/unicorn/proapi.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
server 'xxx.xxx.xx.xx', user: 'deployer', roles: %w{web app db}
Try add the allowed ssh keys to your production machine/ server. That is:
run cat ~/.ssh/id_rsa.pub on your local machine
Then run ~/.ssh/authorized_keys on your server/production machine
Copypaste the result of step 1 above in your authorized_keys file on your server
then run cap production deploy command again
Incase you don't see authorized_keys file when run ~/.ssh/authorized_keys
you can combine all the above commands that is 1 to 3 by running
cat ~/.ssh/id_rsa.pub | ssh USER#HOST "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys".
Thanks for the help!
Unfortunately, yesterday I was tired and inattentive. The problem was really the wrong user. I replaced git with a deployer and everything started up.
I've been at this for about 16 hours and throwing in the towel. I've successfully deployed an rails app with capistrano before and I copied everything initially, but I can't get past assets:precompile. Migration doesn't work either, but one thing at the time.
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require "capistrano/rbenv"
#require "capistrano/bundler"
require "capistrano/rails"
#require "capistrano/rails/assets"
#require "capistrano/rails/migrations"
require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
config/deploy.rb
set :application, 'livelyteams'
set :repo_url, 'https://github.com/unusualslim/livelyteams'
set :puma_threads, [4,16]
set :puma_workers, 0
set :rbenv_ruby, '2.6.5'
set :rails_env, 'production'
append :linked_files, "config/master.key"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# append :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# 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/dev/apps/livelyteams'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, File.read('.ruby-version').strip
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :default_env, {
PATH: '$HOME/.npm-packages/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}
# Default value for :scm is :git
# set :scm, :git
# 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, 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
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
namespace :deploy do
namespace :check do
before :linked_files, :set_master_key do
on roles(:app), in: :sequence, wait: 10 do
unless test("[ -f #{shared_path}/config/master.key ]")
upload! 'config/master.key', "#{shared_path}/config/master.key"
end
end
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app) do
execute "#{fetch(:rbenv_prefix)} pumactl -P ~/app/current/tmp/pids/puma.pid phased-restart"
end
end
end
after 'deploy:publishing', 'deploy:restart'
config/deploy/production.rb
set :stage, :production
set :branch, "master"
server 'livelyteams.com', user: "dev", port: 22, roles: %w{app db web}, primary: true
I think it's related to RAILS_ENV=production, but I've tried everything I could think of.
and the capistrano.log
DEBUG [b2a3647b] Command: cd /home/dev/apps/livelyteams/releases/20200918213106 && yarn install
DEBUG [b2a3647b] yarn install v1.21.1
DEBUG [b2a3647b] info No lockfile found.
DEBUG [b2a3647b] [1/4] Resolving packages...
DEBUG [b2a3647b] [2/4] Fetching packages...
DEBUG [b2a3647b] [3/4] Linking dependencies...
DEBUG [b2a3647b] [4/4] Building fresh packages...
DEBUG [b2a3647b] success Saved lockfile.
DEBUG [b2a3647b] Done in 0.15s.
INFO [b2a3647b] Finished in 0.592 seconds with exit status 0 (successful).
DEBUG [d8f59b17] Running if test ! -d /home/dev/apps/livelyteams/releases/20200918213106; then echo "Directory does not exist '/home/dev/apps/livelyteams/releases/20200918213106'" 1>&2; false; fi as dev#livelyteams.com
DEBUG [d8f59b17] Command: if test ! -d /home/dev/apps/livelyteams/releases/20200918213106; then echo "Directory does not exist '/home/dev/apps/livelyteams/releases/20200918213106'" 1>&2; false; fi
DEBUG [d8f59b17] Finished in 0.042 seconds with exit status 0 (successful).
INFO [cbdabd40] Running RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as dev#livelyteams.com
DEBUG [cbdabd40] Command: cd /home/dev/apps/livelyteams/releases/20200918213106 && ( export PATH="$HOME/.npm-packages/bin/:$PATH" NODE_ENVIRONMENT="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.5" RAILS_ENV="production" RAILS_GROUPS="" ; RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG [cbdabd40] rake aborted!
DEBUG [cbdabd40] ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
DEBUG [cbdabd40] /home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:183:in `_decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:79:in `decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:42:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:21:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:33:in `config'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:38:in `options'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:10:in `find'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `instance_exec'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `run'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:60:in `run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:361:in `initialize!'
/home/dev/apps/livelyteams/releases/20200918213106/config/environment.rb:5:in `<main>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:337:in `require_environment!'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
DEBUG [cbdabd40]
Caused by:
DEBUG [cbdabd40] OpenSSL::Cipher::CipherError:
DEBUG [cbdabd40] /home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:201:in `final'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:201:in `_decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:79:in `decrypt'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_file.rb:42:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:21:in `read'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:33:in `config'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/encrypted_configuration.rb:38:in `options'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:24:in `key_exists?'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/secret_key_finder.rb:10:in `find'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/devise-4.7.2/lib/devise/rails.rb:37:in `block in <class:Engine>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `instance_exec'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:32:in `run'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/initializable.rb:60:in `run_initializers'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:361:in `initialize!'
/home/dev/apps/livelyteams/releases/20200918213106/config/environment.rb:5:in `<main>'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:337:in `require_environment!'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/railties-5.2.4.4/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/home/dev/apps/livelyteams/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
/home/dev/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
DEBUG [cbdabd40] Tasks: TOP => environment
DEBUG [cbdabd40] (See full trace by running task with --trace)
Rails is complaining about your config/master.key file. First (back them up, just in case) rm config/credentials.yml.enc and rm config/master.key then try running bundle exec rails credentials:edit.
My solution ended up being to destroy the current production server and create and new one. Now my project deploys via capistrano like it should.
I am deploying my rails app using Capistrano 3, and get this error from the Puma gem:
bundler: failed to load command: puma (/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/bin/puma)
Errno::ENOENT: No such file or directory - connect(2) for home/ubuntu/GlucoMeDDC/shared/tmp/sockets/puma.sock
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:367:in `initialize'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:367:in `new'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:367:in `add_unix_listener'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:141:in `block in parse'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:88:in `each'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/binder.rb:88:in `parse'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/runner.rb:144:in `load_and_bind'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/cluster.rb:397:in `run'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/launcher.rb:183:in `run'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/lib/puma/cli.rb:77:in `run'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/gems/puma-3.11.0/bin/puma:10:in `<top (required)>'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/bin/puma:22:in `load'
/home/ubuntu/GlucoMeDDC/shared/bundle/ruby/2.4.0/bin/puma:22:in `<top (required)>'
puma stderr: Nothing written
I was looking here for an answer but none of it was helpful for me.
For example, if I do puma:config it will work, but using the DEFAULT Puma configurations, and not taken from my puma.rb file, even that I added conf pointing to it.
Here is my deploy.rb:
lock '3.10.1'
set :application, 'GlucoMeDDC'
set :repo_url, 'git#github.com:user/GlucoMeDDC.git' # Edit this to match your repository
set :branch, ENV['BRANCH'] if ENV['BRANCH']
set :user, 'ubuntu'
set :deploy_to, '/home/ubuntu/GlucoMeDDC'
set :pty, true
set :linked_files, %w{config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
append :rvm_map_bins, 'puma', 'pumactl'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.4.1' # Edit this if you are using MRI Ruby
# set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind
set :puma_conf, "#{current_path}/config/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_access.log"
set :puma_error_log, "#{shared_path}/log/puma_error.log"
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke! 'puma:restart'
end
end
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
Any tips what else can I do?
I'm pretty sure I've encountered this before and it was a result of missing folders / bad permissions in the path raised in the error. I.E. the tmp and / or sockets folders missing or inaccessable from:
... home/ubuntu/GlucoMeDDC/shared/tmp/sockets/puma.sock ...
Double check these are being created as expected. It looks as if they should be, although where's shared_path defined - is this definitely correct?
Otherwise check permissions on folders and the file to ensure they're correct. You can run ls -la to check this, and adjust them as appropriate.
Hope there's something in there that helps - keen to hear your feedback.
That issue may caused by wrong puma_bind. It should be:
set :puma_bind, "unix:///#{shared_path}/tmp/sockets/puma.sock"
As far as I tried, there is no way to configure puma in both puma.rb and deploy.rb.
So I just did all configurations in deploy.rb and it works well. Thank you all for the answers and comments.
I am deploying for the first time to a Digital Ocean Ubuntu droplet. I have configured everything and followed all the steps and am now on the step where I issue the command: cap production deploy:initial. For this command I am getting back this error message:
cap aborted!
Don't know how to build task 'deploy:new_release_path' (see --tasks)
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:58:in `[]'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:361:in `[]'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/dsl/task_enhancements.rb:12:in `after'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/scm/git.rb:21:in `register_hooks'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/configuration/plugin_installer.rb:28:in `install'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/configuration.rb:155:in `install_plugin'
/Users/Christopher/ClientProjects/PawBookings/Capfile:3:in `<top (required)>'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:687:in `raw_load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:96:in `block in load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:95:in `load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:79:in `block in run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/application.rb:14:in `run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/bin/cap:3:in `<top (required)>'
/Users/Christopher/.rbenv/versions/2.3.1/bin/cap:22:in `load'
/Users/Christopher/.rbenv/versions/2.3.1/bin/cap:22:in `<main>'
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
config/deploy.rb
# Change these
server '12.34.56.789', port: 80, roles: [:web, :app, :db], primary: true
set :repo_url, 'my_ssh_github_url'
set :application, 'app_name'
set :user, 'deploy_username'
set :puma_threads, [4, 16]
set :puma_workers, 0
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
# set :log_level, :debug
# set :keep_releases, 5
## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
config/nginx.conf
upstream puma {
server unix:///home/deploy_username/apps/app_name/shared/tmp/sockets/app_name-puma.sock;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/deploy_username/apps/app_name/current/public;
access_log /home/deploy_username/apps/app_name/current/log/nginx.access.log;
error_log /home/deploy_username/apps/app_name/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri #puma;
location #puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
Update:
I moved a couple lines of code in the Capfile. The process seems to have started but now gives the following error message:
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env
** Invoke rvm:hook (first_time)
** Execute rvm:hook
cap aborted!
Net::SSH::Disconnect: connection closed by remote host
New Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
The Git plugin relies on the deploy tasks being present. In your Capfile, you must install the Git plugin after requiring capistrano/deploy, like this:
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
its mainly due to the ruby,rails and ubuntu updated version issues. I got the same problem.
Added in Capfile the below line before the last line and that solved my issue.
install_plugin Capistrano::Puma::Daemon
For reference follow the below tutorial. Would be helpful for someone. Because I spent lot of time to find a solution for this. https://matthewhoelter.com/2020/11/10/deploying-ruby-on-rails-for-ubuntu-2004.html
I've been trying to upgrade from Capistrano 2 to Capistrano 3, but have been working through all the errors. I'm stuck on one that I don't know how to solve now. I'm using Unicorn and Nginx.
Error trace:
cap production deploy:cold --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Task Argument Error
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:96:in `resolve_args_with_dependencies'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:62:in `resolve_args'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:24:in `define_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:360:in `define_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/dsl_definition.rb:32:in `task'
config/deploy.rb:31:in `block (2 levels) in <top (required)>'
config/deploy.rb:29:in `each'
config/deploy.rb:29:in `block in <top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task_manager.rb:196:in `in_namespace'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/dsl_definition.rb:104:in `namespace'
config/deploy.rb:28:in `<top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:12:in `load'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/setup.rb:12:in `block (2 levels) in <top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/lib/capistrano/application.rb:12:in `run'
/Users/devanb/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/capistrano-3.0.1/bin/cap:3:in `<top (required)>'
/Users/devanb/.rbenv/versions/2.0.0-p247/bin/cap:23:in `load'
/Users/devanb/.rbenv/versions/2.0.0-p247/bin/cap:23:in `<main>'
Tasks: TOP => production
Deploy file:
set :application, 'liveinbham'
set :user, 'deployer'
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :scm, "git"
set :repo_url, 'git#github.com:DevanB/LIveInBham.git'
set :use_sudo, false
set :scm_verbose, true
set :git_shallow_clone, 1
set :git_enable_submodules, 1
set :ssh_options, { :forward_agent => true }
set :stage, :production
set :rails_env, "production"
set :branch, "master"
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 public/uploads}
set :keep_releases, 5
namespace :deploy do
%w{start stop restart}.each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{fetch(:application)}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{fetch(:application)}"
end
after "deploy:setup", "deploy:setup_config"
after :finishing, 'deploy:cleanup'
end
desc "tail log files"
task :tail, :roles => :app do
run "tail -f /home/#{fetch(:user)}/apps/#{fetch(:application)}/current/log/production.log" do |channel, stream, data|
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{fetch(:user)} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{fetch(:rails_env)}'"
end
Could be a few things but deploy:cold is depreciated in Capistrano 3, I've just tried it and I just get "don't know how to build task" which is what I'd expect. Potentially running deploy:setup_config and then just a straight up deploy may work.
There's a few other things which will need tweaking like you can no longer use that approach for streaming log files, it's just a simple execute instead. E.g.:
namespace :logs do
desc "tail rails logs"
task :tail_rails do
on roles(:app) do
execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log"
end
end
end
In general the task definition format also needs updating, e.g:
task :setup_config, roles: :app do
# some stuff
end
would become
task :setup_config do
on roles(:app) do
#some stuff
end
end
It looks like your Cap 2 configuration is based quite heavily on the Railscast about it. Mine also was and I recently went through the process of migrating all the apps using it to a new Cap 3 one. I've documented the approach I ended up with here including the code.
The stack trace makes it pretty clear. The error comes from line 31 of your file, where you try to define a task using the old Capistrano 2 syntax. The new Capistrano 3 uses Rake, so you must use Rake syntax to define tasks, with the aid of some Capistrano methods. Rake does not recognize "roles" and "except". TalkingQuickly gave a good-looking example of the new way to define tasks.