Update caddy.lua

This commit is contained in:
lmq8267 2024-01-21 16:32:33 +08:00 committed by GitHub
parent 8d83c077ce
commit 038ae23a15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,14 +29,17 @@ function caddy_status()
if tagfile then
local tagcontent = tagfile:read("*all")
tagfile:close()
if tagcontent and tagcontent ~= "" and luci.fs.stat("/tmp/caddy_time") then
local command1 = io.popen("[ -f /tmp/caddy_time ] && start_time=$(cat /tmp/caddy_time) && time=$(($(date +%s)-start_time)) && day=$((time/86400)) && [ $day -eq 0 ] && day='' || day=${day}天 && time=$(date -u -d @${time} +'%H小时%M分%S秒') && echo $day $time")
e.caddysta = command1:read("*all")
command1:close()
if tagcontent and tagcontent ~= "" then
os.execute("start_time=$(cat /tmp/caddy_time) && time=$(($(date +%s)-start_time)) && day=$((time/86400)) && [ $day -eq 0 ] && day='' || day=${day}天 && time=$(date -u -d @${time} +'%H小时%M分%S秒') && echo $day $time > /tmp/command_output 2>&1")
local command_output_file = io.open("/tmp/command_output", "r")
if command_output_file then
e.caddysta = command_output_file:read("*all")
command_output_file:close()
if e.caddysta == "" then
e.caddysta = "unknown"
end
end
end
end
local command2 = io.popen('test ! -z "`pidof caddy`" && (top -b -n1 | grep -E "$(pidof caddy)" 2>/dev/null | grep -v grep | awk \'{for (i=1;i<=NF;i++) {if ($i ~ /caddy/) break; else cpu=i}} END {print $cpu}\')')