概述
官网 PM2 is a process manager. It manages your applications states, so you can start, stop, restart and delete processes. 进入项目根目录 Or start any other application easily: As you can see many options are available to manage your application with PM2. You will discover them depending on your use case. Managing application state is simple here are the commands Instead of List the status of all application managed by PM2 To display logs in realtime: To dig in older logs: Here is a realtime dashboard that fits directly into your terminal: Here are some commands that are worth knowing. Just try them with a sample application or with your current web application on your development machine:安装pm2
pm2需要全局安装
cnpm install pm2@latest -g
使用
Start an app
pm2 start app.js
pm2 start bashscript.sh
pm2 start python-app.py --watch
pm2 start binary-file -- --port 1520
--name <app_name>
:Specify an app name--watch
:Watch and Restart app when files change--max-memory-restart <200MB>
:Set memory threshold for app reload--log <log_path>
:Specify log file-- arg1 arg2 arg3
:Pass extra arguments to the script--restart-delay <delay in ms>
:Delay between automatic restarts--time
:Prefix logs with time--no-autorestart
:Do not auto restart app--cron <cron_pattern>
:Specify cron for forced restart--no-daemon
:Attach to application logManaging processes
pm2 restart app_name
pm2 reload app_name
pm2 stop app_name
pm2 delete app_name
app_name
you can pass:all
to act on all processesid
to act on a specific process idCheck status, logs, metrics
List managed applications
pm2 [list|ls|status]
Display logs
pm2 logs
pm2 logs --lines 200
Terminal Based Dashboard
pm2 monit
pm2.io: Monitoring & Diagnostic Web Interface
pm2 plus
Updating PM2
pm2 update
CheatSheet
# Fork mode
pm2 start app.js --name my-api # Name process
# Cluster mode
pm2 start app.js -i 0 # Will start maximum processes with LB depending on available CPUs
pm2 start app.js -i max # Same as above, but deprecated.
pm2 scale app +3 # Scales `app` up by 3 workers
pm2 scale app 2 # Scales `app` up or down to 2 workers total
# Listing
pm2 list # Display all processes status
pm2 jlist # Print process list in raw JSON
pm2 prettylist # Print process list in beautified JSON
pm2 describe 0 # Display all informations about a specific process
pm2 monit # Monitor all processes
# Logs
pm2 logs [--raw] # Display all processes logs in streaming
pm2 flush # Empty all log files
pm2 reloadLogs # Reload all logs
# Actions
pm2 stop all # Stop all processes
pm2 restart all # Restart all processes
pm2 reload all # Will 0s downtime reload (for NETWORKED apps)
pm2 stop 0 # Stop specific process id
pm2 restart 0 # Restart specific process id
pm2 delete 0 # Will remove process from pm2 list
pm2 delete all # Will remove all processes from pm2 list
# Misc
pm2 reset <process> # Reset meta data (restarted time...)
pm2 updatePM2 # Update in memory pm2
pm2 ping # Ensure pm2 daemon has been launched
pm2 sendSignal SIGUSR2 my-app # Send system signal to script
pm2 start app.js --no-daemon
pm2 start app.js --no-vizion
pm2 start app.js --no-autorestart
最后
以上就是复杂导师为你收集整理的使用 pm2 管理 node等 服务安装pm2使用Updating PM2CheatSheet的全部内容,希望文章能够帮你解决使用 pm2 管理 node等 服务安装pm2使用Updating PM2CheatSheet所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复