LoginSignup
19

More than 5 years have passed since last update.

initd-foreverでnodeプロセスを自動起動する

Posted at

環境

  • EC2(Amazon Linux)

インストール

  • initd-foreverインストール
# npm install -g forever initd-forever 
# npm install -g log
  • 起動スクリプトの生成(nodeのエントリーポイントがあるディレクトリで、起動スクリプトの雛形を作成)
# initd-forever -n hoge(サービス名)
Script daemon file saved to hoge
# chmod +x hoge
# mv hoge /etc/init.d
  • エントリーポイントになるスクリプトの指定
/etc/init.d/hoge
nodeApp="/home/hoge/"nodeApp="/home/hoge/server.js"
  • サービスの有効化
# chkconfig hoge --add
# chkconfig hoge on
# chkconfig hoge --list
# service hoge start
  • サーバーを再起動して、自動起動されるかを確認する

Tips

foreverコマンド

  • プロセス一覧確認
# forever list
  • ログ確認
# forever log

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
19