gpt4 book ai didi

ruby-on-rails - rails +Capistrano : Sidekiq doesn't always start when new code is deployed

转载 作者:太空宇宙 更新时间:2023-11-03 17:10:54 24 4
gpt4 key购买 nike

在使用 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

编辑 2:另外,我不确定这是否相关,但有时当我在 /config 文件夹中更改某些内容时,我需要登录到(Ubuntu)服务器,杀死 unicorn 进程并手动启动服务器以查看更改。

最佳答案

这是 Capistrano 3 的一个已知问题,将 pty 设置为 false 应该可以解决问题。

There is a known bug that prevents sidekiq from starting when pty is true on Capistrano 3.

set :pty, false

https://github.com/seuros/capistrano-sidekiq#known-issues-with-capistrano-3

相关问题: https://github.com/seuros/capistrano-sidekiq/issues/23

关于ruby-on-rails - rails +Capistrano : Sidekiq doesn't always start when new code is deployed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36844927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com