update 2026-10-09 04:58:55

This commit is contained in:
action committed 2026-10-09 04:58:55 +08:00
1 parent 9c17634d78
commit d6b7af2a48
636 files changed
+163 -121913

No files matched your search

@@ -24,6 +24,36 @@ local uci, uci_get, uci_set, uci_del, uci_foreach, uci_save = api.uci, api.uci_g
local tinsert = table.insert
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
-- [[ 逻辑锁 Start ]] --
if not arg[1] then os.exit(0) end
-- Both update scripts use the same lockf lock; the kernel releases it on exit.
local update_lock = api.nixio.open(api.LOCK_PREFIX .. "_sub_rule.lock", api.nixio.open_flags("rdwr", "creat"))
if not update_lock then
api.log("无法打开订阅/规则更新锁,退出。")
os.exit(1)
end
-- Scheduled updates wait for the lock; manual requests may skip a busy lock.
if not update_lock:lock("tlock") then
if arg[3] ~= "cron" then
api.log("订阅或规则更新正在运行,本次请求跳过。")
os.exit(0)
end
local running = ({s = "订阅", r = "规则更新"})[update_lock:read(1)] or "订阅/规则更新"
update_lock:seek(0)
api.log("[" .. running .. "]实例正在运行,[订阅]进入队列等待...")
if not update_lock:lock("lock") then
api.log("无法取得更新锁,计划任务失败。")
os.exit(1)
end
end
-- Record the running task in the same file: s = subscription, r = rule update.
update_lock:write("s")
update_lock:seek(0)
api.uci:revert(c_config)
math.randomseed(os.time() + math.floor(os.clock() * 1000))
local restart_required = false
-- [[ 逻辑锁 End ]] --
local has_ss_rust = api.is_finded("sslocal")
local has_ssr = api.is_finded("ssr-local") and api.is_finded("ssr-redir")
local has_singbox = api.finded_com("sing-box")
@@ -2107,10 +2137,7 @@ local function update_node(manual)
uci_save(true)
local action = (arg[3] == "cron") and " cron" or ""
if manual ~= 1 then
luci.sys.call("/etc/init.d/passwall restart%s > /dev/null 2>&1 &" % action)
end
if manual ~= 1 then restart_required = true end
end
local function parse_link(raw, add_mode, group, sub_cfg)
@@ -2282,56 +2309,28 @@ local execute = function()
end
end
local function check_instance(action)
local sub_lock = api.LOCK_PREFIX .. "_subscribe.lock"
local rule_lock = api.LOCK_PREFIX .. "_rule_update.lock"
if action == "start" then
math.randomseed(os.time() + math.floor(os.clock() * 1000))
api.nixio.nanosleep(0, math.random(100, 1000) * 1000000)
if fs.access(sub_lock) then
log("有[订阅]实例正在运行,请稍后再试...\n")
os.exit(0)
else
luci.sys.call("touch " .. sub_lock)
uci:revert(c_config)
if arg[1] == "start" then
log('开始订阅...')
xpcall(execute, function(e)
log(e)
if type(debug) == "table" and type(debug.traceback) == "function" then
log(debug.traceback())
end
elseif action == "end" then
api.remove(sub_lock)
return
end
if fs.access(rule_lock) then
log("[规则更新]实例正在运行,[订阅]进入队列等待...\n")
end
while fs.access(rule_lock) do
api.nixio.nanosleep(2, 0)
end
log('订阅发生错误。')
end)
log('订阅完毕...\n')
elseif arg[1] == "add" then
local f = assert(io.open("/tmp/links.conf", 'r'))
local raw = f:read('*all')
f:close()
parse_link(raw, "1", arg[2])
update_node(1)
api.remove("/tmp/links.conf")
elseif arg[1] == "truncate" then
truncate_nodes(arg[2])
end
if arg[1] then
check_instance("start")
if arg[1] == "start" then
log('开始订阅...')
xpcall(execute, function(e)
log(e)
if type(debug) == "table" and type(debug.traceback) == "function" then
log(debug.traceback())
end
log('发生错误, 正在恢复服务')
end)
log('订阅完毕...\n')
elseif arg[1] == "add" then
local f = assert(io.open("/tmp/links.conf", 'r'))
local raw = f:read('*all')
f:close()
parse_link(raw, "1", arg[2])
update_node(1)
api.remove("/tmp/links.conf")
elseif arg[1] == "truncate" then
truncate_nodes(arg[2])
end
check_instance("end")
update_lock:close()
if restart_required then
local action = arg[3] == "cron" and " cron" or ""
luci.sys.call("/etc/init.d/passwall restart" .. action .. " > /dev/null 2>&1 &")
end