capistranoで unicorn:restart 時に exec bundle exec unicorn -c */production.rb -E production -D のエラーが出ます
- 評価
- クリップ 0
- VIEW 670
前提・実現したいこと
ご覧いただきありがとうございます。現在独学でRails tutorialを勉強している者です。
より実践に近い形ということでサーバーを借り、rails tutorial 2週目を学習中に起こった問題です。
13.4.4 本番環境での画像アップロード
rails tutorialの上記を学習中、本番環境への画像アップロードを、conohaのオブジェクトストレージを契約し実装しようとしていたところ、今まで問題なく通っていた
bundle exec cap production deploy
こちらのコマンドがunicorn:restartでエラーが出るようになりました。
現在までほぼ問題なく通っていたコマンドです、エラーメッセージを見ても、下記のgem
- carrierwave 1.2.2
- fog 1.42
これらが干渉しているのかな?と思い3日間さまざまな手を試しましたが、まったく解決できそうにありません。
問題解決のゴールとしては、今までのdeployが問題なくできるようになり、conohaストレージへの本番環境への画像アップロード実装まで勉強したいと考えています。
エラーログを注視する毎日でしたが、どうしても八方塞がりの状況です。
どうかお力添えいただけますと幸いです。
発生している問題・エラーメッセージ
[user]@user:/mnt/c/rails_dev/rails_tutorial/sample_app$ bundle exec cap production deploy
Enter passphrase for /home/[user]/.ssh/vps/id_rsa:
~~~~~~~
00:36 unicorn:restart
01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/sample_app/current/config/unicorn/production.rb -E production…
01 master failed to start, check stderr log for details
#<Thread:0x00007ff67c155890@/home/user/sample_app/vendor/bundle/ruby/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
~~~~~~~
1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
1: from /home/user/sample_app/vendor/bundle/ruby/2.6.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/home/user/sample_app/vendor/bundle/ruby/2.6.0/gems/sshkit-1.21.0/lib/sshkit/command.rb:97:in `exit_status=': bundle exit status: 1 (SSHKit::Command::Failed)
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
1: from /home/user/sample_app/vendor/bundle/ruby/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/user/sample_app/vendor/bundle/ruby/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user@160.*.*.*: bundle exit status: 1 (SSHKit::Runner::ExecuteError)
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@160.*.*.*: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
Caused by:
SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
/mnt/c/rails_dev/rails_tutorial/sample_app/lib/capistrano/tasks/unicorn.rb:11:in `block in start_unicorn'
/mnt/c/rails_dev/rails_tutorial/sample_app/lib/capistrano/tasks/unicorn.rb:10:in `start_unicorn'
/mnt/c/rails_dev/rails_tutorial/sample_app/lib/capistrano/tasks/unicorn.rb:53:in `block (3 levels) in <top (required)>'
Tasks: TOP => unicorn:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as user@160.*.*.*: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
上記のunicorn:restartがどうしても解決しません。
(途中、色々手を試しているうちにbundle installも通らなくなりましたが、本番環境にcurlを導入したりと色々やって解決しました)
問題に関連していると思われるソースコード
Gemfile
source 'https://rubygems.org'
gem 'rails', '5.2.3'
gem 'bcrypt', '3.1.12'
gem 'carrierwave', '1.2.2'# 13.4.1 画像投稿gem
gem 'mini_magick', '4.7.0'# 13.4.1 画像加工?gem
gem 'faker', '1.7.3'# 10.3.3 サンプルデータ投入のgem
gem 'will_paginate', '3.1.7'# 10.3.3 ページネーションのためのgem。バグのため3.1.6からバージョンアップ
gem 'bootstrap-will_paginate', '1.0.0'# 10.3.3 ページネーションのためのgem
gem 'dotenv-rails'# carrierwave.rb用に環境変数を管理するために入れたgem
~~~~~~~
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.1.5'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rbenv'
gem 'ed25519'
gem 'bcrypt_pbkdf'
~~~~~~~
group :production do
gem 'pg', '0.20.0'
gem 'fog', '1.42'# 13.4.1 本番環境でクラウドストレージへ保存するのに便利なgem
end
~~~~~~~
group :production, :staging do
gem 'mysql2'
gem 'unicorn', '5.4.1'
capistrano.log(最後の3行)
INFO [ecdeef74] Running $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/sample_app/current/config/unicorn/production.rb -E production -D as user@160.*.*.*
DEBUG [ecdeef74] Command: cd /var/www/sample_app/current && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.4" ; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/sample_app/current/config/unicorn/production.rb -E production -D )
DEBUG [ecdeef74] master failed to start, check stderr log for details
.carrierwave.rb
# 現在はバグ検証のため、【.carrierwave.rb】としています
require 'carrierwave/storage/abstract'
require 'carrierwave/storage/file'
require 'carrierwave/storage/fog'
if Rails.env.production?
CarrierWave.configure do |config|
# config.fog_provider = 'fog'
config.fog_credentials = {
provider: 'OpenStack',
openstack_tenant: ENV['CONOHA_TENANT_NAME'],
openstack_username: ENV['CONOHA_USERNAME'],
openstack_api_key: ENV['CONOHA_API_PASSWORD'],
openstack_auth_url: ENV['CONOHA_API_AUTH_URL'] + '/tokens',
}
config.fog_directory = ENV['CONOHA_CONTAINER_NAME']
config.fog_public = false
config.asset_host = ENV['CONOHA_ASSET_HOST'] + '/' + ENV['CONOHA_CONTAINER_NAME']
# config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
# 日本語ファイル名の設定
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
end
unicorn.logにあるCarrierWave::Storage::Fogが怪しい??
本番環境に残っている下記のunicorn.log
I, [2020-03-15T20:35:24.812163 #12624] INFO -- : Refreshing Gem list
bundler: failed to load command: unicorn (/var/www/sample_app/shared/bundle/ruby/2.6.0/bin/unicorn)
NameError: uninitialized constant CarrierWave::Storage::Fog
(eval):1:in `storage'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave/uploader/configuration.rb:78:in `eval'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave/uploader/configuration.rb:78:in `storage'
/var/www/sample_app/releases/20200315113501/app/uploaders/picture_uploader.rb:14:in `<class:PictureUploader>'
~~~~~~~
config.ru:4:in `require_relative'
config.ru:4:in `block in <main>'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:125:in `instance_eval'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:125:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `eval'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `block in builder'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:795:in `build_app!'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:139:in `start'
/var/www/sample_app/shared/bundle/ruby/2.6.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>'
/var/www/sample_app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `load'
/var/www/sample_app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `<top (required)>'
こちらがどうも怪しいとは思っているのですが、解決方法が全くわかりません…
試したこと
- 本番環境の unicorn.pid の削除
- fog や fog-aws のgem unistall(conohaのオブジェクトストレージへどうやって保存するか試行錯誤していたところでfog-aws等をinstallしていました)
- carrierwave.rbのコメントアウト等
ほかにも色々試行錯誤しましたが、だめでした…
補足情報(FW/ツールのバージョンなど)
- ubuntu(WSL) 18.04.3
- Ruby 2.6.4
- Rails 5.2.3
- capistrano 3.12.0
- unicorn 5.4.1
本番環境
- さくらVPS(CentOS7)
どうか皆様お力添えいただけますと幸いです。
どうぞよろしくお願いいたします。
文字数が10000文字までしか入力できませんので、ほかのファイル情報等は追記させていただきます。
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
check解決した方法
0
初心に帰ってコードを見直してみると、
carrierwave.rb
ではなく
carrier_wave.rb
でした!なんと灯台下暗し…お騒がせいたしました。
これがネームエラーの意味だったのか…
ネームエラーの際はファイル名まで気をつけようと、また一つ学習しました。
ただ、また次のエラーが出たので、そちらは別スレに立てます。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.19%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
H4L
2020/03/16 21:55
エラーログにもありますが、
capistrano.logやunicorn.logを追記した方がいいかもしれません
自分で見たら意外とあっさりわかる場合もあるので
miura.newaction
2020/03/17 15:48
修正のご依頼をいただきありがとうございます!
unicorn.log と capistrano.log を抜粋して記載いたしました。(文字数の関係で全ての記載が難しく申し訳ありません)
また、両ログとも確認してみましたが、CarrierWave::Storage::Fog という記載が怪しいのかなと思う程度で、ファイル内の全角空白文字を探してみたり、fogのgemを削除したりしてみましたが根本的な解決には至りませんでした。。