Home>

Please write your question in detail here.
Manually deploy the Ruby on rails app personally developed on EC2,
After that, I worked until it was ready for automatic deployment.
When I try to open the IP address in my browser, it says that I cannot access this site.

■■ The following error message occurred while implementing the function.

I can't access the site.
Corresponding source code
[[email protected] ~] $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
[[email protected] 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 = 0I, [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%
  • Error screen screenshot when accessing
    https://gyazo.com/689ac2f97f0908fb4a0cd75a0fc3e6ba

-Check what (or nothing) appears in the nginx log/error log when accessed
[[email protected] nostalgia] $sudo less /var/log/nginx/error.log

~

  • Check what appears (or nothing) in the unicorn log/error log when accessed
    https://gyazo.com/eaa630635e865a6dc62eb4f1b6911911
    Continued
    https://gyazo.com/884521650e3ea73f82bdcd02ac7879f4
What I tried

Check less log/unicorn.stderr.log for the latest error
Check ArgumentError: Already running on PID: 28976 and
When I checked the process with ps aux | grep unicorn and tried to execute the kill command,
PID: 28976 was not found.

[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 ~] $

Because there was a statement in the error statement that the PID was out of date
I checked the PID running on ps.

uraokayuutarou @ uraokayuutarou-no-MacBook .ssh% ps
  PID TTY TIME CMD
25378 ttys000 00: 00.18 -zsh
20482 ttys001 00: 00.06 -zsh
18686 ttys003 00: 00.20 -zsh
33712 ttys004 00: 00.31 -zsh
18715 ttys005 00: 00.09 -zsh
uraokayuutarou @ uraokayuutarou-no-MacBook .ssh%

Will finding and killing PID: 28976 solve the problem? ??

11/11 18:40
Bundle install mysql2 on EC2 and
Run git pull origin master
bundle exec cap production deploy
sudo systemctl restart mariadb
sudo systemctl restart nginx
I ran, but I couldn't access it.

After bundle install

Increasing description
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
Reduced description
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%
See diffffff


11/11 22:56 Addendum
Reread the error statement and assume that PID: 28976 is still running somewhere,
I tried killing it, but it didn't work.

[ec2-user @ ip-172-31-45-251 ~] $kill 28976
-bash: kill: (28976) --No such process

I was able to find out.

When I'm working on deploying again, sudo systemctl restart nginx
When I tried to restart nginx, I got an error message, so
I checked with ps ax | grep nginx to see if nginx is running.

[ec2-user @ ip-172-31-45-251 nostalgia] $sudo systemctl reload nginx
Job for nginx.service invalid.
[ec2-user @ ip-172-31-45-251 nostalgia] $sudo systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[ec2-user @ ip-172-31-45-251 nostalgia] $ps ax | grep nginx
24627 pts/0 D + 0:00 grep --color = auto nginx
[ec2-user @ ip-172-31-45-251 nostalgia] $

And I checked the error log with nginx.
2020/11/12 08:23:52 [emerg] 24605 # 0: directive "upstream" has no opening "{" in /etc/nginx/conf.d/rails.conf: 3
2020/11/12 08:38:21 [emerg] 24646 # 0: directive "upstream" has no opening "{" in /etc/nginx/conf.d/rails.conf: 3
/var/log/nginx/error.log (END)
I predicted that this was probably the reason why I couldn't access the WEB!

Supplement

When I accessed local: host3000 with rails s, the app was displayed without any problem.

  • Answer # 1

    There was an error in the nginx conf.
    Enter the following in the terminal
    vim /etc/nginx/conf.d/rails.conf
    Check the contents

    /var/www/application name/tmp/pids/unicorn.pid
    ⇩ Since the above was incorrect, enter i in the terminal to correct and edit
    server unix: /var/www/application name/shared/tmp/sockets/unicorn.sock;
    Save as: wq

    I couldn't display it because the application name/shared is missing.