mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
service_mgr support list, add a debug command to debug_console
This commit is contained in:
@@ -7,3 +7,4 @@ address = "127.0.0.1:2527"
|
||||
master = "127.0.0.1:2013"
|
||||
start = "main_log"
|
||||
luaservice ="./service/?.lua;./test/?.lua;./examples/?.lua"
|
||||
snax = "./examples/?.lua;./test/?.lua"
|
||||
|
||||
@@ -8,7 +8,7 @@ skynet.start(function()
|
||||
skynet.monitor "simplemonitor"
|
||||
local lualog = skynet.newservice("lualog")
|
||||
local console = skynet.newservice("console")
|
||||
-- skynet.newservice("debug_console",8000)
|
||||
skynet.newservice("debug_console",8000)
|
||||
skynet.newservice("simpledb")
|
||||
local watchdog = skynet.newservice("watchdog")
|
||||
skynet.call(watchdog, "lua", "start", {
|
||||
|
||||
@@ -110,6 +110,7 @@ function COMMAND.help()
|
||||
gc = "gc : force every lua service do garbage collect",
|
||||
start = "lanuch a new lua service",
|
||||
clearcache = "clear lua code cache",
|
||||
service = "List unique service",
|
||||
}
|
||||
end
|
||||
|
||||
@@ -126,4 +127,6 @@ function COMMAND.start(...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function COMMAND.service()
|
||||
return skynet.call("SERVICE", "lua", "LIST")
|
||||
end
|
||||
|
||||
@@ -58,36 +58,107 @@ local function waitfor(name , func, ...)
|
||||
return s
|
||||
end
|
||||
|
||||
function cmd.LAUNCH(service_name, subname, ...)
|
||||
if service_name == "snaxd" then
|
||||
return waitfor("snax."..subname, snax.rawnewservice, subname, ...)
|
||||
local function read_name(service_name)
|
||||
if string.byte(service_name) == 64 then -- '@'
|
||||
return string.sub(service_name , 2)
|
||||
else
|
||||
return waitfor(service_name, skynet.newservice, service_name, subname, ...)
|
||||
return service_name
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.LAUNCH(service_name, subname, ...)
|
||||
local realname = read_name(service_name)
|
||||
|
||||
if realname == "snaxd" then
|
||||
return waitfor(service_name.."."..subname, snax.rawnewservice, subname, ...)
|
||||
else
|
||||
return waitfor(service_name, skynet.newservice, realname, subname, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.QUERY(service_name, subname)
|
||||
if service_name == "snaxd" then
|
||||
return waitfor("snax."..subname)
|
||||
local realname = read_name(service_name)
|
||||
|
||||
if realname == "snaxd" then
|
||||
return waitfor(service_name.."."..subname)
|
||||
else
|
||||
return waitfor(service_name)
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.GLAUNCH(...)
|
||||
if GLOBAL then
|
||||
return cmd.LAUNCH(...)
|
||||
else
|
||||
return waitfor(service_name, skynet.call, "SERVICE", "lua", "LAUNCH", ...)
|
||||
local function list_service()
|
||||
local result = {}
|
||||
for k,v in pairs(service) do
|
||||
if type(v) == "string" then
|
||||
v = "Error: " .. v
|
||||
elseif type(v) == "table" then
|
||||
v = "Querying"
|
||||
else
|
||||
v = skynet.address(v)
|
||||
end
|
||||
|
||||
result[k] = v
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
local function register_global()
|
||||
function cmd.GLAUNCH(name, ...)
|
||||
local global_name = "@" .. name
|
||||
return cmd.LAUNCH(global_name, ...)
|
||||
end
|
||||
|
||||
function cmd.GQUERY(name, ...)
|
||||
local global_name = "@" .. name
|
||||
return cmd.QUERY(global_name, ...)
|
||||
end
|
||||
|
||||
local mgr = {}
|
||||
|
||||
function cmd.REPORT(m)
|
||||
mgr[m] = true
|
||||
skynet.watch(m)
|
||||
end
|
||||
|
||||
local function add_list(all, m)
|
||||
local harbor = "@" .. skynet.harbor(m)
|
||||
local result = skynet.call(m, "lua", "LIST")
|
||||
for k,v in pairs(result) do
|
||||
all[k .. harbor] = v
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.LIST()
|
||||
local result = {}
|
||||
for k in pairs(mgr) do
|
||||
pcall(add_list, result, k)
|
||||
end
|
||||
local l = list_service()
|
||||
for k, v in pairs(l) do
|
||||
result[k] = v
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.GQUERY(...)
|
||||
if GLOBAL then
|
||||
return cmd.QUERY(...)
|
||||
else
|
||||
return waitfor(service_name, skynet.call, "SERVICE", "lua", "QUERY", ...)
|
||||
local function register_local()
|
||||
function cmd.GLAUNCH(name, ...)
|
||||
local global_name = "@" .. name
|
||||
return waitfor(global_name, skynet.call, "SERVICE", "lua", "LAUNCH", global_name, ...)
|
||||
end
|
||||
|
||||
function cmd.GQUERY(name, ...)
|
||||
local global_name = "@" .. name
|
||||
return waitfor(global_name, skynet.call, "SERVICE", "lua", "QUERY", global_name, ...)
|
||||
end
|
||||
|
||||
function cmd.LIST()
|
||||
return list_service()
|
||||
end
|
||||
|
||||
skynet.call("SERVICE", "lua", "REPORT", skynet.self())
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
@@ -110,5 +181,8 @@ skynet.start(function()
|
||||
if skynet.getenv "standalone" then
|
||||
GLOBAL = true
|
||||
skynet.register("SERVICE")
|
||||
register_global()
|
||||
else
|
||||
register_local()
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -2,7 +2,7 @@ local skynet = require "skynet"
|
||||
local snax = require "snax"
|
||||
|
||||
skynet.start(function()
|
||||
local ps = snax.newservice ("pingserver", "hello world")
|
||||
local ps = snax.uniqueservice ("pingserver", "hello world")
|
||||
print(ps.req.ping("foobar"))
|
||||
print(ps.pub.hello())
|
||||
print(pcall(ps.req.error))
|
||||
@@ -24,6 +24,6 @@ end
|
||||
|
||||
]]))
|
||||
print(ps.pub.hello())
|
||||
print(snax.kill(ps,"exit"))
|
||||
-- print(snax.kill(ps,"exit"))
|
||||
skynet.exit()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user