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

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

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

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

Ruby on Rails

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

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

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

Capistrano

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

Q&A

0回答

3769閲覧

Capistorano デプロイ SSHKit::Runner::ExecuteError : rake exit status: 1の原因をご教授お願い致します

sinzanmono46

総合スコア6

unicorn

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

Ruby on Rails

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

Amazon S3

Amazon S3 (Simple Storage Service)とはアマゾン・ウェブ・サービスが提供するオンラインストレージサービスです。

AWS(Amazon Web Services)

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

Capistrano

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

1グッド

1クリップ

投稿2019/12/28 03:45

編集2019/12/28 06:53

現在、railsをAWSでデプロイを試みておりますが、capistoranoのエラーで、
数日間困っております。
アプリ内ではactive storageを使用しており、S3を指定しております。
各キーは/etc/environmentに入れております。
また、AWSのキーはcredentialsにも念のため入れてます。

試みたこと
スワップ領域を用意しメモリの容量拡大
各種キーをenvironmentに保管(DATABASE_PASSWOR,SECRET_KEY_BASE,IAMキー)

情けないですが原因が全く分からないため、
お力添えの程、何卒宜しくお願い致します。

Error log

00:12 deploy:assets:precompile 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile #<Thread:0x00007fa8bc548e10@/Users/xxx/.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/xxx/.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/xxx/.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.176.69.6: rake exit status: 1 (SSHKit::Runner::ExecuteError) rake stdout: Nothing written rake stderr: Nothing written (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as ec2-user@18.176.69.6: rake exit status: 1 rake stdout: Nothing written rake stderr: Nothing written Caused by: SSHKit::Command::Failed: rake exit status: 1 rake stdout: Nothing written rake stderr: Nothing written Tasks: TOP => deploy:assets:precompile (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@18.176.69.6: rake exit status: 1 rake stdout: Nothing written rake stderr: Nothing written ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines: DEBUG [b30eab60] * listen (3.1.5) DEBUG [b30eab60] * parallel (1.19.1) DEBUG [b30eab60] * parser (2.6.5.0) DEBUG [b30eab60] * rainbow (3.0.0) DEBUG [b30eab60] * ruby-progressbar (1.10.1) DEBUG [b30eab60] * unicode-display_width (1.6.0) DEBUG [b30eab60] * rubocop (0.78.0) DEBUG [b30eab60] * spring (2.1.0) DEBUG [b30eab60] * spring-watcher-listen (2.0.1) DEBUG [b30eab60] * web-console (4.0.1) DEBUG [b30eab60] Install missing gems with `bundle install` DEBUG [b30eab60] Finished in 0.407 seconds with exit status 1 (failed). INFO [086f0268] Running $HOME/.rbenv/bin/rbenv exec bundle install --path /var/www/datingapp/shared/bundle --jobs 4 --without development test --deployment --quiet as ec2-user@18.176.69.6 DEBUG [086f0268] Command: cd /var/www/datingapp/releases/20191228064323 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle install --path /var/www/datingapp/shared/bundle --jobs 4 --without development test --deployment --quiet ) INFO [086f0268] Finished in 0.531 seconds with exit status 0 (successful). DEBUG [9c74a943] Running if test ! -d /var/www/datingapp/releases/20191228064323; then echo "Directory does not exist '/var/www/datingapp/releases/20191228064323'" 1>&2; false; fi as ec2-user@18.176.69.6 DEBUG [9c74a943] Command: if test ! -d /var/www/datingapp/releases/20191228064323; then echo "Directory does not exist '/var/www/datingapp/releases/20191228064323'" 1>&2; false; fi DEBUG [9c74a943] Finished in 0.123 seconds with exit status 0 (successful). INFO [5c099478] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as ec2-user@18.176.69.6 DEBUG [5c099478] Command: cd /var/www/datingapp/releases/20191228064323 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

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', '~> 6.0.1' # Use mysql as the database for Active Record gem 'mysql2', '>= 0.4.4' # Use Puma as the app server gem 'puma', '~> 4.1' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 4.0' # 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.7' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: %i[mri mingw x64_mingw] gem 'capistrano' gem 'capistrano-rbenv' gem 'capistrano-bundler' gem 'capistrano-rails' gem 'capistrano3-unicorn' end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'listen', '>= 3.0.5', '< 3.2' gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'better_errors' gem 'binding_of_caller' gem 'rubocop', require: false gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end group :production do gem 'unicorn', '5.4.1' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'active_hash' gem "aws-sdk-s3", require: false gem "devise" gem 'dotenv-rails' gem 'font-awesome-sass' gem 'mini_magick' gem 'pry-rails' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

Capfile

