LoginSignup
8
10

More than 5 years have passed since last update.

PM2で自作アプリをデーモン化する(Raspberry Pi)

Last updated at Posted at 2015-11-21

環境

Raspberry Pi 2 MODEL B URL
Raspbian GNU/Linux 7 (wheezy) URL
Node.js v5.0.0

インストール

npm install -g pm2

基本コマンド

$ pm2 start app.js --name my-api # Name process
$ pm2 list               # Display all processes status
$ pm2 stop 0             # Stop specific process id
$ pm2 restart 0          # Restart specific process id
$ pm2 delete 0           # Will remove process from pm2 list

pm2自身をデーモン化

pm2 statupコマンドで起動スクリプトが作られるのですが、同時に
環境変数PM2_HOMEとユーザを渡した方が楽出来ます。

(直接起動スクリプトを編集してもOK)

sudo env PM2_HOME=/home/pi/.pm2/ pm2 startup -u pi

/etc/init.d/pm2-init.shが作られます。これに実行権限を与えます。

sudo su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"

自作アプリのデーモン登録

pm2 start myapp.js

同様のソフトウェアではPythonベースのSupervisordが知られていますが、それと比較してもコマンドベースで設定を追加できたり使いやすい感じがします。

まだまだ高機能っぽいので理解次第追記します。

8
10
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
8
10