質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

1回答

5196閲覧

CapistranoでRailsアプリのデプロイ中にUnicornにてエラーが発生【Rails+Unicorn+Nginx】

whitia

総合スコア7

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

1クリップ

投稿2019/10/08 23:52

いつも大変お世話になっております。

今回、初めてRailsアプリを作成し、VPSにデプロイしようとしているところです。

(初心者向け)vpsを契約して、capistrano3でRailsアプリをデプロイするまで [その1 サーバー設定編]
(初心者向け)vpsを契約して、Capistrano3でRailsアプリをデプロイするまで [その2 ローカル設定編]

手順は上記ページを参考にさせてもらっています。
現在はその2の「4-2 デプロイの実行」を行っているところなんですが、どうしても解決できないエラーが発生していて困っています。

まず、ターミナルでbundle exec cap production deploy --traceを実行したときに表示されるエラーは以下になります。
あまりにも長いので関係ありそうなところだけ掲載します。

/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.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 /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user@150.95.152.189: bundle exit status: 1 (SSHKit::Runner::ExecuteError) bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as user@150.95.152.189: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' Caused by: SSHKit::Command::Failed: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/command.rb:97:in `exit_status=' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:170:in `execute_command' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `tap' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:80:in `execute' /Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:11:in `block in start_unicorn' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:92:in `within' /Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:10:in `start_unicorn' /Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:53:in `block (3 levels) in <top (required)>' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run' /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' Tasks: TOP => unicorn:restart The deploy has failed with an error: Exception while executing as user@150.95.152.189: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details ** Invoke deploy:failed (first_time) ** Execute deploy:failed

続いて、VPSのunicorn.logのエラー内容が以下になります。

[fog][DEPRECATION] Fog::Storage::AWS is deprecated, please use Fog::AWS::Storage. [fog][WARNING] Unrecognized arguments: region, aws_access_key_id, aws_secret_access_key bundler: failed to load command: unicorn (/var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn) TypeError: no implicit conversion of nil into String /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/signaturev4.rb:12:in `+' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/signaturev4.rb:12:in `initialize' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:544:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:544:in `setup_credentials' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:527:in `initialize' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:788:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/services_mixin.rb:16:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/storage.rb:22:in `new' /var/www/app/shared/bundle/ruby/2.6.0/gems/carrierwave-2.0.0/lib/carrierwave/storage/fog.rb:68:in `eager_load' /var/www/app/shared/bundle/ruby/2.6.0/gems/carrierwave-2.0.0/lib/carrierwave.rb:77:in `block in <class:Railtie>' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `each' /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/application/finisher.rb:118:in `block in <module:Finisher>' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `instance_exec' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `run' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:61:in `block in run_initializers' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each' /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/initializable.rb:60:in `run_initializers' /var/www/app/shared/bundle/ruby/2.6.0/gems/railties-6.0.0/lib/rails/application.rb:363:in `initialize!' /var/www/app/releases/20191008231529/config/environment.rb:5:in `<top (required)>' config.ru:4:in `require_relative' config.ru:4:in `block in <main>' /var/www/app/shared/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval' /var/www/app/shared/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize' config.ru:1:in `new' config.ru:1:in `<main>' /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `eval' /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `block in builder' /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:794:in `build_app!' /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:141:in `start' /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/bin/unicorn:128:in `<top (required)>' /var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `load' /var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `<top (required)>'

1,2行目のfogに関するエラーについて
config/initializers/carrier_wave.rbにてAWSの設定を行っています。
各値はdotenvというGemを使って環境変数に設定しています。
VPSにはconfig/master.keyを作成し、ローカルと同じ値を設定しました。

3行目以降のエラーについて
UnicornはGemfileのgem 'unicorn'で入るはずだと思うんですが…
一応、VPSでgem install unicornを実行してから再デプロイするも状況変わらず。

CapistranoやらUnicornやらNginxやら初めてのことばかりでよくわかっていないので、どなたか解決法を教えていただけると大変助かります。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

【自己解決】

config/deploy.rbに以下を追記しました。

set :default_env, { rbenv_root: "/home/user/.rbenv", path: "/home/user/.rbenv/bin:$PATH", region: ENV["S3_REGION"], aws_access_key_id: ENV["S3_ACCESS_KEY"], aws_secret_access_key: ENV["S3_SECRET_KEY"] }

Capistranoを使ったデプロイでは環境変数.bash_profileを読み込まずに実行されます。
ですので、Capistrano(Unicorn?)の設定ファイルで明示的に環境変数を設定する必要があります。

See also: Rails issue on cap production deploy

.bashrcに設定する方法もあるようです(未検証)。
Capistrano + carrierwaveを使用した際に出るエラー解消

投稿2019/10/10 07:43

whitia

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問