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

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

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

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

Ruby on Rails 5

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

nginx

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

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Capistrano

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

Q&A

2回答

837閲覧

`bundle exec cap production deploy`が最後までできません

Eiji_

総合スコア4

unicorn

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

Ruby on Rails 5

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

nginx

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

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Capistrano

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

0グッド

0クリップ

投稿2019/11/28 13:02

編集2019/11/29 10:25

Capistranoを利用したデプロイ

現在、railsでポートフォリを作成中ですが、エラーが出て詰まっています
bundle exec cap production deployとうつとエラーが出ます。
bundle exec cap production deploy --dry-runではエラーが出ずにうまくいきます。
(Capistrano編)世界一丁寧なAWS解説。EC2を利用して、RailsアプリをAWSにあげるまで
基本的にはこれを軸に進めています。

発生している問題・エラーメッセージ

00:15 unicorn:restart 01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/Oekaki_app/current/config/unicorn/production.rb -E production -D 01 master failed to start, check stderr log for details #<Thread:0x00007fb997b8f328@/Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@18.177.63.188: bundle exit status: 1 (SSHKit::Runner::ExecuteError) bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details #<Thread:0x00007fb997b9d9a0@/Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true): Traceback (most recent call last): 1: from /Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/sugiuraeiosamu/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@18.177.63.188: Exception while executing as ec2-user@18.177.63.188: 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 ec2-user@18.177.63.188: Exception while executing as ec2-user@18.177.63.188: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details Caused by: SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@18.177.63.188: 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 /Users/sugiuraeiosamu/environment/Oekaki_app/lib/capistrano/tasks/unicorn.rb:11:in `block in start_unicorn' /Users/sugiuraeiosamu/environment/Oekaki_app/lib/capistrano/tasks/unicorn.rb:10:in `start_unicorn' /Users/sugiuraeiosamu/environment/Oekaki_app/lib/capistrano/tasks/unicorn.rb:47:in `block (3 levels) in <top (required)>' Tasks: TOP => deploy:restart (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@18.177.63.188: Exception while executing as ec2-user@18.177.63.188: bundle exit status: 1 bundle stdout: Nothing written bundle stderr: master failed to start, check stderr log for details

試したこと

config/deploy/production.rb server "18.177.63.188", user: "ec2-user", roles: %w{web app}, ssh_options: { user: "ec2-user", keys: %w(~/.ssh/aws-and-infra-ssh-key.pem), forward_agent: true, # auth_methods: %w(publickey password) # password: "please use keys" }

検索して上記の書き方が違うのかと思いましたが、全くわかりません。

##追記1

capistrano.log DEBUG [a8c23ee2] Command: cd /var/www/Oekaki_app/releases/20191129055110 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle check --path /var/www/Oekaki_app/shared/bundle ) DEBUG [a8c23ee2] The following gems are missing DEBUG [a8c23ee2] * net-ssh (5.2.0) DEBUG [a8c23ee2] * net-scp (2.0.0) DEBUG [a8c23ee2] * sshkit (1.20.0) DEBUG [a8c23ee2] * airbrussh (1.4.0) DEBUG [a8c23ee2] * bindex (0.8.1) DEBUG [a8c23ee2] * byebug (11.0.1) DEBUG [a8c23ee2] * capistrano (3.11.2) DEBUG [a8c23ee2] * capistrano-bundler (1.6.0) DEBUG [a8c23ee2] * capistrano-rails (1.4.0) DEBUG [a8c23ee2] * capistrano-rbenv (2.1.4) DEBUG [a8c23ee2] * regexp_parser (1.6.0) DEBUG [a8c23ee2] * xpath (3.2.0) DEBUG [a8c23ee2] * capybara (3.29.0) DEBUG [a8c23ee2] * childprocess (2.0.0) DEBUG [a8c23ee2] * diff-lcs (1.3) DEBUG [a8c23ee2] * dotenv (2.7.5) DEBUG [a8c23ee2] * dotenv-rails (2.7.5) DEBUG [a8c23ee2] * factory_bot (5.1.0) DEBUG [a8c23ee2] * factory_bot_rails (5.1.0) DEBUG [a8c23ee2] * hirb (0.7.3) DEBUG [a8c23ee2] * unicode-display_width (0.1.1) DEBUG [a8c23ee2] * hirb-unicode (0.0.5) DEBUG [a8c23ee2] * ruby_dep (1.5.0) DEBUG [a8c23ee2] * listen (3.1.5) DEBUG [a8c23ee2] * rspec-support (3.8.2) DEBUG [a8c23ee2] * rspec-core (3.8.2) DEBUG [a8c23ee2] * rspec-expectations (3.8.4) DEBUG [a8c23ee2] * rspec-mocks (3.8.1) DEBUG [a8c23ee2] * rspec-rails (3.8.2) DEBUG [a8c23ee2] * rubyzip (1.3.0) DEBUG [a8c23ee2] * selenium-webdriver (3.142.4) DEBUG [a8c23ee2] * spring (2.1.0) DEBUG [a8c23ee2] * spring-watcher-listen (2.0.1) DEBUG [a8c23ee2] * web-console (3.7.0) DEBUG [a8c23ee2] * webdrivers (4.1.2) DEBUG [a8c23ee2] Install missing gems with `bundle install`
Gemfile source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.5.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.3' # Use postgresql as the database for Active Record gem 'pg', '>= 0.18', '< 2.0' # Use Puma as the app server gem 'puma', '~> 3.11' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'mini_racer', platforms: :ruby # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use ActiveStorage variant # gem 'mini_magick', '~> 4.8' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'rspec-rails' gem 'factory_bot_rails' gem 'hirb' gem 'hirb-unicode' gem 'dotenv-rails' gem 'capistrano' gem 'capistrano-bundler' gem 'capistrano-rails' gem 'capistrano-rbenv' end group :production, :staging do gem 'unicorn' end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 2.15' # Easy installation and use of chromedriver to run system tests with Chrome # gem 'chromedriver-helper' gem 'webdrivers' gem 'selenium-webdriver' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'slim-rails' gem 'html2slim' gem "bootstrap", "~> 4.3.1" gem 'jquery-rails' gem 'shrine' gem 'devise' gem 'devise-i18n' gem 'devise-i18n-views' gem 'image_processing' gem 'mini_magick' gem 'font-awesome-sass' gem "aws-sdk-s3", require: false gem 'omniauth' gem 'omniauth-twitter'

