123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- local skynet = require "skynet"
- local codecache = require "skynet.codecache"
- require "skynet.manager"
- local logger = require "logger"
- local stringify = require "stringify"
- local cjson = require "cjson"
- local assetcenter
- local watchdog
- local authz = {
- -- yytx = "lee@YY-Games.520"
- lee = "yytx-Games-9527"
- }
- local updateserver
- local function newserver()
- local newnum = {}
- table.insert(newnum,{server=skynet.localname(".span_roulette"),configname={"tabledata_proto","tablecrossgroup_proto","tableshop_proto","bonusturntable_proto"}})--奖金轮盘
- table.insert(newnum,{server=skynet.localname(".span_common_service"),model_name ='cross_elf_master',configname={"dsparameter_proto","dsfight_proto","dsmonster_proto","dsvar_proto",'dsaward_proto','dscrossgroup_proto'}})--跨服精灵大师
- return newnum
- end
- local function hotfix_true(hotfixlist,configname)
- if hotfixlist then
- if hotfixlist == "*" then
- return 1
- end
- for k, v in pairs(configname) do
- if hotfixlist[v] then
- logger.trace("_______________________热更配置:%s,更新服务",v)
- return 1
- end
- end
- end
- return
- end
- --对需要更新配置的服务进行更新
- local function updateconfig(hotfixlist)
- updateserver = updateserver or newserver()
- if next(updateserver) then
- for k, v in pairs(updateserver) do
- if v.configname and hotfix_true(hotfixlist,v.configname) then
- skynet.send(v.server, "lua", "hotfix",hotfixlist,v.model_name)
- end
- end
- else
- logger.trace("_______________________热更配置无服务需要")
- end
- end
- -- local z_trace = require "zlf_log"
- -- local z_trace = z_trace.trace
- -- example:
- -- http://192.168.1.57:9001/hotfix?user=lee&pwd=lee@123&config=*
- -- http://192.168.1.57:9001/hotfix?user=lee&pwd=lee@123&code=*
- -- http://192.168.1.57:9001/hotfix?user=lee&pwd=lee@123&code=*&config=*
- local function hotfix(args, ipaddr, header)
- logger.warn("处理来自主机 %s 的hotfix请求,:%s", ipaddr,args.config)
- -- 鉴权
- -- local user = args.user or ""
- -- local pwd = args.pwd or ""
- -- if authz[user] ~= pwd then
- -- -- return { "403 - Forbidden" }
- -- return cjson.encode({errno = 403, host = header.host, info = "账号或密码错误"})
- -- end
- logger.warn("更新配置文件:%s",args.config)
- -- 热更配置文件
- if args.config then
- local hotfixlist
- assetcenter = assetcenter or skynet.localname(".assetcenter")
- local error
- if args.config == "*" then
- error = skynet.call(assetcenter, "lua", "hotfix")
- hotfixlist = "*"
- elseif args.config then
- hotfixlist = {}
- local ok, entity = pcall(cjson.decode, args.config)
- -- z_trace.guild(" --- entity = ", entity)
- if not ok then
- return { code=400, msg="Bad request" }
- end
- for k, v in pairs(entity.config) do
- logger.warn("更新配置文件:%s",v)
- error = skynet.call(assetcenter, "lua", "hotfix",v)
- hotfixlist[v] = 1
- end
- else
- return cjson.encode({errno = 400, host = header.host, info = "缺少配置表参数"})
- end
- if error then
- return cjson.encode({errno = 400, host = header.host, info = "读取文件失败: ".. error})
- end
- updateconfig(hotfixlist)
- -- else
- -- return cjson.encode({errno = 400, host = header.host, info = "参数未nil : "})
- end
- -- 热更源代码
- if args.code then
- codecache.clear()
- end
- --通知 watchdog, 放弃 agent 池中的失效对象
- watchdog = watchdog or skynet.localname(".ws_watchdog")
- skynet.call(watchdog, "lua", "hotfix")
- logger.warn("hotfix (%s, %s)", args.user, ipaddr)
- return cjson.encode({errno = 200, host = header.host, info = "热更新 成功"})
- end
- return hotfix
|