(Capistrano) After deploying, I get a We're sorry… error in the production environment.

When I automatically deploy an app that works fine in the local environment, an error occurs in the production environment and the view is not displayed When it comes to that, I don't know what to do and I feel desperate. .. .. スクリーンショット 2020-08-17 8.01.24.png Please try it as one of the solutions in such a case.

Conclusion: drop, create manually, migrate automatically

Log in to ec2, manually type commands, and only drop and create the database. After that, the page can be displayed by using the automatic deployment of Capistrano to migrate.

command

After logging in to ec2, first execute the following code to delete and create the database in the production environment.

cd /var/www/<%Application name%>

cd current

rails db:drop RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1

rails db:create RAILS_ENV=production

After that, restart unicorn and mysql. (Long code on the right)

ps aux |grep unic 

//Execution result (number is different)
ec2-user 24327  0.1 11.5 504288 116388 ?       Sl   22:46   0:02 unicorn master -c /var/www/<%Application name%>/current/config/unicorn.rb -E production -D                                                                                            
ec2-user 24334  0.0 12.3 651728 124368 ?       Sl   22:46   0:00 unicorn worker[0] -c /var/www/<%Application name%>/current/config/unicorn.rb -E production -D

kill -9 24327 //Enter process number 24327 for master

sudo service mysqld restart //Restart mysql

Finally return to your local terminal and auto-deploy `Migration is done at this point. ``

bundle exec cap production deploy

accomplished!

Summary

I haven't performed any special operations, but the point is to use the migrate function of capistrano. I don't know why this worked, but it looks like we'll still have to experiment with errors in production. .. ..

Recommended Posts

(Capistrano) After deploying, I get a We're sorry… error in the production environment.
I get Mysql2 :: Error :: ConnectionError in the production environment
[Error] The app is not displayed in the production environment
Error in production environment (The asset "~" is not present in the asset pipeline.)
Create a database in a production environment
I want to display the images under assets/images in the production environment
[Rails] How to reset the database in production environment (Capistrano version)
The parameters I received in Rails were a bit different than I expected
[Rails] About the error that the image is not displayed in the production environment
Creating a Servlet in the Liberty environment
[Rails] Reset the database in the production environment
Display the background image in the production environment
[When using MiniMagick] A memorandum because I stumbled in the CircleCI test environment.
I get an error when adding a dependency
500 Internal Server Error occurs in Rails production environment
I want to get the value in Ruby
I stumbled when I tried using neo4j in the jenv environment, so make a note
[Rails] How to delete production environment MySQL data after putting it in the development environment
I have a question. I get an error when playing a video in Listview on android.
Migration error after Activerecord association in Rails5 + Docker environment (2)
Migration error after Activerecord association in Rails5 + Docker environment
Verification value error that occurred in a clustering environment
[Java] Get the file in the jar regardless of the environment
When I run docker-compose exec in crontab, I get "the input device is not a TTY"
I want to recreate the contents of assets from scratch in the environment built with capistrano
Get the next business day after the specified date in JAVA
Resolve CreateProcess error = 206 when running Java in a Windows environment
I was confused because there was a split in the Array
Easily monitor the indoor environment-⑦ Summarize in a simple tool-
After learning Progate, I tried to make an SNS application using Rails in the local environment