本記事では、Amazon Lightsailで構築されたRedmine環境において発生する「Gem依存エラー」の原因とその解決方法について詳しく解説します。エラーメッセージの解析から始まり、必要なGemのインストール方法、正しいユーザーとRubyインタープリターの確認、ファイルとディレクトリの権限設定、依存関係の確認と解決方法についてステップバイステップで説明します。
Amazon Lightsailで構築したRedmine環境からgemが見つからないエラが発生しました。
Redmine環境
Environment:
Redmine version 4.0.5.stable
Ruby version 2.5.7-p206 (2019-10-01) [x86_64-linux]
Rails version 5.2.3
Environment production
Database adapter Mysql2
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
エラ内容
/opt/bitnami/apache2/logs/error_log
[ 2024-07-11 05:33:54.8801 2131/7f2c72f4a700 age/Cor/Con/CheckoutSession.cpp:285 ]: [Client 1-21] Cannot checkout session because a spawning error occurred. The identifier of the error is f6c74450. Please see earlier logs for details about the error.
App 3613 stdout:
App 3613 stdout:
[ 2024-07-11 05:34:04.7639 2131/7f2c76ee7700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /opt/bitnami/apps/redmine/htdocs/: An error occurred while starting up the preloader.
Error ID: 6dfcacc3
Error details saved to: /tmp/passenger-error-WBP0RE.html
Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
<pre class="commands">bundle install</pre>
<p>If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:</p>
<ol>
<li>Is this app supposed to be run as the <code>daemon</code> user?</li>
<li>Is this app being run on the correct Ruby interpreter? Below you will
see which Ruby interpreter Phusion Passenger attempted to use.</li>
</ol>
<p>-------- The exception is as follows: -------</p>
Could not find rake-13.0.0 in any of the sources (Bundler::GemNotFound)
<pre> /opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:91:in `block in materialize'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `map!'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `materialize'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:171:in `specs'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:238:in `specs_for'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:227:in `requested_specs'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:108:in `block in definition_method'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:20:in `setup'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler.rb:107:in `setup'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/setup.rb:20:in `<top (required)>'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:100:in `preload_app'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:156:in `<module:App>'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:29:in `<main>'</pre>
[ 2024-07-11 05:34:04.7680 2131/7f2c72f4a700 age/Cor/Con/CheckoutSession.cpp:285 ]: [Client 1-22] Cannot checkout session because a spawning error occurred. The identifier of the error is 6dfcacc3. Please see earlier logs for details about the error.
App 3660 stdout:
App 3660 stdout:
[ 2024-07-11 05:34:23.7108 2131/7f2c76ee7700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /opt/bitnami/apps/redmine/htdocs/: An error occurred while starting up the preloader.
Error ID: 1103a3e6
Error details saved to: /tmp/passenger-error-CZZSaj.html
Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
<pre class="commands">bundle install</pre>
<p>If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:</p>
<ol>
<li>Is this app supposed to be run as the <code>daemon</code> user?</li>
<li>Is this app being run on the correct Ruby interpreter? Below you will
see which Ruby interpreter Phusion Passenger attempted to use.</li>
</ol>
<p>-------- The exception is as follows: -------</p>
Could not find rake-13.0.0 in any of the sources (Bundler::GemNotFound)
<pre> /opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:91:in `block in materialize'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `map!'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `materialize'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:171:in `specs'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:238:in `specs_for'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:227:in `requested_specs'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:108:in `block in definition_method'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:20:in `setup'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler.rb:107:in `setup'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/bundler/setup.rb:20:in `<top (required)>'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/bitnami/ruby/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:100:in `preload_app'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:156:in `<module:App>'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
/opt/bitnami/ruby/lib/ruby/gems/2.5.0/gems/passenger-5.1.2/src/helper-scripts/rack-preloader.rb:29:in `<main>'</pre>
原因
エラーメッセージから判断すると、Redmineの環境で必要なgemが見つからないため、アプリケーションが正しく起動できていなかったようです。
以下の手順で問題を解決することができました。
解決方法
1. 必要なGemのインストール
エラーメッセージに示されているように、bundle install
コマンドを実行して、必要なgemをインストールします。
cd /opt/bitnami/apps/redmine/htdocs/
bundle install
2. 正しいユーザーとRubyインタープリターの確認
エラーメッセージに示されているように、アプリケーションが正しいユーザー(例:daemon
)および正しいRubyインタープリターを使用して実行されているかを確認します。
sudo /opt/bitnami/ctlscript.sh restart
3. 権限の確認
もし上記の手順で解決しない場合は、ファイルやディレクトリの権限が正しく設定されているかを確認して、必要な権限を付与します。
sudo chown -R bitnami:daemon /opt/bitnami/apps/redmine/htdocs/
sudo chmod -R 755 /opt/bitnami/apps/redmine/htdocs/
4. 依存関係の確認
Gemfile
とGemfile.lock
が最新であり、すべての依存関係が解決されていることを確認してください。
cd /opt/bitnami/apps/redmine/htdocs/
bundle check
もし依存関係の問題が報告された場合、以下のコマンドで再インストールを試みます。
bundle install --deployment
5. ログの確認
上記の手順でも解決しない場合、詳細なエラーログを確認し、特定の問題を特定します。/tmp/passenger-error-WBP0RE.html
などのエラーログファイルをチェックします。
cat /tmp/passenger-error-XXXX.html
以上