# 啓動並監控名字爲 XXX 的 npm run start:dev 命令
pm2 start npm --watch --name XXX -- run start:dev
### 普通General
npm install pm2 -g # 安裝 PM2
pm2 start app.js # 啓動,守護進程,自動重啓應用程序 Start, Daemonize and auto-restart application (Node)
pm2 start app.py # 啓動,守護進程,自動重啓python應用程序 Start, Daemonize and auto-restart application (Python)
pm2 start npm -- start # 啓動,守護進程,自動重啓node應用程序 Start, Daemonize and auto-restart Node application
### 集羣模式 (只支持node進程) Cluster Mode (Node.js only)
pm2 start app.js -i 4 # 在集羣模式下,啓動4個應用程序實例 Start 4 instances of application in cluster mode
# 同時,將網絡請求,負載均衡到每一個應用實例 it will load balance network queries to each app
pm2 reload all # 0秒重啓全部應用 Zero Second Downtime Reload
pm2 scale [app-name] 10 # 將應用進程調整到10 Scale Cluster app to 10 process
### 進程監控 Scale Cluster app to 10 process
pm2 list # 列出全部用PM2啓動的進程 List all processes started with PM2
pm2 monit # 顯示每一個應用佔用的cpu和內存 Display memory and cpu usage of each app
pm2 show [app-name] # 顯示某個進程的全部信息 Show all informations about application
### 日誌管理 Log management
pm2 logs # 顯示全部應用的日誌 Display logs of all apps
pm2 logs [app-name] # 顯示某個應用的日誌 Display logs for a specific app
pm2 logs --json # json化日誌 Logs in JSON format
pm2 flush
pm2 reloadLogs
### 進程狀態管理 Process State Management
pm2 start app.js --name="api" # 啓動一個應用並命名爲api。 Start application and name it "api"
pm2 start app.js -- -a 34 # 啓動一個應用,並傳遞「-a 34」的參數。 Start app and pass option "-a 34" as argument
pm2 start app.js --watch # 重啓一個應用,當文件改變的時候。Restart application on file change
pm2 start script.sh # 啓動一個bash腳本。Start bash script
pm2 start app.json # 啓動在app.json中聲明的全部應用。Start all applications declared in app.json
### 你也能夠執行用其餘語言編寫的app ( fork 模式):
pm2 start bash.sh -x --interpreter bash
pm2 start python.py -x --interpreter python
pm2 reset [app-name] # 重置全部計數器。Reset all counters
pm2 stop all # 中止全部應用。Stop all apps
pm2 stop 0 # 中止id 爲0的應用。Stop process with id 0
pm2 restart all # 重啓全部應用。Restart all apps
pm2 gracefulReload all # 在集羣模式下,平穩的重加載全部應用。Graceful reload all apps in cluster mode
pm2 delete all # 殺掉全部應用。Kill and delete all apps
pm2 delete 0 # 殺掉id爲0的進程。Delete app with id 0
### 啓動/引導管理 Startup/Boot management
pm2 startup # 檢測init系統,在啓動時生成和配置pm2。Detect init system, generate and configure pm2 boot on startup
pm2 save # 保存當前進程列表。Save current process list
pm2 resurrect # 恢復之前保存的進程。Restore previously save processes
pm2 unstartup # 停用和刪除啓動系統。Disable and remove startup system
pm2 update # 保存進程,終止PM2並恢復進程。Save processes, kill PM2 and restore processes
pm2 generate # 生成樣本json配置文件。Generate a sample json configuration file
### 部署 Deployment
pm2 deploy app.json prod setup # 設置「生產環境」遠程服務器。 Setup "prod" remote server
pm2 deploy app.json prod # 更新「生產環境」遠程服務器。 Update "prod" remote server
pm2 deploy app.json prod revert 2 # 將「生產環境」遠程服務器恢復2。Revert "prod" remote server by 2
### 模塊系統 Module system
pm2 module:generate [name] # 生成名稱爲[name]的示例模塊。Generate sample module with name [name]
pm2 install pm2-logrotate # 安裝模塊(這裏是日誌循環系統)。Install module (here a log rotation system)
pm2 uninstall pm2-logrotate # 卸載模塊。Uninstall module
pm2 publish # 增量版本,git push和npm發佈。Increment version, git push and npm publish
擴展閱讀:
http://www.cnblogs.com/flyingeagle/p/9219376.html
https://www.douban.com/note/314200231/
http://www.javashuo.com/article/p-qhnvlzxq-kz.htmlhtml