当前位置:网站首页>PM2 configuration file
PM2 configuration file
2022-08-09 11:45:00 【choukin】
There are three of the most harmful addictive substances in the world:海洛因、碳水化合物、Salary paid once a month.————《黑天鹅》Author Taleb
当使用PM2When managing multiple apps,可以使用 JS profiles to manage them.
生成配置文件
Use the command below to generate a simple configuration file:
pm2 init simple
会生成一个简单的 ecosystem.config.js:
module.exports = {
apps: [{
name:"app1",
script:"./app.js",
}]
}
If a custom configuration file is created,Make sure the filename is .config.js 结尾的,这样 PM2 It can be managed as a configuration file.
操作配置文件
compared to performing an action on an application,You can use the configuration file directly 启动/停止/重新启动/删除 All applications in the configuration file:
# 启动所有应用程序
pm2 start ecosystem.config.js
# 关闭所有应用
pm2 stop ecosystem.config.js
# 重启
pm2 restart ecosystem.config.js
# 重载
pm2 reload ecosystem.config.js
# 删除
pm2 delete ecosystem.config.js
Operates the specified process
可以使用--only <app_name>Operate a specific application:
pm2 start ecosystem.config.js --only api-app
注意:--only The choice can also be right start/restart/stop/delete 操作.
It can also be separated by commas,Operates multiple specific applications:
pm2 start ecosystem.config.js --only "api-app,worker-app"
切换环境
可以通过设置 env_* to set different environment variables:
module.exports = {
apps:[{
name:"app1",
script:"./app.js",
env_production:{
NODE_ENV:"production"
},
env_development:{
NODE_ENV:"development"
}
}]
}
可以通过 --env [env name] to switch environment variables:
pm2 start ecosystem.config.js --env production
pm2 restart ecosystem.config.js --env development
可用属性
The behavior and configuration of the application can be fine-tuned through the properties below:
常用
| 字段 | 类型 | 例子 | 描述 |
|---|---|---|---|
| name | string | "my-api" | 应用名称,The default is the script name excluding the suffix |
| script | string | "./api/app.js" | 相对于pm2的脚本路径 |
| cwd | string | "/var/www/" | The directory where the application is started |
| args | string | "-a 13 -b 12" | 包含所有的参数,These parameters can be passed to the script via the command line |
| interpreter | string | "/usr/bin/python" | 解释器的绝对路径,默认是nodejs的 |
| interpreter_args | string | "-harmony" | Arguments passed to the interpreter |
| node_args | string | Interpreter parameter aliases |
高级功能
| 字段 | 类型 | 例子 | 描述 |
|---|---|---|---|
| instances | number | -1 | The number of samples to start the application with |
| exec_mode | string | "cluster" | The mode in which to start the application,“cluster”/ "fork" 默认是 fork |
| watch | boolean / [] | true | Enables monitoring and restarting if the folder or files in the folder are changed,The program will reload |
| ignore_watch | [] | ["node_modules","[/\]./"] | A series of regular or folder names,Indicates the folder to ignore |
| max_mermory_restart | string | “150M” | If the application exceeds the specified memory,The application will restart. |
| env | object | {"NODE_ENV":"development","ID":"42"} | Environment variables used in the application |
| env_ | object | {"NODE_ENV":"production","ID":"89"} | 在pm2Injected when the app is restarted pm2 restart ecosystem.config.js -env |
| source_map_support | boolean | true | 默认是true[启用/禁用 source map 文件] |
| instance_var | string | "NODE_APP_INSTANCE" | |
| filter_env | 字符串数组 | ["REACT_"] | excluded"REACT_"开头的全局变量,They are not allowed to infiltrate the cluster |
日志文件
| 字段 | 类型 | 例子 | 描述 |
|---|---|---|---|
| log_date_format | string | 'YYYY-MM-DD HH:mm Z' | |
| erro_file | string | 错误日志文件 默认 $HOME/.pm2/logs/XXXerr.log | |
| out_file | string | 日志文件 默认 $HOME/.pm2/logs/XXXout.log | |
| combine_logs | boolean | true | 如果设置true,Avoid adding processes to log filesid后缀 |
| merge_logs | boolean | true | combine_logs 别名 |
| pid_file | string | 进程id文件路径 $HOME/.pm2/pid/app-pm_id.pid |
控制流
| 字段 | 类型 | 例子 | 描述 |
|---|---|---|---|
| min_updtime | string | Controls the minimum application startup time | |
| listen_timeout | number | 8000 | The timeout if the application is not being listened to,If it exceeds it will reload 毫秒 |
| kill_timeout | number | 1600 | 发送killnumber of milliseconds before |
| shutdown_with_message | nubmer | false | 用process.send('shutdown')而不是process.kill(pid, SIGINT) to close the application |
| wait_ready | boolean | false | 等待process.send('ready')instead of waiting for the reload event |
| max_restarts | number | 10 | Before the app is considered an error and stops restarting,The number of consecutive unstable restarts(Less than one second interval or passmin_uptimecustom time) |
| restart_delay | number | 4000 | Default wait time before restarting a crashed app0 |
| autorestart | boolean | false | 默认true,如果设置false,PM2 No restart on app crash or calm end |
| cron_restart | string | “1 0 * * *” | Restart the application cron表达式, 应用必须在cronfunction is available |
| vizion | boolean | false | 默认true,如果false PM2 Not included after startupvizion功能(Control metadata version) |
| post_update | list | ["npm install", "echo launching the app"] | 从KeymetricsDashboard executionpull/upgrade A series of commands to execute during operation |
| force | boolean | true | 默认false,如果设置为true,The same script can be launched multiple times,这通常是PM2 不允许的. |
部署
| 字段 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| key | SSH key 路径 | stirng | $HOME/.ssh |
| user | SSH 用户名 | string | |
| host | SSH HOST | [stirng] | |
| ssh_options | without command line flagsSSH选项,参阅 man ssh | Stirng / [String] | |
| ref | GIT 远程分支 remote/branch | String | |
| repo | GIT 远程仓库 | String | |
| path | 服务器路径 | ||
| pre-setup | command before installation,or local script path | String | |
| post-setup | 安装后的命令,Or the server script path | String | |
| pre-deploy-local | Actions before deployment | String | |
| post-deploy | Post-deployment actions | String |
边栏推荐
- MySQL执行sql语句的机制
- [现代控制理论]6_稳定性_李雅普诺夫_Lyapunov
- 阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
- ACM01 Backpack problem
- The use of C language typedef 】 : structure, basic data types, and array
- 【面试高频题】可逐步优化的链表高频题
- Ways to prevent data fraud
- 元宇宙:下一代互联网启程(附元宇宙深度报告PDF)
- [Essence] Analysis of the special case of C language structure: structure pointer / basic data type pointer, pointing to other structures
- x86 Exception Handling and Interrupt Mechanism (3) Interrupt Handling Process
猜你喜欢

