I tried to reset the database by ssh connection to EC2 ( rails db: migrate: reset RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
).
PG::ObjectInUse:ERROR:database "AnayumeAppDB" is being accessed by other users
appears.I thought, "Can I easily migrate by restarting EC2?" and restarted EC2 on the AWS console (stop & start).After resetting the database on EC2, the migration was successful.railsdb:seedRAILS_ENV=production
and started puma (bundle exec rails-e-production
) and visited the browser.
Before we did the above "ssh connection to EC2 and reset the database", we checked the puma process ID in psax|grepuma
and stopped puma in kill-9PID
.However, when I accessed the site from my browser, the page was displayed normally (I stopped puma, so the page should not be displayed).
Also, I reset the above database and started puma in the root directory of the app (/var/www/rails/AnayumeApp-web
).However, since you are using capistrano, the latest file should be in /var/www/rails/AnayumeApp-web/current
and you should have run the command to reset the database and restart the puma in this directory?
/var/www/rails/AnayumeApp-web/current/log
I searched the log below, but I couldn't find an error statement.
puma_error.log
puma startup: 2020-05-08 01:55:37+0000===
puma_access.log
puma startup: 2020-05-08 01:55:37+0000===
* Listening on unix://var/www/rails/AnayumeApp-web/shared/tmp/sockets/puma.sock
puma.stdout.log
puma startup: 2020-05-08 01:24:04+0000===
* Restarting...
* Listening on unix://var/www/rails/AnayumeApp-web/releases/20200508012915/tmp/sockets/puma.sock
Exiting
=== puma startup: 2020-05-08 01:48:45 + 0000===
p I am concerned that the path listening to puma.sock is not shared/tmp/sockets/puma.sock
(Because I ran the command to launch puma in the AnayumeApp-web directory?)
nginx.error.log
May 8, 2020 00:50:59 [error] 21638 #0:*154085 open()
"/usr/share/nginx/html/latest/dynamic/instance-identity/document" failed (2: No such file or directory),
client:10.0.1.104, server:_, request: "GET/latest/dynamic/instance-identity/document HTTP/1.1", host: "[::ffff:a9fe:a9fe]"
nginx.access.log
10.0.4.128 --- [08/May/2020:01:13:08+0000] "GET/HTTP/1.1"2003520"-"ELB-HealthChecker/2.0"
puma.stderr.log
=== puma startup: 2020-05-08 09:36:16 + 0000===
production.log
D, [2020-05-08T22:08:53.266128 #28931] DEBUG -- : ESC[1mESC[36mMap Create (0.9ms)ESC[0m ESC[1mESC[32mINSERT INTO "maps" ("address", "latitude", "longitude", "title", "comment", "picture", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"ESC[0m [["address", "台北"], ["latitude", 25.0375198], ["longitude", 121.5636796], ["title", "台北"], ["comment", "I want to eat up Taiwanese sweets..."], ["picture", "taipei.jpg", ["user_id", 1], ["created_at", "2020-05-08 22:08:53.264659"], ["updated_at", "2020-05-08 22:08:53.264659"]]]
→The migration seems to be successful (the production.log was copied at a different time than other logs, so the time is different)
I thought that the path to listening to puma.sock was different because I started puma in the AnayumeApp-web directory instead of the current directory, but I didn't go any further.
US>Ssh connection to EC2, access the database, and delete the database (AnayumeAppDB).We then reset the database and launch puma in /var/www/rails/AnayumeApp-web/current on EC2.However, the browser still shows 502 Bad Gateway.
/etc/nginx/conf.d/AnayumeApp
server unix: /var/www/rails/AnayumeApp-web/shared/tmp/sockets/puma.sock;
puma.rb
bind "unix://#{app_dir}/tmp/sockets/puma.sock"
Before the EC2 reboot, the browser was able to access it successfully, so I think there is no problem with the security group and other settings around AWS.
Above all, I couldn't find such a problem in the log, so I'm groping.
Thank you for your cooperation.
ruby-on-rails ruby amazon-ec2 rds
It was very rudimentary, but I forgot to start nginx...
"When I was researching on ""ec2 Restart 502 BadGateWay"", I came across an example of ""unicorn is not starting well"" and noticed it."
http://lina-marble.hatenablog.com/entry/2016/04/12/153610
sudo systemctl start nginx
on EC2, and the browser now displays the page successfully.
After EC2 reboot, I manually migrated and started puma, so I thought it was caused by DB or puma.
© 2024 OneMinuteCode. All rights reserved.