I'm deploying a Rails app on EC2 and using Unicorn as my application server.
If it was a development environment, I should have started it with rails s
, but in the production environment, the method of starting and stopping the server has changed, so I summarized it as a memo.
ps -ef | grep unicorn | grep -v grep
vinaka 15533 1 0 08:02 ? 00:00:01 unicorn_rails master -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
vinaka 15537 15533 0 08:03 ? 00:00:00 unicorn_rails worker[0] -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
vinaka 15538 15533 0 08:03 ? 00:00:00 unicorn_rails worker[1] -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
Of master, worker [0], worker [1]
If you see three, it seems that Unicorn is running.
The top number of the three I just confirmed(master)15533
Tokill
(The number changes every time, so every timeps -ef | grep unicorn | grep -v grepで番号To確認)
kill -9 15533
ps -ef | grep unicorn | grep -v grep
Then nothing should be displayed. If it is not displayed, Unicorn is stopped.
ps -ef | grep unicorn | grep -v grep
bundle exec unicorn_rails -c /var/www/rails/app name/config/unicorn.conf.rb -D -E production
If nothing comes out, it seems to be running properly.
I will confirm it for the time being.
ps -ef | grep unicorn | grep -v grep
vinaka 15740 1 1 08:48 ? 00:00:01 unicorn_rails master -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
vinaka 15744 15740 0 08:48 ? 00:00:00 unicorn_rails worker[0] -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
vinaka 15745 15740 0 08:48 ? 00:00:00 unicorn_rails worker[1] -c /var/www/rails/ShitsumonWa-/config/unicorn.conf.rb -D -E production
Three are displayed! It has been started. The number should have changed a while ago!
** By the way **
master failed to start, check stderr log for details
If you get an error
cat log/unicorn.log
Check the content of the error with.
Unicorn version (It seems that an error will occur if it is 5.5 or higher, so it is better to specify the version with Gem file
.)
Gemfile
group :production, :staging do
gem 'unicorn', '5.4.1'
end
Also
unicorn_rails -c /var/www/rails/app name/config/unicorn.conf.rb -D -E production
It may get angry, so it is safer to add bundle exec
.
bundle exec unicorn_rails -c /var/www/rails/app name/config/unicorn.conf.rb -D -E production
When `ʻUnicorn`` starts up safely, restart nginx and you're done.
sudo nginx -s reload
It's the end.
Recommended Posts