0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

gem 'capistrano-sidekiq' を使って デプロイ中にcommand not found(コマンドが見つかりません)エラー

Last updated at Posted at 2023-01-13

バージョンが古いためか結構詰まってしまったので書いておきます。
gemをinstallしてCapfileにrequire 'capistrano/sidekiq'と書いただけのシンプルな設定です。

公式

capistrano: https://github.com/capistrano/capistrano
sidekiq: https://github.com/mperham/sidekiq/wiki/Deployment
capistrano-sidekiq: https://github.com/seuros/capistrano-sidekiq

解決方法

  • capistranoのバージョンが3.4.0だったため、3.9.0にアップデート(※2023年/1月現在の最新は3.17です)
  • deploy.rbにset :rbenv_map_bins, %w(rake gem bundle ruby rails sidekiq sidekiqctl)のように、sidekiqとsidekiqctlを追記

どんなエラーだったか

cap staging deployをしたところ、途中で以下のようなエラーが発生

$ cap staging deploy
略
00:00 sidekiq:stop
      01 bundle exec sidekiqctl stop /var/www/****/shared/tmp/pids/sidekiq-0.pid 10
      01 bash: bundle: コマンドが見つかりません
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as /****/@/****/: sidekiqctl exit status: 127
sidekiqctl stdout: Nothing written
sidekiqctl stderr: bash: bundle: コマンドが見つかりません


Caused by:
SSHKit::Command::Failed: sidekiqctl exit status: 127
sidekiqctl stdout: Nothing written
sidekiqctl stderr: bash: bundle: コマンドが見つかりません

Tasks: TOP => sidekiq:stop
(See full trace by running task with --trace)

もう少し詳しく

deploy.rbにset :rbenv_map_bins, %w(rake gem bundle ruby rails sidekiq sidekiqctl)のように、sidekiqとsidekiqctlを追記すると、以下のように通りました

$ cap staging deploy
略
00:33 sidekiq:stop
      01 RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=2.3.1 /usr/local/rbenv/bin/rbenv exec bundle exec sidekiqctl stop /var/www/****/shared/tmp/pids/sidekiq-0.pid 10
      01 Sidekiq shut down gracefully.
    ✔ 01 ****@**** 1.566s
00:34 deploy:symlink:release
      01 ln -s /var/www/****/releases/20230113053903 /var/www/****/releases/current
    ✔ 01 ****@**** 0.077s
      02 mv /var/www/****/releases/current /var/www/****
    ✔ 02 ****@52.198.51.57 0.083s
00:35 sidekiq:start
      01 RBENV_ROOT=/usr/local/rbenv RBENV_VERSION=2.3.1 /usr/local/rbenv/bin/rbenv exec bundle exec sidekiq --index 0 --pidfile /var/www/****/shared/tmp/pids/sidekiq-0.pid --environment staging --…
    ✔ 01 ****@**** 0.736s
略

set :rbenv_map_bins, %w(rake gem bundle ruby rails sidekiq sidekiqctl)
ここに追記すると、rbenv exec ~ として実行されるようになります。

そのため、未記入の方のログでは実行コマンドが以下のようになっていますが、

略 bundle exec sidekiqctl stop 略

追記した場合のログでは実行コマンドが以下のように変わっています。

略 /usr/local/rbenv/bin/rbenv exec bundle exec sidekiqctl stop 略
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?