require "capistrano/setup" require "capistrano/deploy" require "capistrano/scm/git" install_plugin Capistrano::SCM::Git require "capistrano/rbenv" require "capistrano/bundler" require "capistrano/rails/assets" require "capistrano/rails/migrations" require 'capistrano3/unicorn' Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

deploy.rb

lock '3.11.2' set :application, 'xxx' set :repo_url, 'git@github.com:xxx/xxx.git' set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') set :rbenv_type, :user set :rbenv_ruby, '2.5.1' set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/xxxAppPort.pem'] set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" } set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" } set :keep_releases, 5 set :linked_files, fetch(:linked_files, []).push("config/master.key") after 'deploy:publishing', 'deploy:restart' namespace :deploy do task :restart do invoke 'unicorn:restart' end end

Unicorn.rb

app_path = File.expand_path('../../../', __FILE__) worker_processes 1 working_directory "#{app_path}/current" pid "#{app_path}/shared/tmp/pids/unicorn.pid" listen "#{app_path}/shared/tmp/sockets/unicorn.sock" stderr_path "#{app_path}/shared/log/unicorn.stderr.log" stdout_path "#{app_path}/shared/log/unicorn.stdout.log" timeout 60 preload_app true GC.respond_to?(:copy_on_write_friendly=) && GC.copy_on_write_friendly = true check_client_connection false run_once = true before_fork do |server, worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! if run_once run_once = false # prevent from firing again end old_pid = "#{server.config[:pid]}.oldbin" if File.exist?(old_pid) && server.pid != old_pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH => e logger.error e end end end after_fork do |_server, _worker| defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection end

config/environments/production.rb

Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. config.cache_classes = true config.eager_load = true config.consider_all_requests_local = false config.action_controller.perform_caching = true config.require_master_key = true config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? config.assets.compile = false # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :amazon config.force_ssl = true config.log_level = :debug config.log_tags = [:request_id] config.action_mailer.perform_caching = false config.i18n.fallbacks = true config.active_support.deprecation = :notify config.log_formatter = ::Logger::Formatter.new if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end

config/deploy/production.rb

server "11.111.11.1", user: "ec2-user", roles: %w{app db web}
aiuhaeufh08👍を押しています

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

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

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

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

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

siruku6

2019/12/28 03:57 編集

念のため、公開しても問題ない範囲で config/deploy/環境名.rb も掲載しておきましょう。(EC2や鍵のパスワードが特定されないように注意) エラーとしては bundle exec rake assets:precompile が失敗しているようです。 また、precompileのエラーを起こしたときに私は config/environments/環境名.rb も修正した記憶があるので、そちらも掲載しておきましょう。 ちなみにそのときは、javascript / css のシンタックスエラーもprecompile失敗の原因の一つだったので、javascript css をすべて見直すという苦行が発生しました... --- 確かなんの参考にもならなかったと記憶していますが念のため、 Refer to log/capistrano.log for details. とあるので、このファイルは軽く見ておきましょう(たぶん、コンソールログに表示されているものと全く同じ内容だった気がします...)
sinzanmono46

2019/12/28 07:20 編集

siruku6様、お力添えの程、ありがとうございます。 それぞれのファイルを追記致しました。 追記したエラーログに関してですが、有益な情報はないと判断して省いていたのですがどうでしょうか? また、config/environments/production.rbに書いている config.assets.compile = falseはtrueにしてみましたが、エラーは変わりませんでした。 なお、以前ローカル内でRAILS_ENV=production rails assets:precompileとしたところ、 Compilation failed: ModuleNotFoundError: Module not found: Error: Can't resolve '@fortawesome/fontawesome-free' in '/Users/xxx/personal_app/xxxapp/app/javascript/packs' となり、失敗しました。 未熟で申し訳ございませんが、何卒ご教授頂ければ嬉しい限りです。
siruku6

2020/01/05 07:58 編集

遅くなって申し訳ないです。 やはりcapistranoが出してくれたエラーログは大して役に立たなさそうです。 ただし、なぜかcapistranoでprecompileしたときは出してくれないのですが、そうでないときはきちんとerror原因を出してくれているみたいですね。 ModuleNotFoundError: Module not found: Error: Can't resolve '@fortawesome/fontawesome-free' in '/Users/xxx/personal_app/xxxapp/app/javascript/packs' が原因のようです。 Can't resolve '@fortawesome/fontawesome-free' とあるので、これを解釈することができていないようです。 uglifierというgemの処理中に発生していると考えられるので、その辺を調べる必要があると思います。 --- ちなみに、uglifierは、productionモードで precompile するときだけ処理を行っており、処理内容としては、アプリにアクセスしてきた人が css や javascript を解読できないように、ソースを醜く(ugly)書き換えてくれる、というものになります。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問