mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-20 10:19:00 +08:00
feat: add ql service log command
This commit is contained in:
+16
-4
@@ -211,6 +211,11 @@ run_extra_shell() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## 查看青龙服务日志
|
||||||
|
show_service_logs() {
|
||||||
|
pm2 logs qinglong "$@"
|
||||||
|
}
|
||||||
|
|
||||||
## 脚本用法
|
## 脚本用法
|
||||||
usage() {
|
usage() {
|
||||||
t "$cmd_update 命令使用方法:"
|
t "$cmd_update 命令使用方法:"
|
||||||
@@ -221,10 +226,11 @@ usage() {
|
|||||||
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
||||||
echo -e "6. $cmd_update bot # 启动tg-bot"
|
echo -e "6. $cmd_update bot # 启动tg-bot"
|
||||||
echo -e "7. $cmd_update check # 检测青龙环境并修复"
|
echo -e "7. $cmd_update check # 检测青龙环境并修复"
|
||||||
echo -e "8. $cmd_update resetlet # 重置登录错误次数"
|
echo -e "8. $cmd_update log [pm2-log-options] # 查看青龙服务日志"
|
||||||
echo -e "9. $cmd_update resettfa # 禁用两步登录"
|
echo -e "9. $cmd_update resetlet # 重置登录错误次数"
|
||||||
echo -e "10. $cmd_update resetpwd # 修改登录密码"
|
echo -e "10. $cmd_update resettfa # 禁用两步登录"
|
||||||
echo -e "11. $cmd_update resetname # 修改登录用户名"
|
echo -e "11. $cmd_update resetpwd # 修改登录密码"
|
||||||
|
echo -e "12. $cmd_update resetname # 修改登录用户名"
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_qinglong() {
|
reload_qinglong() {
|
||||||
@@ -471,6 +477,12 @@ main() {
|
|||||||
local p8="${8}"
|
local p8="${8}"
|
||||||
local p9="${9}"
|
local p9="${9}"
|
||||||
local p10="${10}"
|
local p10="${10}"
|
||||||
|
|
||||||
|
if [[ "$p1" == "log" ]]; then
|
||||||
|
show_service_logs "${@:2}"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
local log_dir="${p1}"
|
local log_dir="${p1}"
|
||||||
make_dir "$dir_log/$log_dir"
|
make_dir "$dir_log/$log_dir"
|
||||||
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||||
|
|||||||
@@ -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 <container_name>' on the host machine",
|
"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 <container_name>' on the host machine",
|
||||||
"2. 容器内执行 ql check、ql update": "2. Execute 'ql check' and 'ql update' inside the container",
|
"2. 容器内执行 ql check、ql update": "2. Execute 'ql check' and 'ql update' inside the container",
|
||||||
"24小时未运行": "Idle 24h+",
|
"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",
|
"6位数字": "6-digit number",
|
||||||
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK push icon, custom push icon (requires iOS 15 or above to display)",
|
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK push icon, custom push icon (requires iOS 15 or above to display)",
|
||||||
"BARK推送消息的分组,默认为qinglong": "BARK push message grouping, default is qinglong",
|
"BARK推送消息的分组,默认为qinglong": "BARK push message grouping, default is qinglong",
|
||||||
|
|||||||
@@ -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 <容器名>",
|
"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",
|
"2. 容器内执行 ql check、ql update": "2. 容器内执行 ql check、ql update",
|
||||||
"24小时未运行": "24小时未运行",
|
"24小时未运行": "24小时未运行",
|
||||||
"3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果": "3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果",
|
"3. 如果无法解决,容器内执行 ql log,拷贝执行结果": "3. 如果无法解决,容器内执行 ql log,拷贝执行结果",
|
||||||
"6位数字": "6位数字",
|
"6位数字": "6位数字",
|
||||||
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)",
|
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)",
|
||||||
"BARK推送消息的分组,默认为qinglong": "BARK推送消息的分组,默认为qinglong",
|
"BARK推送消息的分组,默认为qinglong": "BARK推送消息的分组,默认为qinglong",
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ const Error = () => {
|
|||||||
<div>{intl.get('2. 容器内执行 ql check、ql update')}</div>
|
<div>{intl.get('2. 容器内执行 ql check、ql update')}</div>
|
||||||
<div>
|
<div>
|
||||||
{intl.get(
|
{intl.get(
|
||||||
'3. 如果无法解决,容器内执行 pm2 logs,拷贝执行结果',
|
'3. 如果无法解决,容器内执行 ql log,拷贝执行结果',
|
||||||
)}
|
)}
|
||||||
<Typography.Link href="https://github.com/whyour/qinglong/issues/new?assignees=&labels=&template=bug_report.yml">
|
<Typography.Link href="https://github.com/whyour/qinglong/issues/new?assignees=&labels=&template=bug_report.yml">
|
||||||
{intl.get('提交 issue')}
|
{intl.get('提交 issue')}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user