pm2 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

pm2 命令安装:


-bash/zsh: pm2: command not found

# Arch Linux
pacman -S pm2

# Npm
npm install pm2 -g

# Yarn
yarn global add pm2

# Debian
apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash -

# Dockerfile
dockerfile.run/pm2

# Update
npm install pm2 -g && pm2 update  

pm2 命令补充说明:


PM2 是一款免费的开源、先进、高效、跨平台的 Node.js 生产级流程管理器,具有内置负载均衡器。 它适用于 Linux、MacOS 和 Windows。 它支持应用程序监控、微服务 / 进程的高效管理、以集群模式运行应用程序、应用程序的优雅启动和关闭。

pm2 命令语法:


pm2 [options] [args ...]

pm2 命令选项:


# Start Process
pm2 start server.js

# OR set an application state with name --name or -n
pm2 start web.js --name "node-app-backend"

# Stop Process
pm2 stop node-app-backend

# Restart Process
pm2 restart node-app-backend

# Update Environment Variable
NODE_ENV=production pm2 restart node-app-backend --update-env

# Delete Process
pm2 delete node-app-backend

# List Processes
pm2 list

# Or
pm2 [list|ls|l|status]

# Detail Info about Process with ID
pm2 show 0

# Here 0 is process id
# Reset Restart Count - this will reset restart count
pm2 reset all

# Sort Processes
pm2 list --sort name:desc

OR

pm2 list --sort [name|id|pid|memory|cpu|status|uptime][:asc|desc]

# By default sorting field is name and sorting order is asc
# Watch and Restart app when files change
pm2 start server.js --watch

# Pass extra arguments to the script
pm2 start server.js -- arg1 arg2 arg3

# Delay between automatic restart of application
pm2 start server.js --restart-delay <delay in ms>

# Do not auto restart application
pm2 start server.js --no-autorestart

# Logging
pm2 logs
pm2 logs <app-name>

pm2 命令实例:


pm2 使用可用于后续操作的名称启动进程:

pm2 start app.js --name application_name

pm2 列出进程:

pm2 list

pm2 监控所有进程:

pm2 monit

pm2 停止一个进程:

pm2 stop application_name

pm2 重启应用进程:

pm2 restart application_name

pm2 转储所有进程以便稍后复活它们:

pm2 save

pm2 恢复以前转储的进程:

pm2 resurrect

pm2 命令扩展阅读:




pm2 命令评论

共收录到 487Linux 命令