mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add cluster.reload(config)
This commit is contained in:
@@ -3,6 +3,11 @@ local cluster = require "cluster"
|
||||
local snax = require "snax"
|
||||
|
||||
skynet.start(function()
|
||||
cluster.reload {
|
||||
db = "127.0.0.1:2528",
|
||||
db2 = "127.0.0.1:2529",
|
||||
}
|
||||
|
||||
local sdb = skynet.newservice("simpledb")
|
||||
-- register name "sdb" for simpledb, you can use cluster.query() later.
|
||||
-- See cluster2.lua
|
||||
|
||||
@@ -6,5 +6,6 @@ bootstrap = "snlua bootstrap" -- The service for bootstrap
|
||||
luaservice = "./service/?.lua;./test/?.lua;./examples/?.lua"
|
||||
lualoader = "lualib/loader.lua"
|
||||
cpath = "./cservice/?.so"
|
||||
cluster = "./examples/clustername.lua"
|
||||
-- use cluster.reload instead, see cluster1.lua
|
||||
-- cluster = "./examples/clustername.lua"
|
||||
snax = "./test/?.lua"
|
||||
|
||||
@@ -21,8 +21,8 @@ function cluster.open(port)
|
||||
end
|
||||
end
|
||||
|
||||
function cluster.reload()
|
||||
skynet.call(clusterd, "lua", "reload")
|
||||
function cluster.reload(config)
|
||||
skynet.call(clusterd, "lua", "reload", config)
|
||||
end
|
||||
|
||||
function cluster.proxy(node, name)
|
||||
|
||||
@@ -29,12 +29,16 @@ end
|
||||
|
||||
local node_channel = setmetatable({}, { __index = open_channel })
|
||||
|
||||
local function loadconfig()
|
||||
local f = assert(io.open(config_name))
|
||||
local source = f:read "*a"
|
||||
f:close()
|
||||
local tmp = {}
|
||||
assert(load(source, "@"..config_name, "t", tmp))()
|
||||
local function loadconfig(tmp)
|
||||
if tmp == nil then
|
||||
tmp = {}
|
||||
if config_name then
|
||||
local f = assert(io.open(config_name))
|
||||
local source = f:read "*a"
|
||||
f:close()
|
||||
assert(load(source, "@"..config_name, "t", tmp))()
|
||||
end
|
||||
end
|
||||
for name,address in pairs(tmp) do
|
||||
assert(type(address) == "string")
|
||||
if node_address[name] ~= address then
|
||||
@@ -47,8 +51,8 @@ local function loadconfig()
|
||||
end
|
||||
end
|
||||
|
||||
function command.reload()
|
||||
loadconfig()
|
||||
function command.reload(source, config)
|
||||
loadconfig(config)
|
||||
skynet.ret(skynet.pack(nil))
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user