Skip to content

Commit

Permalink
fix: 修正pm2相关问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CakmLexi committed Jun 17, 2024
1 parent f39dd21 commit 5b1b913
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/defSet/pm2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apps:
- name: "Karin"
# 入口
script: "./index.js"
script: "./lib/index.js"
# 进程守护
autorestart: true
# 每分钟最大重启数量
Expand Down
9 changes: 9 additions & 0 deletions lib/db/level.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export default class LevelDB extends Level {
return null
}
}

/**
* 增加set方法
* @param {string} key 键
* @param {object|string} value 值
*/
async set (key, value, ...args) {
return await super.put(key, value, ...args)
}
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import Notice from './event/notice.js'
import Request from './event/request.js'
import Online from './core/online.js'

export const common = new Common()
export const config = new Config()
export const segment = new Segment()
export const button = new Button()
Expand All @@ -47,6 +46,7 @@ const isDev = process.env.KarinMode === 'dev' ? '[开发模式]' : '[生产模
* 日志模块初始化
*/
export const logger = new Logger().config(config).logger()
export const common = new Common(logger, segment)

/**
* 全局变量
Expand Down
14 changes: 14 additions & 0 deletions lib/tools/pm2Log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'fs'
import yaml from 'yaml'
import path from 'path'
import { fileURLToPath } from 'url'
import { spawn } from 'child_process'

const dir = path.resolve(fileURLToPath(import.meta.url), '../../..')
const _path = path.resolve(dir + '/config/config/pm2.yaml')
const data = yaml.parse(fs.readFileSync(_path, 'utf8'))

const name = data.apps[0].name
const lines = data.lines || 1000
const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2'
spawn(cmd, ['logs', '--lines', lines, name], { stdio: 'inherit', shell: true, cwd: dir })
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"init": "node lib/tools/install.js",
"init:dev": "node lib/tools/install.js",
"init:pack": "node lib/tools/install.js",
"log": "pm2 logs ./config/config/pm2.yaml",
"log": "node lib/tools/pm2Log.js",
"monit": "pm2 monit",
"restart": "pm2 restart ./config/config/pm2.yaml",
"sort:pack": "npx sort-package-json",
Expand Down

0 comments on commit 5b1b913

Please sign in to comment.