Capistrano 3 + rbenv + sidekiq:找不到命令

问题描述 投票:1回答:1

我正在升级到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, '[email protected]:/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
  • 我不确定capistrano rbenv gem是否真的使用ruby 2.3.1版本进行部署。我很确定这与它有关。但我不知道该如何调试
  • 使用capistrano 2来启动sidekiq的原始命令是set :sidekiq_cmd, defer { "bundle exec sidekiq -c5 -r ./lib/load_feeds/sidekiq_runner.rb -q high -q low" }
  • 我正在部署sinatra应用,它使用ENV["RACK_ENV"]作为配置文件。因此,rails env和机架环境之间的混合]
ruby capistrano sidekiq rbenv capistrano3
1个回答
0
投票

如果有人仍然需要答案->这是因为服务器上安装了多个ruby版本。下面的消息表示尚有使用1.9.3-p429 ruby​​版本的sidekiq进程仍在运行。

01 The `sidekiq' command exists in these Ruby versions:
01   1.9.3-p429

[当您想使用其他版本进行部署时,请不要忘记先使用以下命令停止当前的sidekiq进程:

cap production sidekiq:stop

如果要使用Ruby版本1.9.3-p429而不是2.3.1,则将VirtualHost配置更改为

PassengerRuby /home/deploy/.rbenv/versions/1.9.3-p429/bin/ruby

并更改您的全球红宝石版本

rbenv global 1.9.3-p429
rbenv rehash

并且不要忘记在重新部署之前在deploy.rb处更改红宝石版本设置:

set :rbenv_ruby, '1.9.3-p429'

就我而言,我有两个红宝石版本:2.3.7和2.6.5。在sidekiq进程仍在运行时,全局版本已更改为2.6.5(在全局版本仍在使用2.3.7的情况下,该进程已启动)。

© www.soinside.com 2019 - 2024. All rights reserved.