ソースコードから理解する技術-UnderSourceCode

手を動かす(プログラムを組む)ことで技術を理解するブログ

Nginx、Unicornにてapplication.rbの変更を反映する

タイトル通りのことをするために自分が行った操作を
メモとして書いておきます。

具体的には、Nginx、Unicornをそれぞれ再起動しました。
(プライベートのアプリだから許されるかも。24時間稼動のシステムでは・・・?)

■Nginxの再起動
以下のコマンドを実行する。
$ /etc/init.d/nginx restart


Unicornの再起動(ついでに開始、終了も)
Unicornをデーモンとして起動している場合
プロセスの再起動を行う。

1.UnicornのプロセスIDを取得する。
$ ps -ef | grep unicorn | grep -v grep
以下のような感じで、プロセスが取得できる。

user      1912 29572  0 01:17 ?        00:00:07 unicorn worker[0] -c config/unicorn.conf -D                                                                           
user 1915 29572 0 01:17 ? 00:00:09 unicorn worker[1] -c config/unicorn.conf -D
user 29572 1 0 Nov16 ? 00:00:02 unicorn master -c config/unicorn.conf -D

2.masterプロセスの再起動
masterのプロセスID(上記の例では29572)を指定し、プロセスを再起動する。
$ kill -HUP masterのプロセスID

3.プロセスの終了
$ kill -QUIT masterのプロセスID

4.Unicornの起動
アプリケーションのrootフォルダに移動し、以下のコマンドを実行する。
$ unicorn -c config/unicorn.conf -D
(config/unicorn.conf は、unicornの定義ファイルのパス)

※productionモードの場合は、-E productionを追加する。

以上です。