nodejs pm2守護進程使用


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM