前提・実現したいこと
現在、ruby on rails で開発したアプリを、capistoranoを使ってEC2インスタンスにデプロイをこころみているところです。
そこで、unicorn:startの中の、プロセスをkillする処理が失敗してしまい困っています。
発生している問題・エラーメッセージ
###中略(bundle exec cap production deploy実行中) 01:31 unicorn:start 01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/app/current/config/u… 01 master failed to start, check stderr log for details #<Thread:0x00007f937a839d10@/Users/user/rails6-compose/apps/app/vendor/bundle/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): 13: from /Users/user/rails6-compose/apps/app/vendor/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' ###中略 /Users/user/rails6-compose/apps/app/vendor/bundle/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 /Users/user/rails6-compose/apps/app/vendor/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute' /Users/user/rails6-compose/apps/app/vendor/bundle/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@x.xx.xxx.xxx: 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@x.xx.xxx.xxx: 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 Tasks: TOP => unicorn:start (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as ec2-user@x.xx.xxx.xxx: 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: DEBUG [8689ce8d] Command: if test ! -d /var/www/app/releases/20200721052338; then echo "Directory does not exist '/var/www/app/releases/20200721052338'" 1>&2; false; fi DEBUG [8689ce8d] Finished in 0.614 seconds with exit status 0 (successful). INFO [7cb59359] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate as ec2-user@x.xx.xxx.xxx DEBUG [7cb59359] Command: cd /var/www/app/releases/20200721052338 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.4" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate ) INFO [7cb59359] Finished in 1.928 seconds with exit status 0 (successful). INFO [5aa6de05] Running /usr/bin/env ln -s /var/www/app/releases/20200721052338 /var/www/app/releases/current as ec2-user@x.xx.xxx.xxx DEBUG [5aa6de05] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.4" ; /usr/bin/env ln -s /var/www/app/releases/20200721052338 /var/www/app/releases/current ) INFO [5aa6de05] Finished in 0.683 seconds with exit status 0 (successful). INFO [d925d361] Running /usr/bin/env mv /var/www/app/releases/current /var/www/app as ec2-user@x.xx.xxx.xxx DEBUG [d925d361] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.4" ; /usr/bin/env mv /var/www/app/releases/current /var/www/app ) INFO [d925d361] Finished in 0.711 seconds with exit status 0 (successful). DEBUG [d4a27ef4] Running if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi as ec2-user@x.xx.xxx.xxx DEBUG [d4a27ef4] Command: if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi DEBUG [d4a27ef4] Finished in 0.613 seconds with exit status 0 (successful). ###ここで、プロセスのkillに失敗します。 DEBUG [fda06aef] Running [ -e /var/www/app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/app/shared/tmp/pids/unicorn.pid` as ec2-user@x.xx.xxx.xxx DEBUG [fda06aef] Command: [ -e /var/www/app/shared/tmp/pids/unicorn.pid ] && kill -0 `cat /var/www/app/shared/tmp/pids/unicorn.pid` DEBUG [fda06aef] Finished in 0.636 seconds with exit status 1 (failed). INFO [f48744c2] Running $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/app/current/config/unicorn.rb -E deployment -D as ec2-user@x.xx.xxx.xxx DEBUG [f48744c2] Command: cd /var/www/app/current && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.4" RAILS_ENV="production" ; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/app/current/config/unicorn.rb -E deployment -D ) DEBUG [f48744c2] master failed to start, check stderr log for details
設定ファイル
deploy.rb lock '3.14.1' set :application, 'app' set :repo_url, 'git@github.com:XXXXXX/app.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.6.4' set :ssh_options, auth_methods: ['publickey'], keys: ['~/.ssh/my-key.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" listen "#{app_path}/shared/tmp/sockets/unicorn.sock" pid "#{app_path}/shared/tmp/pids/unicorn.pid" 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 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
試したこと
・いろいろ記事を調べたところ、unicorn.pidを削除すると成功するとありましたが失敗しました。
・pidsのディレクトリの権限を、誰でも書き込み・読み込みできるよう権限を777にしましたが失敗しました。
・working_directory "#{app_path}/current"
となっており、このディレクトリに移動した上で、
$HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/app/current/config//unicorn.rb
を押下したところ、
[ec2-user@ip-XXX-XX-XX-XX current]$ ls /var/www/app/shared/tmp/pids/unicorn.pid /var/www/app/shared/tmp/pids/unicorn.pid
と、ファイルの生成はうまく行くようです。
ですが、プロセスは動いてないみたいです。
$ ps aux | grep unicorn |grep -v grep $
仮説としては、unicorn.pidファイルの生成はできたけど
何らかの理由で、プロセスがすぐに落ちてしまうのかと思いますが
解決策がわかりません。
ご教授お願い致します。
補足情報(FW/ツールのバージョンなど)
参考情報
【初心者向け】WEBプログラミング学習完全ロードマップ【MacBook購入から実務レベルまで】
【保存版】AWSのアカウント登録からRails自動デプロイまでの全手順【Capistrano】
回答1件
あなたの回答
tips
プレビュー