Closed soiamsoNG closed 3 months ago
感谢反馈!
systemd service Type=notify 的情况下 ,会一直等待 READY=1,未收到前会一直处于启动未完成状态(activating),需要一个位点发出 READY=1。
ExecCommand 没有 | 的escape, 导致 echo "STOPPING=1" | socat - UNIX-SENDTO:/run/notify/notify.sock 这种代码不能使用
ExecCommand 是否可以添加array类型支持,而不是只有string类型用 | 分割,
例子: execCommand_Run = ["sh","-c","echo \"READY=1\" | socat - UNIX-SENDTO:/run/notify/notify.sock"]
因为 Golang 的原因, 管道需要套娃: https://studygolang.com/topics/10056 不过, 不清楚用什么符号分割命令及参数较好. 理论上, 用空格最为直观, 但也需要处理空格转义的问题
方向一,如下可以前面两个参数硬编码,这样就不用考虑现在的分割问题或转义问题, 也可以用分号输入多行命令。 exec.Command("/bin/sh", "-c", "这部分是execCommand设定的字符串")
方向二,也可以继续现在的分割方法, 见到 “ \| ” 不分割
方向三,ExecCommand识别json的type,string用旧方法,array就按顺序放到 exec.Command的arg里面。
可测试此版本: https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/actions/runs/8813068013
具体而言: 通过改为对字符串的逐字读取, 现在可以以更接近实际命令使用的空格作为分割符, 且若遇到 '
或 "
时, 内部的空格不会被识别为分割符, 管道现也不会因为和分割符一样而被忽略. 但是, 出于上述提到的原因, 可能仍然需要以 sh 来套娃.
对转义做了简单的处理, 并在 RunConsole 开头插入一个具体的测试, 测试代码及结果如下:
config.Debug = true
_, out, _ := ExecCommand("/bin/sh -c 'echo Testing'")
Log("Test", "%s", false, string(out))
_, out, _ = ExecCommand("/bin/sh -c 'echo \"'Testing'\"'")
Log("Test", "%s", false, string(out))
_, out, _ = ExecCommand("/bin/sh -c 'echo '\\Testing...\\''")
Log("Test", "%s", false, string(out))
_, out, _ = ExecCommand("/bin/bash -c 'echo '\\Testing...\\''")
Log("Test", "%s", false, string(out))
_, out, _ = ExecCommand("/bin/bash -c 'echo '\\Testing...\\'|cat'")
Log("Test", "%s", false, string(out))
return
[2024-04-24 15:57:25][Debug-ExecCommand] Split (|): /bin/sh|-c|echo Testing.
[2024-04-24 15:57:25][Test] Testing
.
[2024-04-24 15:57:25][Debug-ExecCommand] Split (|): /bin/sh|-c|echo "Testing".
[2024-04-24 15:57:25][Test] Testing
.
[2024-04-24 15:57:25][Debug-ExecCommand] Split (|): /bin/sh|-c|echo \Testing...\'.
[2024-04-24 15:57:25][Test] Testing...'
.
[2024-04-24 15:57:25][Debug-ExecCommand] Split (|): /bin/bash|-c|echo \Testing...\'.
[2024-04-24 15:57:25][Test] Testing...'
.
[2024-04-24 15:57:25][Debug-ExecCommand] Split (|): /bin/bash|-c|echo \Testing...\'|cat.
[2024-04-24 15:57:25][Test] Testing...'
.
测试版本可用,要等docker版本再测试了
3.3b6 已发布!
在3.3b6 container下测试以下配置可用
"execCommand_Run": "sh -c 'echo \"READY=1\" | socat - UNIX-SENDTO:/run/notify/notify.sock'",
"fetchFailedThreshold": 2,
"execCommand_FetchFailed": "sh -c 'echo \"STOPPING=1\" | socat - UNIX-SENDTO:/run/notify/notify.sock'"
视作完成而关闭!
[RunConsole] 程序已启动
之后[Fetch] 获取时发生了错误
之后例子: readyCommand=echo "READY=1" | socat - UNIX-SENDTO:/run/notify/notify.sock clientLostCommand=echo "STOPPING=1" | socat - UNIX-SENDTO:/run/notify/notify.sock