I am splitting my redis and resque workers out to a new machine. Previously they all ran on one machine - successfully.
I us cap for deploying and after a successful deploy I get this in my rails log when I try to queue up a resque job:
==> shared/log/production.log <==
I, [2016-05-28T05:43:03.924222 #5769] INFO -- : Started GET "/photos/24803/rotate/180" for 127.0.0.1 at 2016-05-28 05:43:03 +0000
I, [2016-05-28T05:43:04.080861 #5769] INFO -- : Processing by PhotosController#rotate as HTML
I, [2016-05-28T05:43:04.081274 #5769] INFO -- : Parameters: {"id"=>"24803", "degrees"=>"180"}
D, [2016-05-28T05:43:04.183430 #5769] DEBUG -- : Photo Load (1.4ms) SELECT `photos`.* FROM `photos` WHERE `photos`.`id` = 24803 LIMIT 1
I, [2016-05-28T05:43:04.250844 #5769] INFO -- : Completed 500 Internal Server Error in 169ms (ActiveRecord: 22.1ms)
F, [2016-05-28T05:43:04.256268 #5769] FATAL -- :
Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
app/models/photo.rb:109:in `rotate'
app/controllers/photos_controller.rb:106:in `rotate'
So I'm thinking that my app server does not get that it should go to the "backend server" for this stuff.
My configuration:
I have the app server running op 192.168.2.102 - everything is installed there except for redis. Redis is installed on 192.168.2.103
config/deploy.rb:
server '192.168.2.102', port: 22, roles: [:web, :app], primary: true
server '192.168.2.103', port: 22, roles: [:db, :resque_worker, :resque_scheduler]
set :repo_url, 'xxx'
set :application, 'xxx'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :workers, { "import" => 1, "utility" => 1 }
set :resque_environment_task, true
# 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) }
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{db/production.sqlite3}
set :linked_dirs, %w{ log tmp/pids tmp/cache tmp/sockets public/system }
#set :bundle_binstubs, nil
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
after "deploy:restart", "resque:restart"
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
config/resque.yml:
development: localhost:6379
test: localhost:6379
production: 192.168.2.103:6379
config/initializers/resque.rb
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
Resque.logger = MonoLogger.new(File.open("#{Rails.root}/log/resque.log", "w+"))
Resque.logger.formatter = Resque::QuietFormatter.new
config/initializers/redis.rb:
$redis = Redis.new(:host => ENV["REDIS_HOST"], :port => ENV["REDIS_PORT"])
I'not sure whether I need the last file...
If you're thinking that it's my connectio setup that's wrong then think no more (about that..). Firstly Resque is not even trying to connect to the right redis. secondly, when I do this:
...on 192.168.2.103:
deploy#raspberrypi:~/apps/phototank $ netstat -nlpt | grep 6379
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN -
tcp6 0 0 :::6379 :::* LISTEN -
...on 192.168.2.102:
deploy#raspberrypi:~/apps/phototank $ redis-cli -h 192.168.2.103 ping
PONG
____EDIT____
If I run
RAILS_ENV=development rails s
on my development machine everything works perfect...what the hell?!??
Problem located:
config/initializers/resque.rb
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
Resque.logger = MonoLogger.new(File.open("#{Rails.root}/log/resque.log", "w+"))
Resque.logger.formatter = Resque::QuietFormatter.new
The second line sets the env to development if nothing else is defined...the env gets set in the line after that...
I simply removed the first two lines
Related
I have a rails application that is not rendering assets. It was previously working fine. When I added linked files it not only uploaded the files I specified but also precompiled assets. Even after clobbering all assets and recompiling it fails to render them even though that exist on the box.
error
Caddyfile
mydomain.com {
gzip
log stdout
root /home/deploy/apps/rails-app/current/public
proxy / unix:///home/deploy/apps/rails-app/shared/tmp/sockets/rails-app-puma.sock {
except /assets # this is /public/assets directory
except /solr
transparent
websocket
policy round_robin
}
errors stdout
header / {
Strict-Transport-Security "max-age=31536000"
}
proxy /solr localhost:8983 {
transparent
}
}
deploy.rb
# frozen_string_literal: true
# config valid only for current version of Capistrano
# lock '3.13.0'
# Change these
server '...', port: 2221, roles: %i[web app db], primary: true
set :repo_url, '...'
set :application, '...'
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], auth_methods: %w(publickey) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
set :bundle_flags, '--no-cache'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.6.6'
set :rails_env, 'production'
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
## Defaults:
set :branch, 'master'
set :log_level, :debug
set :keep_releases, 5
## Linked Files & Directories (Default None):
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :linked_dirs, %w{data_files}
set :linked_dirs, fetch(:linked_dirs, []).push('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
I was able to get this working but using the fileserver directive.
https://example.com {
encode zstd gzip
root * /home/deploy/apps/rails-app/current/public
file_server
tls user#email.com
#notStatic {
not file
}
reverse_proxy #notStatic unix//home/deploy/apps/rails-app/shared/tmp/sockets/rails-app-puma.sock
header / {
Strict-Transport-Security "max-age=31536000"
}
}
I have been following this tutorial: https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
But I get this error:
root#demo:~/app # cap demo deploy:initial
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after require "capistrano/deploy":
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host x.x.x.x: Connection refused - connect(2) for "x.x.x.x." port 5000
Errno::ECONNREFUSED: Connection refused - connect(2) for "x.x.x.x" port 5000
I have been researching for a few hours and have no idea how to fix this as I cannot find a formulated answer.
Heres the deploy.rb
server 'x.x.x.x', port: 5000, roles: [:web, :app, :db], primary: true
set :repo_url, 'git#github.com:company/app.git'
set :application, 'app'
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, true
set :stage, :demo
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/app.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, :develop
# 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/develop`
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
I am trying to deploy my rails app with Capistrano. While deploying it asks for the passphrase for key '/home/gokul/.ssh/id_rsa' but, I can't able to type the passphrase the characters are visible and not authenticating.
deploy.rb
# Server
server 'xxx.xxx.xxx.xxx', roles: [:web, :app, :db], primary: true
# Repository
set :repo_url, 'git#bitbucket.org:gokul/testapp.git'
set :scm_passphrase, ''
set :application, 'testapp'
set :user, 'gokul'
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)}/APP/#{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), auth_methods: ['publickey'], keys: %w(~/.ssh/privatekey.pem) }
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}
set :linked_dirs, %w(tmp/pids)
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
Deployment Log:
It is asking for the passphrase but while entering the passphrase it is visible and not authenticating.
gokul$ cap production deploy
rvm 1.29.1 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]
ruby-2.3.1
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
00:00 git:wrapper
01 mkdir -p /tmp
✔ 01 gokul#xxx.xxx.xxx.xxx 0.708s
Uploading /tmp/git-ssh-testapp-gokul.sh 100.0%
02 chmod 700 /tmp/git-ssh-testapp-gokul.sh
✔ 02 gokul#xxx.xxx.xxx.xxx 0.706s
00:03 git:check
01 git ls-remote git#bitbucket.org:gokul/testapp.git HEAD
01 Enter passphrase for key '/home/gokul/.ssh/id_rsa':
password
a
sde
we
ere
re
e
e
e
^C(Backtrace restricted to imported tasks)
cap aborted!
Interrupt:
Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error:
I tried setting pty as false as answered in https://stackoverflow.com/a/23227003/4172728. But this doesn't work for me.
Can anyone help me please.
Thank you.
I solved this issue by adding my local machine public key from ~/.ssh/id_rsa.pub to the list of access keys in the bitbucket repository settings.
And then, added the id_rsa to the ssh-agent as below:
gokul$ ssh-add ~/.ssh/id_rsa
Ref: https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
I have a simple rails app that I am trying to deploy to a production server using Capistrano, but it appears to fail when trying to create the puma.pid.
When I check the the puma.access.log I see the following,
/home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock (URI::InvalidURIError)
from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:85:in `block in parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `each'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `parse'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/runner.rb:119:in `load_and_bind'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/single.rb:79:in `run'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/cli.rb:215:in `run'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/bin/puma:10:in `<top (required)>'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `load'
from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `<main>'
Does anybody know why puma would display this error? I can post more configuration files if need be too.
The console output when running the deploy command,
INFO [5680e746] Finished in 2.087 seconds with exit status 0 (successful).
DEBUG [d53f0457] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi on youtee.io
DEBUG [d53f0457] Command: if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi
DEBUG [d53f0457] Finished in 0.296 seconds with exit status 0 (successful).
DEBUG [54524c04] Running /usr/bin/env [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ] on youtee.io
DEBUG [54524c04] Command: [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ]
DEBUG [54524c04] Finished in 0.310 seconds with exit status 1 (failed).
DEBUG [287a3b10] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi on youtee.io
DEBUG [287a3b10] Command: if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi
DEBUG [287a3b10] Finished in 0.217 seconds with exit status 0 (successful).
INFO [5a813829] Running /usr/bin/env echo "Branch master (at 538f125)
deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log on youtee.io
DEBUG [5a813829] Command: echo "Branch master (at 538f125) deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log
INFO [5a813829] Finished in 0.248 seconds with exit status 0 (successful).
production.rb
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
server 'youtee.io', port: 4321, roles: [:web, :app, :db], primary: true
set :rvm_ruby_string, '2.2.1'
set :repo_url, 'git#bitbucket.org:ipatch/tshirt.git'
set :application, 'Tshirt'
set :user, 'capin'
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)}"
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml config/secrets.yml}
# see this SO answer, http://stackoverflow.com/a/32011351/708807
# set :linked_dirs, fetch(:linked_dirs, []).push('public/uploads')
set :puma_bind, "tcp://0.0.0.0:9294"
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
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
# preserve uploaded files through Capistrano deployments
# ln -n = ln -h, which if target dir is a sym link don't follow
# ln -f, if already linked unlink so new link can be created
# ln -s, creates a symlink
# execute :ln, "-nfs #{shared_path}/public/uploads/store #{release_path}/public/uploads/store"
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
# role-based syntax
# ==================
# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.
# role :app, %w{deploy#example.com}, my_property: :my_value
# role :web, %w{user1#primary.com user2#additional.com}, other_property: :other_value
# role :db, %w{deploy#example.com}
# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.
# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
set :ssh_options, {
keys: %w(/Users/capin/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey password)
# port: 4321,
}
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
shared/puma.rb
#!/usr/bin/env puma
directory '/home/capin/apps/Tshirt/current'
rackup "/home/capin/apps/Tshirt/current/config.ru"
environment 'production'
pidfile "/home/capin/apps/Tshirt/shared/tmp/pids/puma.pid"
state_path "/home/capin/apps/Tshirt/shared/tmp/pids/puma.state"
stdout_redirect '/home/capin/apps/Tshirt/current/log/puma.error.log', '/home/capin/apps/Tshirt/current/log/puma.access.log', true
threads 4,16
bind 'unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock'
workers 0
preload_app!
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = "/home/capin/apps/Tshirt/current/Gemfile"
end
on_worker_boot do
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.establish_connection
end
end
Looks like mistake in your puma/capistrano configuration file. I think you put the line unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock into single quotas instead of double and string interpolation is not working :)
UPDATE:
check your puma_bind value, should be
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
in double quotas
I am using figaro gem to store my environment variables in both deployment and production environments.
However on each deploy the production application.yml file gets deleted (which I create manually, because my development application.yml is listed in gitignore). Am I missing some basic git/capistrano stuff?
I'm not using Heroku, hence this is my approach:
Other Hosts
If you're not deploying to Heroku, you have two options:
Generate a remote configuration file
My deploy.rb:
# Change these
server 'xx.xxx.xxx.xx', port: 4012, roles: [:web, :app, :db], primary: true
set :repo_url, 'git-repo'
set :application, 'mosflash'
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}
set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}
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
This line is included in my .gitignore:
# Ignore application configuration
/config/application.yml
Right now I'm recreating application.yml after each deploy, but this is quite tiresome.