LoginSignup
15
15

More than 5 years have passed since last update.

node.jsでサーバーを落とさずにデプロイする(naught編)

Last updated at Posted at 2015-03-13

モジュールのインストール

naughtというプロセス管理モジュールを使用するとサーバーを落とさずにデプロイすることが可能になります。
https://github.com/andrewrk/naught

グローバルでインストール
$ sudo npm install -g naught

nodeサーバー用jsファイルを編集

naughtにworkerの開始と終了の通知を判別できるようにするために、サーバー用jsファイルのlistenを下記のように編集します。

app.js
// Start server
server.listen(config.port, config.ip, function() {
  // Send online to naught
  if (process.send) {
    process.send('online');
  }
  console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
});

// Send shutdown to naught
process.on('message', function(message) {
  if (message === 'shutdown') {
    process.exit(0);
  }
});

サーバーをworker化して起動

naught start [サーバー用js] でworkerを起動します。

$ sudo naught start app.js
Bootup. booting: 0, online: 0, dying: 0, new_online: 0
SpawnNew. booting: 1, online: 0, dying: 0, new_online: 0
NewOnline. booting: 0, online: 0, dying: 0, new_online: 1
workers online: 1

--daemon-mode オプションでdaemonとして起動するか指定できます。
(デフォルト: true)

--worker-count のオプションを付与するとworker数を指定できます。
(デフォルト: 0)

サーバーを停止

停止はstopで

$ sudo naught stop
ShutdownOld. booting: 0, online: 0, dying: 1, new_online: 0
OldExit. booting: 0, online: 0, dying: 0, new_online: 0

--timeout オプションでセッションの強制タイムアウト時間を指定できます。
(デフォルト: none)

デプロイ

deployコマンドでworkerの停止と再起動を行います。

$ sudo naught deploy
SpawnNew. booting: 1, online: 1, dying: 0, new_online: 0
NewOnline. booting: 0, online: 1, dying: 0, new_online: 1
ShutdownOld. booting: 0, online: 0, dying: 1, new_online: 1
OldExit. booting: 0, online: 0, dying: 0, new_online: 1
done

--timeout オプションでセッションの強制タイムアウト時間を指定できます。
(デフォルトはnone)

15
15
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
15
15