From 2b83d6718c652412eec0f0170940490b89a043ca Mon Sep 17 00:00:00 2001 From: huahua132 <958677003@qq.com> Date: Thu, 5 Dec 2024 17:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=83=8F=E6=96=87=E4=BB=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=95=B4=E7=90=86=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/AB_question/load_mods.lua | 16 +++++++++++- examples/record/load_mods.lua | 21 ++++++++++++++- service/contriner_mgr.lua | 3 ++- service/hot_container.lua | 41 ++++++++++++++++++++++++++---- 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/examples/AB_question/load_mods.lua b/examples/AB_question/load_mods.lua index 0a35a0fbf..a0de566eb 100644 --- a/examples/AB_question/load_mods.lua +++ b/examples/AB_question/load_mods.lua @@ -6,6 +6,7 @@ return { B_m = { launch_seq = 2, launch_num = 4, + is_record_on = 1, --开启录像 --自动定时热更 skynet-fly.time_extend.time_point.lua 的配置项 auto_reload = { @@ -13,11 +14,24 @@ return { sec = 30, --第30秒 }, + --录像文件自动整理 + --需要启动logrotate_m + record_backup = { + max_age = 3, --最大保留天数 + max_backups = 8,--最大保留文件数 + point_type = 1, --每分钟整理一次 + sec = 20, --第20秒整理 + }, + mod_args = { {instance_name = "test_one"}, {instance_name = "test_one"}, {instance_name = "test_two"}, {instance_name = "test_two"}, } - } + }, + logrotate_m = { + launch_seq = 3, + launch_num = 1, + } } \ No newline at end of file diff --git a/examples/record/load_mods.lua b/examples/record/load_mods.lua index 07026ef61..2cdfce7b1 100644 --- a/examples/record/load_mods.lua +++ b/examples/record/load_mods.lua @@ -26,5 +26,24 @@ return { launch_seq = 3, launch_num = 1, is_record_on = 1, --录像 - } + + --自动定时热更 skynet-fly.time_extend.time_point.lua 的配置项 + auto_reload = { + type = 1, --每分钟 + sec = 30, --第30秒 + }, + + --录像文件自动整理 + --需要启动logrotate_m + record_backup = { + max_age = 3, --最大保留天数 + max_backups = 8,--最大保留文件数 + point_type = 1, --每分钟整理一次 + sec = 20, --第20秒整理 + }, + }, + logrotate_m = { + launch_seq = 4, + launch_num = 1, + } } \ No newline at end of file diff --git a/service/contriner_mgr.lua b/service/contriner_mgr.lua index 88bfa6be0..9eb047584 100644 --- a/service/contriner_mgr.lua +++ b/service/contriner_mgr.lua @@ -59,6 +59,7 @@ local function launch_new_module(module_name, config) local launch_num = config.launch_num local is_record_on = config.is_record_on --是否写录像 local auto_reload = config.auto_reload --自动热更机制 + local record_backup = config.record_backup --录像文件整理 local mod_args = config.mod_args or {} local default_arg = config.default_arg or {} @@ -81,7 +82,7 @@ local function launch_new_module(module_name, config) local server_id = skynet.newservice('hot_container',module_name,i,cur_date,cur_time,version,is_record_on) local args = mod_args[i] or default_arg - local isok,ret = pcall(skynet_call, server_id, 'lua', 'start', args, auto_reload) + local isok,ret = pcall(skynet_call, server_id, 'lua', 'start', args, auto_reload, record_backup) if not isok or not ret then log.fatal("launch_new_module err ",module_name,args) is_ok = false diff --git a/service/hot_container.lua b/service/hot_container.lua index 4474fde74..941938b0a 100755 --- a/service/hot_container.lua +++ b/service/hot_container.lua @@ -18,7 +18,7 @@ assert(MODULE_NAME) local new_loaded = _loaded if IS_RECORD_ON == 1 then - skynet.start_record(ARGV, MODULE_NAME .. '-' .. INDEX .. '-' .. VERSION .. '-' .. os.date('%Y%m%d-%H%M%S', LAUNCH_TIME)) + skynet.start_record(ARGV, MODULE_NAME .. '-' .. VERSION .. '-' .. INDEX .. '-' .. os.date('%Y%m%d-%H%M%S', LAUNCH_TIME)) end local CMD = {} @@ -167,7 +167,7 @@ local function check_exit() end end -function CMD.start(cfg, auto_reload) +function CMD.start(cfg, auto_reload, record_backup) if g_breakpoint_debug_host and g_breakpoint_debug_port then log.warn_fmt("start breakpoint module_name[%s] index[%s] host[%s] port[%s]", MODULE_NAME, INDEX, g_breakpoint_debug_host, g_breakpoint_debug_port) require("skynet-fly.LuaPanda").start(g_breakpoint_debug_host, g_breakpoint_debug_port); @@ -187,16 +187,15 @@ function CMD.start(cfg, auto_reload) for _,func in ipairs(g_start_after_cb) do skynet.fork(func) end - contriner_client:open_ready() - SERVER_STATE = SERVER_STATE_TYPE.starting + --自动热更处理 if auto_reload and INDEX == 1 then local timer_point = require "skynet-fly.time_extend.timer_point" g_time_point_obj = timer_point:new(auto_reload.type) local function set_time_point_opt(opt) if auto_reload[opt] then - local set_func = assert(g_time_point_obj['set_' .. opt], "opt func not exists: " .. opt) + local set_func = assert(timer_point['set_' .. opt], "opt func not exists: " .. opt) g_time_point_obj = set_func(g_time_point_obj, auto_reload[opt]) end end @@ -212,6 +211,38 @@ function CMD.start(cfg, auto_reload) skynet.send('.contriner_mgr','lua','load_modules', skynet.self(), MODULE_NAME) end) end + + --录像保留文件整理 + if record_backup and INDEX == 1 and IS_RECORD_ON == 1 then + local logrotate = require "skynet-fly.logrotate" + skynet.fork(function() + local rotate_obj = logrotate:new() + :set_file_path(skynet.getenv('recordpath')) + local function set_rotate_opt(opt) + if record_backup[opt] then + local set_func = assert(logrotate['set_' .. opt], "opt func not exists: " .. opt) + rotate_obj = set_func(rotate_obj, record_backup[opt]) + end + end + set_rotate_opt('max_age') + set_rotate_opt('max_backups') + + set_rotate_opt('point_type') + set_rotate_opt('month') + set_rotate_opt('day') + set_rotate_opt('hour') + set_rotate_opt('min') + set_rotate_opt('sec') + set_rotate_opt('wday') + set_rotate_opt('yday') + + rotate_obj:set_back_pattern(MODULE_NAME) --设置匹配文件名 + rotate_obj:builder() + end) + end + + contriner_client:open_ready() + SERVER_STATE = SERVER_STATE_TYPE.starting else SERVER_STATE = SERVER_STATE_TYPE.start_failed end