capistrano.logのエラーを読むと、Gemファイルのgroup :development, :testが
無いってことになりますが、
上記のQiitaだとこれでいいのですが
AWSはこれで大丈夫
だとステージングにGemを追加してます。どうゆうことなんでしょうか

##追記2
unicorn側とnginx側のsockが違っていて治して、更にサーバー側からunicornをkillしたら、最後まで'bundle exec cap production deployが最後までできましたが。 ①サーバー側にインターネットからアクセスすると403エラーになります。 ②また、bundle exec cap production deploy`をunicornをkillせずにやると追記1と同じエラーが出ます。
Unicornの古いプロセスが消えません
今はこれが気になります。

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

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

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

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

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

guest

回答2

0

できました。
403エラーはlog/nginx.error.log から権限の確認で解決できます。
追記3の①はスルーで問題ない感じです。
②はやはりできません。手動でunicornをサーバー上で切るとまたbundle exec cap production deployが最後までエラーなくできます。

投稿2019/11/29 14:02

Eiji_

総合スコア4

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

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

winterboum

2019/11/29 19:43

unicornのpidがどこに保存されているか unicornの起動プロセスではどこのpidを読んでkillしているか を確認してください
guest

0

unicornの起動がうまく行っていません。
AWSにloginして、原因を確定する必要があります

投稿2019/11/29 02:50

winterboum

総合スコア23347

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

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

Eiji_

2019/11/29 08:16

unicorn側のsockとNginx側のsockがあっていませんでした。 `ps aux | grep unicorn`で ``` ec2-user 22773 0.1 11.6 484484 117556 ? Sl 16:52 0:01 unicorn master -c /var/www/Oekaki_app/current/config/unicorn/production.rb -E production -D ec2-user 22777 0.0 10.8 485552 109112 ? Sl 16:52 0:00 unicorn worker[0] -c /var/www/Oekaki_app/current/config/unicorn/production.rb -E production -D ec2-user 22779 0.0 10.7 485552 108416 ? Sl 16:52 0:00 unicorn worker[1] -c /var/www/Oekaki_app/current/config/unicorn/production.rb -E production -D ec2-user 23736 0.0 0.0 119436 952 pts/0 S+ 17:11 0:00 grep --color=auto unicorn ``` もう少し調べてみます
Eiji_

2019/11/29 12:23

##追記3  ``` socket=/var/www/Oekaki_app/current/tmp/sockets/.unicorn.sock I, [2019-11-29T20:50:44.557952 £16419] INFO -- : listening on addr=/var/www/Oekaki_app/current/tmp/sockets/.unicorn.sock fd=11 bundler: failed to load command: unicorn (/var/www/Oekaki_app/shared/bundle/ruby/2.5.0/bin/unicorn) ArgumentError: Already running on PID:16419 (or pid=/var/www/Oekaki_app/current/tmp/pids/unicorn.pid is stale) /var/www/Oekaki_app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=' /var/www/Oekaki_app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start' /var/www/Oekaki_app/shared/bundle/ruby/2.5.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>' /var/www/Oekaki_app/shared/bundle/ruby/2.5.0/bin/unicorn:23:in `load' /var/www/Oekaki_app/shared/bundle/ruby/2.5.0/bin/unicorn:23:in `<top (required)>' ``` ①unlinking existing socket=/var/www/Oekaki_app/current/tmp/sockets/.unicorn.sock ②ArgumentError: Already running on PID:16419 (or pid=/var/www/Oekaki_app/current/tmp/pids/unicorn.pid is stale) これが今は気になります
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問