enum in c language

抗积分饱和 PID代码实现,matlab仿真实现
How tall is the B+ tree of the MySQL index?

x86 Exception Handling and Interrupt Mechanism (1) Overview of the source and handling of interrupts

Redis的下载安装

JS 封装节流(后期优化)

【精华文】C语言结构体特殊情况分析:结构体指针 / 基本数据类型指针,指向其他结构体

wpf path xaml写法和c#写法对比

mysql + redis + flask + flask-sqlalchemy + flask-session 配置及项目打包移植部署

【面试高频题】可逐步优化的链表高频题
随机推荐
元宇宙:下一代互联网启程(附元宇宙深度报告PDF)
PAT 1015 进制转换
fidder为什么不会抓包的问题
【C language】typedef的使用:结构体、基本数据类型、数组
Win10调整磁盘存储空间详解
wpf path xaml写法和c#写法对比
预置第三方apk到MTK项目相关问题总结
【VQA survey】视觉问答中的语言学问题
ClickHouse物化视图(八)
使用gdb调试多进程程序、同时调试父进程和子进程
x86 Exception Handling and Interrupt Mechanism (3) Interrupt Handling Process
The use of signal function (signal) in C language
学生成绩查找系统
The use of gdb tui
Redis的下载安装
[现代控制理论]6_稳定性_李雅普诺夫_Lyapunov
Fapi_StatusType Fapi_issueProgrammingCommand使用注意事项
MySQL执行sql语句的机制
抗积分饱和 PID代码实现,matlab仿真实现
x86 exception handling and interrupt mechanism (2) interrupt vector table