diff --git a/shell/update.sh b/shell/update.sh index cdd6a6dc..c78191f5 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -211,6 +211,11 @@ run_extra_shell() { fi } +## 查看青龙服务日志 +show_service_logs() { + pm2 logs qinglong "$@" +} + ## 脚本用法 usage() { t "$cmd_update 命令使用方法:" @@ -221,10 +226,11 @@ usage() { echo -e "5. $cmd_update rmlog # 删除旧日志" echo -e "6. $cmd_update bot # 启动tg-bot" echo -e "7. $cmd_update check # 检测青龙环境并修复" - echo -e "8. $cmd_update resetlet # 重置登录错误次数" - echo -e "9. $cmd_update resettfa # 禁用两步登录" - echo -e "10. $cmd_update resetpwd # 修改登录密码" - echo -e "11. $cmd_update resetname # 修改登录用户名" + echo -e "8. $cmd_update log [pm2-log-options] # 查看青龙服务日志" + echo -e "9. $cmd_update resetlet # 重置登录错误次数" + echo -e "10. $cmd_update resettfa # 禁用两步登录" + echo -e "11. $cmd_update resetpwd # 修改登录密码" + echo -e "12. $cmd_update resetname # 修改登录用户名" } reload_qinglong() { @@ -471,6 +477,12 @@ main() { local p8="${8}" local p9="${9}" local p10="${10}" + + if [[ "$p1" == "log" ]]; then + show_service_logs "${@:2}" + return $? + fi + local log_dir="${p1}" make_dir "$dir_log/$log_dir" local log_time=$(date "+%Y-%m-%d-%H-%M-%S") diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 42103041..ec5a7127 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -2,7 +2,7 @@ "1. 宿主机执行 docker run --rm -v\n /var/run/docker.sock:/var/run/docker.sock\n containrrr/watchtower -cR <容器名>": "1. Execute 'docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR ' on the host machine", "2. 容器内执行 ql check、ql update": "2. Execute 'ql check' and 'ql update' inside the container", "24小时未运行": "Idle 24h+", - "3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果": "3. If the problem persists, execute 'pm2 logs' inside the container and copy the results", + "3. 如果无法解决,容器内执行 ql log,拷贝执行结果": "3. If the problem persists, execute 'ql log' inside the container and copy the results", "6位数字": "6-digit number", "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK push icon, custom push icon (requires iOS 15 or above to display)", "BARK推送消息的分组,默认为qinglong": "BARK push message grouping, default is qinglong", diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 244333db..ae12cf39 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -2,7 +2,7 @@ "1. 宿主机执行 docker run --rm -v\n /var/run/docker.sock:/var/run/docker.sock\n containrrr/watchtower -cR <容器名>": "1. 宿主机执行 docker run --rm -v\n /var/run/docker.sock:/var/run/docker.sock\n containrrr/watchtower -cR <容器名>", "2. 容器内执行 ql check、ql update": "2. 容器内执行 ql check、ql update", "24小时未运行": "24小时未运行", - "3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果": "3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果", + "3. 如果无法解决,容器内执行 ql log,拷贝执行结果": "3. 如果无法解决,容器内执行 ql log,拷贝执行结果", "6位数字": "6位数字", "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)", "BARK推送消息的分组,默认为qinglong": "BARK推送消息的分组,默认为qinglong", diff --git a/src/pages/error/index.tsx b/src/pages/error/index.tsx index df8f5a12..6389ea89 100644 --- a/src/pages/error/index.tsx +++ b/src/pages/error/index.tsx @@ -87,7 +87,7 @@ const Error = () => {
{intl.get('2. 容器内执行 ql check、ql update')}
{intl.get( - '3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果', + '3. 如果无法解决,容器内执行 ql log,拷贝执行结果', )} {intl.get('提交 issue')} diff --git a/test/back/qlServiceLogCommand.test.cjs b/test/back/qlServiceLogCommand.test.cjs new file mode 100644 index 00000000..4f64dabb --- /dev/null +++ b/test/back/qlServiceLogCommand.test.cjs @@ -0,0 +1,56 @@ +'use strict'; + +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const { spawnSync } = require('node:child_process'); +const { after, test } = require('node:test'); + +const root = path.resolve(__dirname, '../..'); +const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-log-command-')); + +after(() => fs.rmSync(fixtureRoot, { recursive: true, force: true })); + +function writeExecutable(filePath, content) { + fs.writeFileSync(filePath, content, { mode: 0o755 }); +} + +test('ql log scopes PM2 output to qinglong and forwards log options', () => { + const shellDir = path.join(fixtureRoot, 'shell'); + const binDir = path.join(fixtureRoot, 'bin'); + fs.mkdirSync(shellDir, { recursive: true }); + fs.mkdirSync(binDir, { recursive: true }); + + fs.copyFileSync( + path.join(root, 'shell/update.sh'), + path.join(shellDir, 'update.sh'), + ); + fs.writeFileSync( + path.join(shellDir, 'share.sh'), + 'load_ql_envs() { :; }\nimport_config() { :; }\n', + ); + fs.writeFileSync(path.join(shellDir, 'api.sh'), ''); + fs.writeFileSync(path.join(shellDir, 'env.sh'), ''); + writeExecutable( + path.join(binDir, 'pm2'), + '#!/usr/bin/env bash\nprintf "%s\\n" "$@"\n', + ); + + const result = spawnSync( + '/bin/bash', + [path.join(shellDir, 'update.sh'), 'log', '--lines', '25', '--nostream'], + { + encoding: 'utf8', + env: { + ...process.env, + PATH: `${binDir}:${process.env.PATH}`, + QL_DIR: fixtureRoot, + }, + }, + ); + + assert.equal(result.status, 0, result.stderr); + assert.equal(result.stdout, 'logs\nqinglong\n--lines\n25\n--nostream\n'); + assert.equal(fs.existsSync(path.join(fixtureRoot, 'data/log/log')), false); +});