Capistranoを導入後、自動デプロイするとサイトにアクセス出来なくなりました。
前提・実現したいこと
ここに質問の内容を詳しく書いてください。
EC2で個人開発したRuby on rails アプリを手動デプロイし、
その後自動デプロイできる状態まで作業したのですが、
ブラウザでIPアドレスを開こうとするとこのサイトにアクセス出来ませんと表示されてしまいます。
■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
サイトにアクセス出来ない。
該当のソースコード
[ec2-user@ip-172-31-45-251 ~]$ less log/unicorn.stderr.log
log/unicorn.stderr.log: No such file or directory
[ec2-user@ip-172-31-45-251 ~]$ cd /var/www/nostalgia
[ec2-user@ip-172-31-45-251 nostalgia]$ less log/unicorn.stderr.log
I, [2020-11-07T10:55:16.939475 #28976] INFO -- : master process ready
I, [2020-11-07T10:55:16.944288 #28984] INFO -- : worker=0 ready
bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails)
ArgumentError: Already running on PID:28976 (or pid=/var/www/nostalgia/tmp/pids/unicorn.pid is stale)
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid='
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load'
/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<top (required)>'
bundler: failed to load command: unicorn_rails (/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails)
ArgumentError: Already running on PID:28976 (or pid=/var/www/nostalgia/tmp/pids/unicorn.pid is stale)
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid='
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load'
/home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<top (required)>'
I, [2020-11-08T07:58:59.094353 #28976] INFO -- : reaped #<Process::Status: pid 28984 exit 0> worker=0
I, [2020-11-08T07:58:59.094553 #28976] INFO -- : master complete
I, [2020-11-08T07:59:15.497198 #6889] INFO -- : Refreshing Gem list
I, [2020-11-08T07:59:16.579258 #6889] INFO -- : listening on addr=0.0.0.0:3000 fd=9
I, [2020-11-08T07:59:16.584083 #6889] INFO -- : master process ready
I, [2020-11-08T07:59:16.588905 #6897] INFO -- : worker=0 ready
I, [2020-11-08T08:24:21.305363 #6889] INFO -- : reaped #<Process::Status: pid 6897 exit 0> worker=0
I, [2020-11-08T08:24:21.305561 #6889] INFO -- : master complete
I, [2020-11-08T08:39:59.756896 #7391] INFO -- : Refreshing Gem list
I, [2020-11-08T08:40:00.819264 #7391] INFO -- : listening on addr=0.0.0.0:3000 fd=9
I, [2020-11-08T08:40:00.823995 #7391] INFO -- : master process ready
I, [2020-11-08T08:40:00.827531 #7399] INFO -- : worker=0 ready
I, [2020-11-09T01:58:37.132740 #7391] INFO -- : reaped #<Process::Status: pid 7399 exit 0> worker=0
I, [2020-11-09T01:58:37.133055 #7391] INFO -- : master complete
I, [2020-11-09T01:59:11.874187 #12898] INFO -- : Refreshing Gem list
I, [2020-11-09T01:59:13.884108 #12898] INFO -- : listening on addr=/var/www/nostalgia/tmp/sockets/unicorn.sock fd=9
I, [2020-11-09T01:59:13.888796 #12898] INFO -- : master process ready
I, [2020-11-09T01:59:13.892300 #12906] INFO -- : worker=0 ready
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=': Already running on PID:12898 (or pid=/var/www/nostalgia/tmp/pids/unicorn.pid is stale) (ArgumentError)
from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load'
from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<main>'
/home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=': Already running on PID:12898 (or pid=/var/www/nostalgia/tmp/pids/unicorn.pid is stale) (ArgumentError)
from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
from /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `load'
from /home/ec2-user/.rbenv/versions/2.6.5/bin/unicorn_rails:23:in `<main>'
I, [2020-11-09T02:57:50.438145 #12898] INFO -- : reaped #<Process::Status: pid 12906 exit 0> worker=0
I, [2020-11-09T02:57:50.438283 #12898] INFO -- : master complete
I, [2020-11-09T03:12:01.935370 #13576] INFO -- : Refreshing Gem list
I, [2020-11-09T03:12:02.970145 #13576] INFO -- : unlinking existing socket=/var/www/nostalgia/tmp/sockets/unicorn.sock
I, [2020-11-09T03:12:02.970332 #13576] INFO -- : listening on addr=/var/www/nostalgia/tmp/sockets/unicorn.sock fd=9
:client_loop: send disconnect: Broken pipe
uraokayuutarou@uraokayuutarou-no-MacBook .ssh %
試したこと
less log/unicorn.stderr.logで最新のエラーを確認し、
ArgumentError: Already running on PID:28976 を確認し、
ps aux | grep unicornでプロセスを確認し、killコマンドを実行しようとしたところ、
PID:28976が見つかりませんでした。
[ec2-user@ip-172-31-45-251 ~]$ ps aux | grep unicorn
ec2-user 13013 0.0 9.4 455308 94912 ? Sl 07:19 0:01 unicorn master -c /var/www/nostalgia/current/config/unicorn.rb -E deployment -D
ec2-user 13052 0.0 8.6 456400 87576 ? Sl 07:19 0:00 unicorn worker[0] -c /var/www/nostalgia/current/config/unicorn.rb -E deployment -D
ec2-user 13526 0.0 0.0 117012 908 pts/2 S+ 07:52 0:00 less log/unicorn.stderr.log
ec2-user 13733 0.0 0.0 119436 964 pts/3 S+ 08:11 0:00 grep --color=auto unicorn
[ec2-user@ip-172-31-45-251 ~]$ kill 13013
[ec2-user@ip-172-31-45-251 ~]$
PIDが古くなっているとエラー文に記載があったため
psで動作しているPIDを確認してみました。
uraokayuutarou@uraokayuutarou-no-MacBook .ssh % ps
PID TTY TIME CMD
25378 ttys000 0:00.18 -zsh
20482 ttys001 0:00.06 -zsh
18686 ttys003 0:00.20 -zsh
33712 ttys004 0:00.31 -zsh
18715 ttys005 0:00.09 -zsh
uraokayuutarou@uraokayuutarou-no-MacBook .ssh %
PID:28976を探してkillすれば問題は解決するのでしょうか!?
EC2でmysql2をbundle installして、
git pull origin masterを実行
bundle exec cap production deploy
sudo systemctl restart mariadb
sudo systemctl restart nginx
を実行しましたが、アクセス出来ず。
bundle install後
増えていた記述
I, [2020-11-07T10:55:14.533545 #28976] INFO -- : Refreshing Gem list I, [2020-11-07T10:55:16.939475 #28976] INFO -- : master process ready
I, [2020-11-07T10:55:16.928690 #28976] INFO -- : listening on addr=0.0.0.0:3000 fd=9
I, [2020-11-07T10:55:1
減った記述
I, [2020-11-09T03:12:02.970145 #13576] INFO -- : unlinking existing socket=/var/www/nostalgia/tmp/sockets/unicorn.sock
I, [2020-11-09T03:12:02.970332 #13576] INFO -- : listening on addr=/var/www/nostalgia/tmp/sockets/unicorn.sock fd=9
: :client_loop: send disconnect: Broken pipe
uraokayuutarou@uraokayuutarou-no-MacBook .ssh %
diffffff参照
エラー文を再度読み直し、PID:28976がどこかで起動したままだと仮定して、
killしてみたのですが、うまく行きませんでした。
[ec2-user@ip-172-31-45-251 ~]$ kill 28976
-bash: kill: (28976) - No such process
補足
rails s してlocal:host3000にアクセスするとアプリは問題なく表示されていました。