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

@ -27,18 +27,21 @@ function caddy_status()
e.running=luci.sys.call("pidof caddy >/dev/null")==0 e.running=luci.sys.call("pidof caddy >/dev/null")==0
local tagfile = io.open("/tmp/caddy_time", "r") local tagfile = io.open("/tmp/caddy_time", "r")
if tagfile then if tagfile then
local tagcontent = tagfile:read("*all") local tagcontent = tagfile:read("*all")
tagfile:close() tagfile:close()
if tagcontent and tagcontent ~= "" and luci.fs.stat("/tmp/caddy_time") then if tagcontent and tagcontent ~= "" 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") 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")
e.caddysta = command1:read("*all") local command_output_file = io.open("/tmp/command_output", "r")
command1:close() if command_output_file then
if e.caddysta == "" then e.caddysta = command_output_file:read("*all")
e.caddysta = "unknown" command_output_file:close()
end if e.caddysta == "" then
end e.caddysta = "unknown"
end
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}\')') 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}\')')
e.caddycpu = command2:read("*all") e.caddycpu = command2:read("*all")
command2:close() command2:close()