这是一篇纯草稿纸记录的文章,毫无技术可言,哈哈
按照skynet readme运行的结果,程序中加了一些日志帮助分析启动流程
[dongsong@localhost skynet]$ ./skynet examples/config | tee skynet.log
root = "./"
thread = 8
logger = nil
harbor = 1
address = "127.0.0.1:2526"
master = "127.0.0.1:2013"
start = "main" -- main script
bootstrap = "snlua bootstrap" -- The service for bootstrap
standalone = "0.0.0.0:2013"
luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua"
lualoader = "lualib/loader.lua"
-- preload = "./examples/preload.lua" -- run preload.lua before every lua service run
snax = root.."examples/?.lua;"..root.."test/?.lua"
cpath = root.."cservice/?.so"
-- daemon = "./skynet.pid"
[DEBUG] skynet_context_new(module_name("logger"), param("(null)"))
[DEBUG] bootstrap("snlua bootstrap")
[DEBUG] skynet_context_new(module_name("snlua"), param("bootstrap"))
[:01000001] LAUNCH logger
-->第一个服务(logger),启动时由c创建,不是用skynet lua api创建的
[LUA_DBUG] loadfile("./service/bootstrap.lua")
[LUA_DBUG] dofile(bootstrap)
[:01000002] LAUNCH snlua bootstrap
-->也是启动时c创建,第一个lua vm,运行service/bootstrap服务(它会起更多的服务)
[DEBUG] skynet_context_new(module_name("snlua"), param("launcher"))
[LUA_DBUG] loadfile("./service/launcher.lua")
[:01000003] LAUNCH snlua launcher
-->bootstrap创建的新服务:skynet.launch("snlua","launcher")
-->launch是一个负责启动和管理lua服的服务
-->自此以后可以用skynet.newservice创建lua服了
[LUA_DBUG] dofile(launcher)
lanuch service received: 2 :01000002 LAUNCH "snlua cmaster"
[DEBUG] skynet_context_new(module_name("snlua"), param("cmaster"))
[LUA_DBUG] loadfile("./service/cmaster.lua")
[:01000004] LAUNCH snlua cmaster
lanuch service received: 0 :01000003 LAUNCHOK ""
[LUA_DBUG] dofile(cmaster)
[:01000004] master listen socket 0.0.0.0:2013
lanuch service received: 0 :01000004 LAUNCHOK ""
lanuch service received: 3 :01000002 LAUNCH "snlua cslave"
[DEBUG] skynet_context_new(module_name("snlua"), param("cslave"))
[LUA_DBUG] loadfile("./service/cslave.lua")
[LUA_DBUG] dofile(cslave)
[DEBUG] skynet_context_new(module_name("harbor"), param("1 16777221"))
[LUA_DBUG] cmaster recorded slave nodes:
table: 0x7fd15526ddd0
{
1=>
table: 0x7fd15534e060
{
id=>1
fd=>4
addr=>127.0.0.1:2526
}
}
lanuch service received: 0 :01000005 LAUNCHOK ""
[:01000005] LAUNCH snlua cslave
[:01000005] slave connect to master 127.0.0.1:2013
[:01000004] connect from 127.0.0.1
[:01000006] LAUNCH harbor 1 16777221
[:01000004] Harbor 1 (fd=4) report 127.0.0.1:2526
[:01000005] Waiting for 0 harbors
[:01000005] Shakehand ready
lanuch service received: 4 :01000002 LAUNCH "snlua datacenterd"
[DEBUG] skynet_context_new(module_name("snlua"), param("datacenterd"))
[LUA_DBUG] loadfile("./service/datacenterd.lua")
[LUA_DBUG] dofile(datacenterd)
[:01000007] LAUNCH snlua datacenterd
lanuch service received: 0 :01000007 LAUNCHOK ""
lanuch service received: 5 :01000002 LAUNCH "snlua service_mgr"
[DEBUG] skynet_context_new(module_name("snlua"), param("service_mgr"))
[LUA_DBUG] loadfile("./service/service_mgr.lua")
[LUA_DBUG] dofile(service_mgr)
[:01000008] LAUNCH snlua service_mgr
lanuch service received: 0 :01000008 LAUNCHOK ""
lanuch service received: 6 :01000002 LAUNCH "snlua main"
[DEBUG] skynet_context_new(module_name("snlua"), param("main"))
[LUA_DBUG] loadfile("./examples/main.lua")
[LUA_DBUG] dofile(main)
[:01000009] LAUNCH snlua main
Server start
lanuch service received: 2 :01000009 LAUNCH "snlua console"
[DEBUG] skynet_context_new(module_name("snlua"), param("console"))
[:0100000a] LAUNCH snlua console
[LUA_DBUG] loadfile("./service/console.lua")
[LUA_DBUG] dofile(console)
lanuch service received: 0 :0100000a LAUNCHOK ""
lanuch service received: 3 :01000009 LAUNCH "snlua debug_console 8000"
[DEBUG] skynet_context_new(module_name("snlua"), param("debug_console 8000"))
[LUA_DBUG] loadfile("./service/debug_console.lua")
[LUA_DBUG] dofile(debug_console)
[:0100000b] LAUNCH snlua debug_console 8000
[:0100000b] Start debug console at 127.0.0.1 8000
lanuch service received: 0 :0100000b LAUNCHOK ""
lanuch service received: 4 :01000009 LAUNCH "snlua simpledb"
[DEBUG] skynet_context_new(module_name("snlua"), param("simpledb"))
[LUA_DBUG] loadfile("./examples/simpledb.lua")
[LUA_DBUG] dofile(simpledb)
[:0100000c] LAUNCH snlua simpledb
lanuch service received: 0 :0100000c LAUNCHOK ""
lanuch service received: 5 :01000009 LAUNCH "snlua watchdog"
[DEBUG] skynet_context_new(module_name("snlua"), param("watchdog"))
[:0100000d] LAUNCH snlua watchdog
[LUA_DBUG] loadfile("./examples/watchdog.lua")
[LUA_DBUG] dofile(watchdog)
lanuch service received: 2 :0100000d LAUNCH "snlua gate"
[DEBUG] skynet_context_new(module_name("snlua"), param("gate"))
[:0100000e] LAUNCH snlua gate
[LUA_DBUG] loadfile("./service/gate.lua")
[LUA_DBUG] dofile(gate)
lanuch service received: 0 :0100000e LAUNCHOK ""
lanuch service received: 0 :0100000d LAUNCHOK ""
Watchdog listen on 8888
lanuch service received: 0 :01000009 REMOVE ":01000009"
[:01000009] KILL self
[dongsong@localhost skynet]$ sudo netstat -lntp | grep skynet
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 2705/./skynet
--> simpledb service (watchdog service listen 8888), waiting for examples/client.lua
tcp 0 0 0.0.0.0:2013 0.0.0.0:* LISTEN 2705/./skynet
--> cmaster service (listen examples/config.master), waiting for slave to connect
tcp 0 0 127.0.0.1:2526 0.0.0.0:* LISTEN 2705/./skynet
--> cslave service (listen examples/config.address), waiting for old slave node to connect (as the first slave, waiting for none?)
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 2705/./skynet
--> debug_console service (listen 8000), waiting for telnet
[dongsong@localhost skynet]$ ./lua examples/client.lua
Response: 0 true Welcome to skynet
set a 1000
Request: 1
Response: 1 true nil
get a
Request: 2
Response: 2 true 1000
[dongsong@localhost skynet]$ telnet 127.0.0.1 8000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Welcome to skynet console
help
clearcache clear lua code cache
gc gc : force every lua service do garbage collect
help This help message
info Info address : get service infomation
kill kill address : kill service
list List all the service
mem mem : show memory status
service List unique service
snax lanuch a new snax service
start lanuch a new lua service
stat Dump all stats
task task address : show service task detail
^]
telnet> Connection closed.