Skynet startup Process--

Source: Internet
Author: User

Skynet consists of one or more processes, each of which is referred to as a Skynet node. This article describes the start-up process for the Skynet node.

The Skynet node starts by running the Skynet main program and must pass in a Config file name on the startup command line as the startup parameter. Skynet will read this config file to get the required parameters for startup.

The first service to start is logger, which is responsible for logging the log output from the service after it is logged. Logger is a simple C service, and skynet_error the C API will send the string to it. In the config file, the logger configuration item can configure the file name of the log output, which is nil by default, indicating output to standard output.

Bootstrap this configuration item is related to the second service that Skynet runs. This service usually starts up the whole system. The default bootstrap configuration entry is "snlua bootstrap" , which means that Skynet will start the Snlua service and pass bootstrap as a parameter to it. Snlua is the LUA sandbox service, Bootstrap will match to the final Lua script based on the configured Luaservice. If you press the default configuration, the script should be Service/bootstrap.lua.

If it is not necessary, you do not need to change the Booststrap configuration item to let the default bootstrap script work. The current bootstrap script is as follows:

Local Skynet=Require"Skynet"Local Harbor=Require"Skynet.harbor"Skynet.Startfunction ()Local standalone= Skynet.Getenv"Standalone"Local launcher=ASSERT (Skynet.Launch"Snlua","Launcher")) Skynet.Name". Launcher", launcher)Local harbor_id=Tonumber (Skynet.Getenv"Harbor")If harbor_id==0ThenASSERT (standalone==Nil) Standalone=True Skynet.Setenv"Standalone","True")Local OK, slave=Pcall (Skynet.NewService,"Cdummy")IfNot OKThen Skynet.Abort ()End Skynet.Name". Slave", slave)ElseIf standaloneThenIfNotPcall (Skynet.NewService,"Cmaster")Then Skynet.Abort ()EndEndLocal OK, slave=Pcall (Skynet.NewService,"Cslave")IfNot OKThen Skynet.Abort ()End Skynet.Name". Slave", slave)EndIf standalonethen local Datacenter = skynet. NewService  "Datacenterd" Skynet. Name ( "Datacenter", DATACENTER)  End Skynet. newservice  "Service_mgr" pcall (Skynet. Newservice,skynet. getenv  "Start" or  "Main" Skynet. Exit () end)             

This script usually determines whether you are starting a master node or a Slave node based on the standalone configuration. If the master node is further passed harbor whether or not you are starting a single-node Skynet network.

In a single-node mode, there is no need to communicate through the built-in harbor mechanism for nodes. But to be compatible (because you still have the possibility to register a global name), you need to start a service called Cdummy, which is responsible for intercepting global name changes to the external broadcast.

In the case of multi-node mode, for the master node, the Cmaster service needs to be started for node scheduling. In addition, each node (including the master node itself) needs to start the Cslave service for message forwarding between nodes, as well as synchronizing global names.

Next on the master node, you also need to start the DataCenter service.

Then, start the management for UniqueService service_mgr .

Finally, it reads the start configuration item from Config and runs as a user-defined service startup portal script. After success, put yourself out.

The start configuration item is the user-defined startup script, and the default value is "main". If you are just trying out Skynet, there may be several different startup scripts, so it is recommended that you write more than one config file and configure different start items inside. There are many such examples under the examples directory.

Skynet startup Process--

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.