pm2是一個守護進程管理器,它可以幫助你保持應用一直online.
安裝
$ npm install pm2@latest -g # or $ yarn global add pm2
Quick Start
最簡單的方式啟動、守護、監視你的應用的方法:
$ pm2 start app.js
或者啟動其他類型的應用:
$ pm2 start bashscript.sh $ pm2 start python-app.py --watch $ pm2 start binary-file -- --port 1520
一些其他的選項:
# Specify an app name --name <app_name> # Watch and Restart app when files change --watch # Set memory threshold for app reload --max-memory-restart <200MB> # Specify log file --log <log_path> # Pass extra arguments to the script -- arg1 arg2 arg3 # Delay between automatic restarts --restart-delay <delay in ms> # Prefix logs with time --time # Do not auto restart app --no-autorestart # Specify cron for forced restart --cron <cron_pattern> # Attach to application log --no-daemon
管理進程
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
檢查狀態和日志
列出所有pm2管理的進程:
$ pm2 [list|ls|status]

打印日志:
$ pm2 logs $ pm2 logs --lines 200
pm2.io: 一個Web interface
$ pm2 plus

參考鏈接:https://pm2.keymetrics.io/docs/usage/quick-start/#welcome
