bootstrap.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. local service = require "skynet.service"
  2. local skynet = require "skynet.manager" -- import skynet.launch, ...
  3. skynet.start(function()
  4. local standalone = skynet.getenv "standalone"
  5. local launcher = assert(skynet.launch("snlua","launcher"))
  6. skynet.name(".launcher", launcher)
  7. local harbor_id = tonumber(skynet.getenv "harbor" or 0)
  8. if harbor_id == 0 then
  9. assert(standalone == nil)
  10. standalone = true
  11. skynet.setenv("standalone", "true")
  12. local ok, slave = pcall(skynet.newservice, "cdummy")
  13. if not ok then
  14. skynet.abort()
  15. end
  16. skynet.name(".cslave", slave)
  17. else
  18. if standalone then
  19. if not pcall(skynet.newservice,"cmaster") then
  20. skynet.abort()
  21. end
  22. end
  23. local ok, slave = pcall(skynet.newservice, "cslave")
  24. if not ok then
  25. skynet.abort()
  26. end
  27. skynet.name(".cslave", slave)
  28. end
  29. if standalone then
  30. local datacenter = skynet.newservice "datacenterd"
  31. skynet.name("DATACENTER", datacenter)
  32. end
  33. skynet.newservice "service_mgr"
  34. local enablessl = skynet.getenv "enablessl"
  35. if enablessl == "true" then
  36. service.new("ltls_holder", function ()
  37. local c = require "ltls.init.c"
  38. c.constructor()
  39. end)
  40. end
  41. pcall(skynet.newservice,skynet.getenv "start" or "main")
  42. skynet.exit()
  43. end)