befly-tpl 3.4.13 → 3.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SYSTEMD_DEPLOY.md CHANGED
@@ -138,19 +138,15 @@ sudo systemctl restart befly
138
138
 
139
139
  ## 配置说明
140
140
 
141
- ### 集群模式选择
141
+ ### 单进程模式
142
142
 
143
143
  ```ini
144
- # 选项1:单进程模式(适合小型应用)
144
+ # Systemd 推荐单进程模式
145
145
  ExecStart=/usr/local/bin/bun run befly start
146
-
147
- # 选项2:自动集群模式(推荐,使用所有CPU核心)
148
- ExecStart=/usr/local/bin/bun run befly start --cluster max
149
-
150
- # 选项3:指定进程数(如4个进程)
151
- ExecStart=/usr/local/bin/bun run befly start --cluster 4
152
146
  ```
153
147
 
148
+ **集群部署推荐使用 PM2**:Systemd 适合单进程部署,如需集群模式请使用 PM2(参见项目根目录的 PM2 相关文档)
149
+
154
150
  ### 用户和权限
155
151
 
156
152
  ```bash
@@ -193,18 +189,9 @@ EnvironmentFile=/var/www/befly/.env.production
193
189
 
194
190
  ### Nginx 配置示例
195
191
 
196
- ```nginx
197
- upstream befly_cluster {
198
- # 集群模式下配置多个端口
199
- server 127.0.0.1:3000;
200
- server 127.0.0.1:3001;
201
- server 127.0.0.1:3002;
202
- server 127.0.0.1:3003;
203
-
204
- # 负载均衡策略
205
- least_conn; # 最少连接
206
- }
192
+ #### 单进程模式
207
193
 
194
+ ```nginx
208
195
  server {
209
196
  listen 80;
210
197
  server_name yourdomain.com;
@@ -215,7 +202,7 @@ server {
215
202
  # ssl_certificate_key /path/to/key.pem;
216
203
 
217
204
  location / {
218
- proxy_pass http://befly_cluster;
205
+ proxy_pass http://127.0.0.1:3000;
219
206
  proxy_http_version 1.1;
220
207
 
221
208
  # WebSocket 支持
@@ -306,7 +293,7 @@ sudo systemd-analyze verify /etc/systemd/system/befly.service
306
293
 
307
294
  # 测试启动命令
308
295
  cd /var/www/befly
309
- sudo -u www-data bun run befly start --cluster max
296
+ sudo -u www-data bun run befly start
310
297
  ```
311
298
 
312
299
  ### 权限问题
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly-tpl",
3
- "version": "3.4.13",
3
+ "version": "3.4.15",
4
4
  "description": "Befly 3.0 TypeScript Template",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -10,8 +10,7 @@
10
10
  "scripts": {
11
11
  "dev": "bun run --env-file=.env.development main.ts",
12
12
  "start": "bun run --env-file=.env.production main.ts",
13
- "pm2:start": "pm2 start pm2.config.js --env production",
14
- "pm2:dev": "pm2 start pm2.config.js --env development",
13
+ "pm2": "pm2 start pm2.config.cjs",
15
14
  "sync:dev": "NODE_ENV=development befly sync",
16
15
  "sync:prod": "NODE_ENV=production befly sync"
17
16
  },
@@ -32,10 +31,10 @@
32
31
  ],
33
32
  "type": "module",
34
33
  "dependencies": {
35
- "befly": "^3.4.12"
34
+ "befly": "^3.4.14"
36
35
  },
37
36
  "engines": {
38
37
  "bun": ">=1.3.0"
39
38
  },
40
- "gitHead": "7d2c21a0b69867c650cbec930e041821a1914ffb"
39
+ "gitHead": "8ced9f183b280460e8136eb00985c0fb83e63bc1"
41
40
  }
package/pm2.config.cjs ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * PM2 进程管理配置文件(CommonJS 格式)
3
+ * 使用 Bun 的 --env-file 参数显式指定环境变量文件
4
+ *
5
+ * 使用方法:
6
+ * 1. 启动:pm2 start pm2.config.cjs
7
+ * 2. 查看状态:pm2 status
8
+ * 3. 查看日志:pm2 logs befly
9
+ * 4. 重启:pm2 restart befly
10
+ * 5. 停止:pm2 stop befly
11
+ * 6. 删除:pm2 delete befly
12
+ * 7. 保存配置:pm2 save
13
+ * 8. 开机自启:pm2 startup
14
+ *
15
+ * 环境变量加载:
16
+ * - 默认使用生产环境:--env-file=.env.production
17
+ *
18
+ * 注意:PM2 配置文件必须使用 CommonJS 格式(.cjs),不支持 ESM
19
+ */
20
+
21
+ module.exports = {
22
+ apps: [
23
+ {
24
+ name: 'befly',
25
+ script: './main.ts',
26
+ interpreter: 'bun',
27
+ interpreter_args: '--env-file=.env.production',
28
+
29
+ // 集群模式配置
30
+ instances: 4, // 实例数量,可设置为 'max' 使用所有 CPU
31
+ exec_mode: 'cluster', // 集群模式
32
+
33
+ // 自动重启配置
34
+ autorestart: true,
35
+ watch: false,
36
+ max_memory_restart: '1G', // 内存超过 1G 自动重启
37
+
38
+ // 日志配置
39
+ error_file: './logs/pm2-error.log',
40
+ out_file: './logs/pm2-out.log',
41
+ log_date_format: 'YYYY-MM-DD HH:mm:ss',
42
+ merge_logs: true
43
+ }
44
+ ]
45
+ };