可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
可通过 NPM 或 Yarn 安装最新版 PM2
$ npm install pm2@latest -g
或
$ yarn global add pm2
启动、守护并监控应用最简单的方式如下
$ 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 强制执行d restart
--cron <cron_pattern>
Attach to application log
--no-daemon
Managing application state is simple here are the commands
$ pm2 restart app_name
$ pm2 reload app_name
$ pm2 stop app_name
$ pm2 delete app_name
all to act on all processesid to act on a specific process idNow that you have started this application, you can check its status, logs, metrics and even get the online dashboard with pm2.io.
List the status of all application managed by PM2
$ pm2 [list|ls|status]
To display logs in realtime
$ pm2 logs
To dig in older logs
$ pm2 logs --lines 200
Here is a realtime dashboard that fits directly into your terminal
$ pm2 monit
Web based dashboard, cross servers with diagnostic system
$ pm2 plus
For Node.js applications, PM2 includes an automatic load balancer that will share all HTTP[s]/Websocket/TCP/UDP connections between each spawned processes.
To start an application in Cluster mode
$ pm2 start app.js -i max
Read more about cluster mode here.
You can also create a configuration file, called Ecosystem File, to manage multiple applications. To generate an Ecosystem file
$ pm2 ecosystem
This will generate an ecosystem.config.js file
module.exports = {
apps : [{
name: "app",
script: "./app.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}, {
name: 'worker',
script: 'worker.js'
}]
}
And start it easily
$ pm2 start ecosystem.config.js
Read more about application declaration here
Restarting PM2 with the processes you manage on server boot/reboot is critical. To solve this, just run this command to generate an active startup script
$ pm2 save
Read more about startup script generator here
It’s pretty easy with the --watch option
$ cd /path/to/my/app
$ pm2 start env.js --watch --ignore-watch="node_modules"
This will watch & restart the app on any file change from the current directory + all subfolders and it will ignore any
changes in the node_modules folder --ignore-watch="node_modules".
You can then use pm2 logs to check for restarted app logs.
以下是一些值得记住的常用命令。可在示例应用或本机开发中的 Web 应用上直接试用
Fork 模式
$ pm2 start app.js --name my-api # Name process
集群模式
$ pm2 start app.js -i 0 # 将根据可用 CPU 启动最大进程数并进行负载均衡
$ pm2 start app.js -i max # 与上面相同,但已弃用
$ pm2 scale app +3 # 将 `app` 扩展 3 个工作进程
$ pm2 scale app 2 # 将 `app` 扩展或缩减到总共 2 个工作进程
列表
$ pm2 list # 显示所有进程状态
$ pm2 jlist # 以原始 JSON 格式打印进程列表
$ pm2 prettylist # 以美化 JSON 格式打印进程列表
$ pm2 describe 0 # 显示关于特定进程的所有信息
$ pm2 monit # 监控所有进程
日志
$ pm2 logs [--raw] # 以流式传输显示所有进程日志
$ pm2 flush # 清空所有日志文件
$ pm2 reload日志 # 重新加载所有日志
操作
$ pm2 stop all # 停止所有进程
$ pm2 restart all # 重启所有进程
$ pm2 reload all # 将进行 0 秒停机重载(针对网络应用)
$ pm2 stop 0 # 停止特定进程 ID
$ pm2 restart 0 # 重启特定进程 ID
$ pm2 delete 0 # 将从 PM2 列表中删除进程
$ pm2 delete all # 将从 PM2 列表中删除所有进程
其他
$ pm2 reset <process> # 重置元数据(重启时间等)
$ pm2 updatePM2 # 更新内存中的 PM2
$ pm2 ping # 确保 PM2 守护进程已启动
$ pm2 sendSignal SIGUSR2 my-app # 向脚本发送系统信号
$ pm2 start app.js --no-daemon
$ pm2 start app.js --no-vizion
$ pm2 start app.js --no-autorestart
我们使其简单,版本之间没有破坏性更改,过程很简单
$ npm install pm2@latest -g
然后更新内存中的 PM2
$ pm2 update