LoginSignup
1
0

More than 3 years have passed since last update.

AWS Railsの再起動手順

Posted at

この度Railsで開発中のアプリをAWSへ開発中アプリをデプロイしましたが、
今後本番環境のサーバー再起動を行う頻度は高いだろうと思い
備忘録としてUnicornの再起動手順をまとめていきたいと思います。

EC2インスタンスにログインしている前提で進めていきます。

まずは ps aux | grep unicorn コマンドでプロセスIDを確認します。

ターミナル
[ec2-user@ip-172-31-33-238 <対象リポジトリ>]$ ps aux | grep unicorn
ec2-user 26995 17.4 10.7 475732 108272 ?       Sl   13:55   0:01 unicorn_rails master -c config/unicorn.rb -E production -D
ec2-user 26999  0.0 10.0 476748 101508 ?       Sl   13:55   0:00 unicorn_rails worker[0] -c config/unicorn.rb -E production -D
ec2-user 27002  0.0  0.0 119436   908 pts/0    S+   13:55   0:00 grep --color=auto unicorn

この時 unicorn_rails master と表示されているプロセスが Unicorn のプロセスとなっているので、今回の場合は 26995 がPIDとなります。

PIDが確認できたら killコマンドを使ってプロセスを止めます。

ターミナル
[ec2-user@ip-172-31-33-238 <対象リポジトリ>]$ kill 26995

ps aux | grep unicornコマンドで実際に止まっているのか確認します。

ターミナル
[ec2-user@ip-172-31-33-238 <対象リポジトリ>]$ ps aux | grep unicorn
ec2-user 27345  0.0  0.0 119436   964 pts/0    S+   14:27   0:00 grep --color=auto unicorn

上記のような表示になっていればプロセスは止まっています。

確認が取れたら下記コマンドを入力しUnicornを起動させます。

ターミナル
[ec2-user@ip-172-31-23-189 <対象リポジトリ>]$ RAILS_SERVE_STATIC_FILES=1 unicorn_rails -c config/unicorn.rb -E production -D

以上で再起動は完了しました。

EC2インスタンスに紐付けたElasticIPを使ってブラウザにアクセスすると、正常に表示されているか確認ができます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0