I am running sidekiq in production and I deploy my app using capistrano. While processing background job, I am getting following error
I18n::InvalidLocaleData: can not load translations from /path/to/folder/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/folder/releases/20160904153949/config/locales/en.yml>.
release 20160904153949 is old and has been deleted. I am wondering why sidekiq is still looking into older release.
Below is how my deploy.rb file looks like:
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'app_name'
set :repo_url, 'git#github.com:reboot/app_name.git'
# Default branch is :master
set :branch, 'master'
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/path/to/app'
set :use_sudo, false
set :bundle_binstubs, nil
# 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', 'public/assets')
# 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
set :keep_assets, 3
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
end
end
end
Below is how my Capfile looks like
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/sidekiq'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
sidekiq stop/start is handled by capistrano/sidekiq gem. My app gets deployed fine. Problem is that sidekiq is looking into wrong release for required file.
Also I don't have sidekiq.yml file at this stage. My app is small so never created yml file for it.
Ruby: 2.3.0p0,
Rails: 4.2.5,
nginx/passenger combination,
Capistrano 3.4
Upadate
Below is full error message:
2016-09-07T19:33:22.349Z 3262 TID-md1a4 ContactUsEmailJob JID-fb18ad450d73ed857fe66aee INFO: fail: 0.069 sec
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: {"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ContactUsEmailJob","queue":"default","args":[{"job_class":"ContactUsEmailJob","job_id":"e30dfe20-89b2-49a9-833c-8e479bdb8a2d","queue_name":"default","arguments":[{"utf8":"✓","authenticity_token":"i+OuDyC2c243UvC0FRWk1esASnUhQ2jKbfvZnoX2GZLela+mPCcOU6qtpU3OZhxr0wTCYUpmFXD6623Q==","name":"Test","message":"test","controller":"static_pages","action":"email_us","_aj_hash_with_indifferent_access":true}],"locale":"en"}],"retry":true,"jid":"fb18ad450d73ed857fe66aee","created_at":1473276802.277088,"enqueued_at":1473276802.2773373,"error_message":"can not load translations from /path/to/app/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/app/releases/20160904153949/config/locales/en.yml>","error_class":"I18n::InvalidLocaleData","failed_at":1473276802.3480363,"retry_count":0}
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: I18n::InvalidLocaleData: can not load translations from /path/to/app/releases/20160904153949/config/locales/en.yml: #<Errno::ENOENT: No such file or directory # rb_sysopen - /path/to/app/releases/20160904153949/config/locales/en.yml>
2016-09-07T19:33:22.350Z 3262 TID-md1a4 WARN: /path/to/app/shared/bundle/ruby/2.3.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:184:in `rescue in load_yml'
Ok so I solved the problem by following these steps:
kill process of sidekiq pkill sidekiq
deleted sidekiq pid file from /path/to/app/current/tmp/pid/
started sidekiq using cap sidekiq:start, this will create pid file
finally deploy my app ( this process will restart sidekiq again)
Everything worked find after that.
Related
I have an existing Rails application that is set up to use Capistrano for deployments. I'm adding a Staging environment to it, but running bundle exec cap staging deploy returns an error:
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy#[IP Redacted]: cat /var/www/staging-app-name/current/REVISION exit status: 1
cat /var/www/staging-app-name/current/REVISION stdout: Nothing written
cat /var/www/staging-app-name/current/REVISION stderr: cat: /var/www/staging-app-name/current/REVISION: No such file or directory
Versions:
Rails - 4.2.11
Ruby - 2.3.1
Capistrano - 3.15.0
Deploy.rb:
set :stages, %w(production staging)
set :application, "application-name"
set :repo_url, "[Redacted]"
set :conditionally_migrate, !ENV['FIRST_RUN']
set :migration_role, :app
set :default_stage, "production"
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
set :linked_dirs, fetch(:linked_dirs, []).push(
'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'vendor/bundle',
'public/system',
'public/uploads',
'public/assets'
)
set :default_env, { path: "/opt/ruby_build/builds/2.3.1/bin:$PATH" }
deploy/staging.rb:
server '[IP redacted]', user: 'deploy', roles: %w{app db web}
set :branch, 'develop'
set :deploy_to, '/var/www/staging-app-name'
set :stage, 'staging'
set :rails_env, 'staging'
deploy/production.rb
server '[IP redacted]', user: 'deploy', roles: %w{app db web}
set :branch, 'master'
set :deploy_to, '/var/www/production-app-name'
set :stage, 'production'
set :rails_env, 'production'
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require "capistrano/bundler"
require "capistrano/rails/migrations"
require "capistrano/conditional"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
This would be the first Staging deployment, so the staging-app-name directory is empty.
It's worth noting that Production deployments are working.
I've confirmed the directory/file permissions on the server are fine.
Any help would be appreciated!
I have 2 different remote servers for my Rails application.To deploy im using capistrano. First - staging, second production. To run puma server each server uses their own comand, so on local machine im using next:
STAGING:
run("bundle exec puma -C /var/www/snapship/shared/config/puma.rb --daemon")
PROD:
sudo :systemctl, "start puma.target"
When I deploy my application i write: cap staging deploy or cap production deploy. How can I let the Rails app know which puma start it should use? Because I cant check Rails.env on local machine (it always development)
UPDATE:: (Capfile)
require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/rbenv"
require "capistrano/bundler"
require "capistrano/puma"
require "capistrano/puma/nginx"
require "capistrano/puma/jungle"
require "sshkit/sudo"
require "whenever/capistrano"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
Deploy.rb
lock '3.5.0'
set :application, 'snapship'
set :pty, true
set :repo_url, 'git#gitlab.com:snapship/snapship-backend.git'
set :user, ENV['USER'] || 'deploy'
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/puma.rb', '.env', '.rbenv-vars')
set :linked_dirs, %w(tmp/pids tmp/sockets log public/uploads)
# rbenv plugin setup
set :rbenv_type, :user
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 :rbenv_map_bins, fetch(:rbenv_map_bins, []).push('foreman')
# bundle plugin setup
set :bundle_bins, fetch(:bundle_bins, []).push('foreman')
# puma plugin setup
set :puma_preload_app, true
set :puma_init_active_record, true
set :puma_conf, "#{shared_path}/config/puma.rb"
before :deploy, "deploy:run_tests"
after "deploy:publishing", "foreman:export"
after "deploy:publishing", "systemd:update"
after "deploy:publishing", "systemd:enable"
set :migration_servers, -> { release_roles(fetch(:migration_role)) }
Also 2 files staging and production for each deploy.
What worked for me:
# in deploy.rb
# define stages
set :stages, %w(staging production)
# then get the current stage
set :my_var_env, Proc.new { fetch :stage }
then run cap staging deploy
I also use the gem 'capistrano3-puma' which gives me tasks like
cap staging|production puma:[start|stop|restart|status]
I'm using capistrano for deploy my rails application, but I got the following error:
Skipping task `sidekiq:restart'.
Capistrano tasks may only be invoked once. Since task `sidekiq:restart' was previously invoked, invoke("sidekiq:restart") at config/deploy.rb:49 will be skipped.
If you really meant to run this task again, first call Rake::Task["sidekiq:restart"].reenable
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686
Besides that, I think the command is not working even on the first time, since sidekiq is not running. I could start it manually, but I believe even if not running, it should start anyway, right?
My deploy/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:
set :stage, :production
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
# Using remote cache to deploy
set :deploy_via, :remote_cache
server '35.160.22.104', user: 'ubuntu', roles: %w{app db web}
# 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.
set :rails_env, :production
set :pty, true
# number of unicorn workers
# set :unicorn_worker_count, 5
# 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
#
set :ssh_options, {
keys: %w(/home/ronanlopes/Pems/hybrazil-impulso.pem ~/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey)
}
# Sidekiq
set :sidekiq_config, File.join(current_path, 'config', 'sidekiq.yml')
set :sidekiq_log, File.join(shared_path, 'log', 'sidekiq.log')
set :sidekiq_pid, File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid')
My deploy.rb:
# config valid only for current version of Capistrano
lock '3.7.0'
set :application, 'hybrazil'
set :repo_url, 'git#github.com:fneto/hybrazil.git'
set :user, 'ubuntu'
# Need this so capistrano creates the directories as "ubuntu" user
set :use_sudo, false
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/hybrazil'
set :passenger_restart_with_touch, true
set :rvm_type, :user
set :rvm_ruby_version, '2.3.1'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
namespace :deploy do
desc 'Restart application'
task :restart do
invoke 'sidekiq:restart'
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
end
Any help would be appreciated. Thanks!
For me, setting pty to false worked. Still don't know why, but if someone does, would appreciate a explanation on comments. Thanks!
I'm having issues with running ruby gem commands while using Capistrano 3 with capistrano-rbenv (I'm assuming it can't find the ruby interpreter), specifically delayed_job. I've posted the necessary files associated with the issue:
`require': no such file to load -- rubygems (LoadError)
Any assistance would be greatly appreciated.
Gemfile
gem 'capistrano', "~> 3.6"
gem 'capistrano-rbenv', '~> 2.0'
Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require "capistrano/rbenv"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
deploy.rb
# config valid only for current version of Capistrano
lock '3.6.1'
set :application, 'youtube_rank_tracker'
set :repo_url, './.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/dogecoin'
# Default value for :scm is :git
set :scm, :git
# Default value for :format is :airbrussh.
set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'
# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
# Default value for default_env is {}
# set :default_env, { path: '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH' }
# Default value for keep_releases is 5
set :keep_releases, 5
# set :default_env, { path: "$HOME/.rbenv/bin:$PATH" }
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all) do |host|
execute :mkdir, "-p #{release_path}/tmp"
execute :touch, release_path.join('tmp/restart.txt')
execute "cd #{release_path} && RAILS_ENV=production bin/delayed_job restart;"
# execute "cd #{release_path} && bundle exec rake -T"
end
end
end
after 'deploy:publishing', 'deploy:restart'
Error
he deploy has failed with an error: Exception while executing as root#.....: cd /.... && RAILS_ENV=production bin/delayed_job restart; exit status: 1
cd /.... && RAILS_ENV=production bin/delayed_job restart; stdout: /usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
from /usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:2
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:1:in `require'
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:1
Short answer
Instead of writing it yourself, use the semi-official Capistrano 3 Delayed Job integration Gem: https://github.com/AgileConsultingLLC/capistrano3-delayed-job
Long answer
If you were to actually write this yourself, capistrano-rbenv only affects a small default list of commands, as seen here: https://github.com/capistrano/rbenv/blob/master/lib/capistrano/tasks/rbenv.rake#L47
In this case, you'd probably want something like the following:
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:all) do |host|
within release_path do
execute :ruby, "bin/delayed_job", 'restart'
end
end
end
end
Instead of creating the tmp/ directory, add it to :linked_dirs in your config.
Also, it looks like you are touching tmp/restart.txt to restart Passenger. Alternatively, use the capistrano-passenger gem to do that. It can run in a newer mode which uses the passenger commands to restart your app, or you can tell it to use the touch file mechanism.
Finally, instead of using cd ${release_path}, use the within DSL method. That will accomplish the same thing and not break the command map.
I am using capistrano for deployment, and for some reason my shared/bin folder is empty, and, well it should contain -rails, rake, bundle, setup, spring. now obviously I did something wrong, but as I am new to capistrano, I have no Idea what it is, because it is in my git repository, and as far as I know it copies the entire thing from the repository. since I am not sure wether it is relavent or not, I will just put everything I changed reguarding the capistrano deployment.
here's my deploy.rb
lock '3.4.0'
# application settings
set :application, 'SomeApplication'
set :user, 'someuser'
#set :repo_url, 'git#bitbucket.org:someapp/someappserver.git'
set :rails_env, 'production'
set :use_sudo, false
set :keep_releases, 5
#git settings
set :scm, :git
set :branch, "master"
set :repo_url, "git#bitbucket.org:someapplication/someapplicationserver.git"
set :deploy_via, :remote_cache
set :rvm_ruby_version, '2.2.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"
# dirs we want symlinked to the shared folder
# during deployment
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :pg_database, "someapp_production"
set :pg_user, "someapp_production"
set :pg_ask_for_password, true
namespace :deploy do
task :config_nginx do
pre = File.basename(previous_release)
cur = File.basename(release_path)
run "#{sudo} sed 's/#{pre}/#{cur}/g' /etc/nginx/sites-available/default"
end
task :restart_thin_server do
run "cd #{previous_release}; source $HOME/.bash_profile && thin stop -C thin_config.yml"
run "cd #{release_path}; source $HOME/.bash_profile && thin start -C thin_config.yml"
end
task :restart_nginx do
run "#{sudo} service nginx restart"
end
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')
#
# The capistrano-unicorn-nginx gem handles all this
# for this example
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
here is my deploy/production.rb
# production deployment
set :stage, :production
# use the master branch of the repository
set :branch, "master"
# the user login on the remote server
# used to connect and deploy
set :deploy_user, "someuser"
# the 'full name' of the application
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
# the server(s) to deploy to
server 'someserver.cloudapp.net', user: 'someuser', roles: %w{web app db}, primary: true
# the path to deploy to
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
# set to production for Rails
set :rails_env, :production
and here is my cap file
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# 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/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/passenger'
require 'capistrano/thin'
require 'capistrano/postgresql'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
like #emj365 said
just remove bin form your linked_dirs in config/deploy.rb
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
#gilmishal Kindly check with this link .. capistrano-deploy-configuration
And keep your eye on directory path where i did mistake many a times
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name' # This conf is by default
Hope it will solve your problem