我正在升级到Capistrano 3,在部署期间,sidekiq应该启动。但我收到以下错误:
00:23 sidekiq:start
01 $HOME/.rbenv/bin/rbenv exec sidekiq --index 0 --pidfile /var/www/my_app/shared/tmp/pids/sidekiq-0.pid --environment staging --logfile …
01 rbenv: sidekiq: command not found
01
01 The `sidekiq' command exists in these Ruby versions:
01 1.9.3-p429
01
我没有为此项目使用系统ruby或rbenv默认ruby版本。我在我的VirtualHost
apache配置中设置了ruby版本:
PassengerRuby /home/deploy/.rbenv/versions/2.3.1/bin/ruby
和$ rbenv versions
返回
1.9.3-p429
* 2.1.2 (set by /home/deploy/.rbenv/version)
2.3.1
这是我的Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require 'capistrano/sidekiq'
require "whenever/capistrano"
require 'airbrake/capistrano/tasks'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/passenger'
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
这是我的deploy.rb
# config valid only for current version of Capistrano
lock '3.6.1'
server '123.456.789.0', user: 'my_user', roles: %w{web app db}
set :application, 'my_app'
set :repo_url, 'git@server.com:/myApp'
set :ssh_options, { forward_agent: true }
set :passenger_restart_with_touch, true
set :migration_role, :app
set :rbenv_ruby, '2.3.1'
set :rbenv_map_bins, ['rake', 'gem', 'bundle', 'ruby', 'rails', 'sidekiq', 'sidekiqctl']
set :default_env, ->{ { rack_env: fetch(:rails_env) } }
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system')
set :linked_files, fetch(:linked_files, []).push('config/config.yml')
after 'deploy:finished', 'airbrake:deploy'
set :whenever_command_environment_variables, ->{ { rack_env: fetch(:whenever_environment) } }
set :whenever_environment, ->{ fetch :rack_env, fetch(:stage, "production") }
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
set :sidekiq_env, -> { fetch(:rails_env) }
set :sidekiq_concurrency, 5
set :sidekiq_require, './lib/sidekiq_runner.rb'
set :sidekiq_queue, ['high', 'low']
我的deploy/staging.rb
(还有一个production.rb):
set :rails_env, "staging"
set :deploy_to, "/var/www/my_app"
role :web, "123.456.789.0" # Your HTTP server, Apache/etc
role :app, "123.456.789.0" # This may be the same as your `Web` server
role :db, "123.456.789.0", primary: true # This is where Rails migrations will run
set :sidekiq_cmd, defer { "bundle exec sidekiq -c5 -r ./lib/load_feeds/sidekiq_runner.rb -q high -q low" }
ENV["RACK_ENV"]
配置文件。因此,rails env和rack env 答案 0 :(得分:1)
这是因为您的服务器上安装了多个ruby版本,并且它们的配置不正确。该消息表明,您当前的部署过程(在deploy.rb
上设置为v.2.3.1)无法运行sidekiq:start
,因为仍有sidekiq进程仍在使用v.1.9.3-p429运行。
01 The `sidekiq' command exists in these Ruby versions:
01 1.9.3-p429
当您要使用不同的rbenv_ruby
版本进行部署时,请不要忘记先使用先前部署的rbenv_version
停止当前的sidekiq进程,在这种情况下,该版本为v.1.9.3-p429在消息中,在deploy.rb
set :rbenv_ruby, '1.9.3-p429'
然后做
$ cap production sidekiq:stop
在v.2.3.1的情况下,最好遵循服务器apache配置的ruby版本。因此,您必须将服务器的全局红宝石版本从v.2.1.2更改为v.2.3.1:
$ rbenv global 2.3.1
$ rbenv rehash
,如果您再次检查$ rbenv version
,它将返回
1.9.3-p429
2.1.2
* 2.3.1 (set by /home/deploy/.rbenv/version)
注意:特别是如果您有多个不同的红宝石版本的VirtualHost
,则不必更改全局版本。
最重要的是:在使用不同的ruby版本重新部署之前,请不要忘记确保没有使用先前部署的ruby版本运行的sidekiq进程。此外,请确保您的rbenv_ruby
版本设置遵循VirtualHost
上的deploy.rb
红宝石版本:
set :rbenv_ruby, '2.3.1'
再次执行cap production deploy
,您将再没有rbenv: sidekiq: command not found
错误和apache错误。