【发布时间】:2016-08-19 02:25:36
【问题描述】:
在使用 Capistrano 部署新代码时,我有时会遇到 Sidekiq 问题。
这是我的设置 (deploy/production.rb):
set :rails_env, "production"
set :stage, :production
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require "whenever/capistrano"
set :user, 'deployer'
set :use_sudo, false
before "deploy", "deploy:setup"
after "deploy:restart", "deploy:cleanup"
server "IP", :web, :app, :db, primary: true
set :deploy_to, "/home/deployer/apps/myapp-production/"
set :ssh_options, { :forward_agent => true }
set :keep_releases, 3
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_myapp-production #{command}"
end
end
task :setup_config, roles: [:app] do
sudo "ln -nfs #{current_path}/config/nginx_production.conf /etc/nginx/sites-enabled/default"
sudo "ln -nfs #{current_path}/config/unicorn_init_production.sh /etc/init.d/unicorn_myapp-production"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: [:app] do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
after "deploy:create_symlink", "deploy:restart"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: [:web] 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
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
begin
from = source.next_revision(current_revision) # <-- Fail here at first-time deploy because of current/REVISION absence
rescue
err_no = true
end
if err_no || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
before "deploy", "deploy:check_revision"
end
有时会发生的情况是我部署了一些代码,一次 Sidekiq 正在运行,另一次却没有。我想说这个比例是 1/5 的情况下 Sidekiq 在部署新代码后没有运行(没有重新启动)。
如何确保 Sidekiq 在每次部署后始终运行(正确重启)?
谢谢
编辑:
deploy.rb:
require "capistrano/ext/multistage"
require "rvm/capistrano"
require 'bundler/capistrano'
require 'delayed/recipes' # added for running deplayed jobs
require 'capistrano/sidekiq'
set :application, 'myapp'
set :bundle_flags, "--quiet --no-cache"
# Default value for :scm is :git
set :scm, :git
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :repository, 'git@bitbucket.org:username/myapp.git'
set :branch, "master"
set :normalize_asset_timestamps, false
set :pty, true
EDIT2:
另外,我不确定这是否相关,但有时当我更改/config 文件夹中的某些内容时,我需要登录(Ubuntu)服务器,杀死独角兽进程并手动启动服务器以查看更改。
【问题讨论】:
-
我在 capistrano 配置中没有看到 sidekiq 部署代码。你如何部署你的 sidekiq?
-
抱歉,忘记添加这部分了。我添加了
deploy.rb部分。 -
@user984621 你在 sidekiq 日志中有任何错误吗?
-
@Sebin 没有错误,只是没有运行;如果我发送一个使用 Sidekiq 的请求,那么这个请求会存储在 Redis 中,一旦 Sidekiq 运行,这个请求就会从 Redis 中提取并处理。
标签: ruby-on-rails ubuntu amazon-ec2 capistrano sidekiq