Rails自動デプロイ中のSSHKit::Runner::ExecuteError
○期待する動作
http://www.onseo.info/articles/11
の記事をそのままコピー&ペーストして自動デブロイのやり方を学んでいます。
○エラーの内容(抜粋)
macuser@mac-no-MacBook-Air blog-app % bundle exec cap production deploy
を実施後EC2のElasticIPを開くと
502 Bad Gateway(nginx/1.16.1)と表示されます.
以下ターミナル上のエラー内容です。(AWSへのSSH接続は問題なくできています。)
(途中省略)
00:11 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/macuser/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/macuser/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ec2-user@AMAZONEEC2のアドレス: 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@MAZONEEC2のアドレス: 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@AMAZONEEC2のアドレス: 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:
INFO [9e1dfe41] Running $HOME/.rbenv/bin/rbenv exec bundle config --local path /var/www/blog-app/shared/bundle as ec2-user@AMAZONEEC2のアドレス
DEBUG [9e1dfe41] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle config --local path /var/www/blog-app/shared/bundle )
INFO [9e1dfe41] Finished in 0.293 seconds with exit status 0 (successful).
INFO [3b1fed01] Running $HOME/.rbenv/bin/rbenv exec bundle config --local without development:test as ec2-user@AMAZONEEC2のアドレス
DEBUG [3b1fed01] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle config --local without development:test )
INFO [3b1fed01] Finished in 0.299 seconds with exit status 0 (successful).
DEBUG [825050c9] Running if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi as ec2-user@52.193.111.3
DEBUG [825050c9] Command: if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi
DEBUG [825050c9] Finished in 0.103 seconds with exit status 0 (successful).
DEBUG [526cdd54] Running $HOME/.rbenv/bin/rbenv exec bundle check as ec2-user@AMAZONEEC2のアドレス
DEBUG [526cdd54] Command: cd /var/www/blog-app/releases/20200906030849 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.5.1" ; $HOME/.rbenv/bin/rbenv exec bundle check )
DEBUG [526cdd54] The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
DEBUG [526cdd54] The Gemfile's dependencies are satisfied
DEBUG [526cdd54] Finished in 0.428 seconds with exit status 0 (successful).
INFO The Gemfile's dependencies are satisfied, skipping installation
DEBUG [2ef0f040] Running if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi as ec2-user@AMAZONEEC2のアドレス
DEBUG [2ef0f040] Command: if test ! -d /var/www/blog-app/releases/20200906030849; then echo "Directory does not exist '/var/www/blog-app/releases/20200906030849'" 1>&2; false; fi
DEBUG [2ef0f040] Finished in 0.100 seconds with exit status 0 (successful).
INFO [60b7bf95] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as ec2-user@52.193.111.3
DEBUG [60b7bf95] Command: cd /var/www/blog-app/releases/20200906030849 && ( 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 )
○該当箇所
require 'thread'
module SSHKit
module Runner
class Parallel < Abstract
def execute
threads = hosts.map do |host|
Thread.new(host) do |h|
begin
backend(h, &block).run
rescue ::StandardError => e
e2 = ExecuteError.new e
raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
end
end
end
threads.each(&:join)
end
end
end
end
○試したこと
サーバーの再起動(参考https://qiita.com/aoitrain/items/90036ec9c24f0566711e)
GitHubへの再PUSH
AWSへSSH接続後、rake secretを再実行
見づらい文章ですみません。
その他足りないところがありましたら追記させていただきます。
一日調べても解決策が見つからず困っております。
どうぞよろしくお願いいたします。