LoginSignup
38
34

More than 5 years have passed since last update.

PM2をサービスに登録してnodejsサーバーの自動起動をする(centos6.x)

Last updated at Posted at 2013-12-19

とりあえず再起動時に自動起動させたい人向けの記事です

PM2をインストールする

sudo npm install pm2 -g

initスクリプトの作成とサービスの登録をする

sudo pm2 startup centos

(このコマンドを実行すると/etc/init.d/pm2-init.shが作成され各runlevelにリンクが張られる)

PM2にスクリプトを登録して状態を保存する

sudo pm2 start app.js

確認

再起動して自動起動しているか確認する

reboot
-----
pm2 list

以下のログが出て起動しなかったなら

/var/log/boot.log
sudo: sorry, you must have a tty to run sudo

sudoの設定を変更する

visudo
# ↓をコメントアウトする
Defaults    requiretty
38
34
2

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
38
34