nodejs-doc-pm2

安装

1
npm  install -g pm2

命令

命令 描述
pm2 list 显示所有进程状态
pm2 monit 监视所有进程
pm2 logs 显示所有进程日志
pm2 stop all 停止所有进程
pm2 restart all 重启所有进程
pm2 reload all 0秒停机重载进程 (用于 NETWORKED 进程)
pm2 stop id 停止指定的进程
pm2 restart id 重启指定的进程
pm2 startup 产生 init 脚本 保持进程活着
pm2 web 运行健壮的 computer API endpoint (http://localhost:9615)
pm2 delete id 杀死指定的进程
pm2 delete all 杀死全部进程
pm2 desc id 查看指定id进程详情
pm2 info id 查看指定id进程详情

选项

选项 描述
-h, --help output usage information
-V, --version output the version number
-v --version get version
-s --silent hide all messages
-m --mini-list display a compacted list without formatting
-f --force force actions
-n --name <name> set a for script
-i --instances <number> launch [number] instances (for networked app)(load balanced)
-l --log [path] specify entire log file (error and out are both included)
-o --output <path> specify out log file
-e --error <path> specify error log file
-p --pid <pid> specify pid file
--max-memory-restart <memory> specify max memory amount used to autorestart (in megaoctets)
--env <environment_name> specify environment to get specific env variables (for JSON declaration)
-x --execute-command execute a program using fork system
-u --user <username> define user when generating startup script
-c --cron <cron_pattern> restart a running process based on a cron pattern
-w --write write configuration in local folder
--interpreter <interpreter> the interpreter pm2 should use for executing app (bash, python…)
--log-date-format <momentjs format> add custom prefix timestamp to logs
--no-daemon run pm2 daemon in the foreground if it doesn’t exist already
--merge-logs merge logs from different instances but keep error and out separated
--watch watch application folder for changes
--ignore-watch <folders|files> folder/files to be ignored watching, chould be a specific name or regex - e.g. –ignore-watch=”test node_modules “some scripts””
--node-args <node_args> space delimited arguments to pass to node in cluster mode - e.g. –node-args=”–debug=7001 –trace-deprecation”
--no-color skip colors
--no-vizion skip vizion features (versioning control)
--no-autorestart do not automatically restart apps

参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 根据有效CPU数目启动最大进程数目运行js程序
pm2 start app.js -i max

# 启动3个进程运行js程序
pm2 start app.js -i 3

#用fork模式启动 app.js 而不是使用 cluster 并且传递参数 (-a 123)
pm2 start app.js -x -- -a 123

# 启动一个进程并把它命名为 aa
pm2 start app.js --name aa

# 运行一次sh 脚本
pm2 start scrip.sh -x --interpreter bash --no-autorestart

# 运行py 脚本
pm2 start scrip.py -x --interpreter python