mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
launch all the bootstrap services in bootstrap.lua
This commit is contained in:
@@ -592,6 +592,8 @@ harbor_init(struct harbor *h, struct skynet_context *ctx, const char * args) {
|
|||||||
fprintf(stderr, "Harbor: Connect to master failed\n");
|
fprintf(stderr, "Harbor: Connect to master failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
skynet_harbor_start(ctx);
|
||||||
|
|
||||||
h->local_addr = skynet_strdup(local_addr);
|
h->local_addr = skynet_strdup(local_addr);
|
||||||
|
|
||||||
_launch_gate(ctx, local_addr);
|
_launch_gate(ctx, local_addr);
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local launcher = assert(skynet.launch("snlua launcher"))
|
assert(skynet.launch("logger", skynet.getenv "logger"))
|
||||||
|
|
||||||
|
local standalone = skynet.getenv "standalone"
|
||||||
|
local master_addr = skynet.getenv "master"
|
||||||
|
|
||||||
|
if standalone then
|
||||||
|
assert(skynet.launch("master", master_addr))
|
||||||
|
end
|
||||||
|
|
||||||
|
local local_addr = skynet.getenv "address"
|
||||||
|
local harbor_id = skynet.getenv "harbor"
|
||||||
|
|
||||||
|
assert(skynet.launch("harbor",master_addr, local_addr, harbor_id))
|
||||||
|
|
||||||
|
local launcher = assert(skynet.launch("snlua","launcher"))
|
||||||
skynet.name(".launcher", launcher)
|
skynet.name(".launcher", launcher)
|
||||||
|
|
||||||
if skynet.getenv "standalone" then
|
if standalone then
|
||||||
local datacenter = assert(skynet.newservice "datacenterd")
|
local datacenter = assert(skynet.newservice "datacenterd")
|
||||||
skynet.name("DATACENTER", datacenter)
|
skynet.name("DATACENTER", datacenter)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ skynet_harbor_register(struct remote_name *rname) {
|
|||||||
|
|
||||||
int
|
int
|
||||||
skynet_harbor_message_isremote(uint32_t handle) {
|
skynet_harbor_message_isremote(uint32_t handle) {
|
||||||
|
assert(HARBOR != 0);
|
||||||
int h = (handle & ~HANDLE_MASK);
|
int h = (handle & ~HANDLE_MASK);
|
||||||
return h != HARBOR && h !=0;
|
return h != HARBOR && h !=0;
|
||||||
}
|
}
|
||||||
@@ -43,16 +44,7 @@ skynet_harbor_init(int harbor) {
|
|||||||
HARBOR = (unsigned int)harbor << HANDLE_REMOTE_SHIFT;
|
HARBOR = (unsigned int)harbor << HANDLE_REMOTE_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
skynet_harbor_start(const char * master, const char *local) {
|
skynet_harbor_start(void *ctx) {
|
||||||
size_t sz = strlen(master) + strlen(local) + 32;
|
REMOTE = ctx;
|
||||||
char args[sz];
|
|
||||||
sprintf(args, "%s %s %d",master,local,HARBOR >> HANDLE_REMOTE_SHIFT);
|
|
||||||
struct skynet_context * inst = skynet_context_new("harbor",args);
|
|
||||||
if (inst == NULL) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
REMOTE = inst;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int sessio
|
|||||||
void skynet_harbor_register(struct remote_name *rname);
|
void skynet_harbor_register(struct remote_name *rname);
|
||||||
int skynet_harbor_message_isremote(uint32_t handle);
|
int skynet_harbor_message_isremote(uint32_t handle);
|
||||||
void skynet_harbor_init(int harbor);
|
void skynet_harbor_init(int harbor);
|
||||||
int skynet_harbor_start(const char * master, const char *local);
|
void skynet_harbor_start(void * ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,12 +4,8 @@
|
|||||||
struct skynet_config {
|
struct skynet_config {
|
||||||
int thread;
|
int thread;
|
||||||
int harbor;
|
int harbor;
|
||||||
const char * logger;
|
|
||||||
const char * module_path;
|
const char * module_path;
|
||||||
const char * master;
|
|
||||||
const char * local;
|
|
||||||
const char * bootstrap;
|
const char * bootstrap;
|
||||||
const char * standalone;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define THREAD_WORKER 0
|
#define THREAD_WORKER 0
|
||||||
|
|||||||
@@ -115,12 +115,8 @@ main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
config.thread = optint("thread",8);
|
config.thread = optint("thread",8);
|
||||||
config.module_path = optstring("cpath","./cservice/?.so");
|
config.module_path = optstring("cpath","./cservice/?.so");
|
||||||
config.logger = optstring("logger",NULL);
|
|
||||||
config.harbor = optint("harbor", 1);
|
config.harbor = optint("harbor", 1);
|
||||||
config.master = optstring("master","127.0.0.1:2012");
|
|
||||||
config.bootstrap = optstring("bootstrap","snlua bootstrap");
|
config.bootstrap = optstring("bootstrap","snlua bootstrap");
|
||||||
config.local = optstring("address","127.0.0.1:2525");
|
|
||||||
config.standalone = optstring("standalone",NULL);
|
|
||||||
|
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "skynet_handle.h"
|
#include "skynet_handle.h"
|
||||||
#include "skynet_module.h"
|
#include "skynet_module.h"
|
||||||
#include "skynet_timer.h"
|
#include "skynet_timer.h"
|
||||||
#include "skynet_harbor.h"
|
|
||||||
#include "skynet_monitor.h"
|
#include "skynet_monitor.h"
|
||||||
#include "skynet_socket.h"
|
#include "skynet_socket.h"
|
||||||
|
|
||||||
@@ -181,18 +180,15 @@ _start(int thread) {
|
|||||||
free_monitor(m);
|
free_monitor(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
_start_master(const char * master) {
|
|
||||||
struct skynet_context *ctx = skynet_context_new("master", master);
|
|
||||||
if (ctx == NULL)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bootstrap(struct skynet_context * ctx, const char * cmdline) {
|
bootstrap(const char * cmdline) {
|
||||||
if (!skynet_command(ctx, "LAUNCH", cmdline)) {
|
int sz = strlen(cmdline);
|
||||||
fprintf(stderr, "Bootstrap error : %s\n", cmdline);
|
char name[sz+1];
|
||||||
|
char args[sz+1];
|
||||||
|
sscanf(cmdline, "%s %s", name, args);
|
||||||
|
struct skynet_context *ctx = skynet_context_new(name, args);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
skynet_error(NULL, "Bootstrap error : %s\n", cmdline);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,26 +202,7 @@ skynet_start(struct skynet_config * config) {
|
|||||||
skynet_timer_init();
|
skynet_timer_init();
|
||||||
skynet_socket_init();
|
skynet_socket_init();
|
||||||
|
|
||||||
struct skynet_context *ctx;
|
bootstrap(config->bootstrap);
|
||||||
ctx = skynet_context_new("logger", config->logger);
|
|
||||||
if (ctx == NULL) {
|
|
||||||
fprintf(stderr,"launch logger error\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->standalone) {
|
|
||||||
if (_start_master(config->standalone)) {
|
|
||||||
fprintf(stderr, "Init failed : master\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// harbor must be init first
|
|
||||||
if (skynet_harbor_start(config->master , config->local)) {
|
|
||||||
fprintf(stderr, "Init failed : no master\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap(ctx, config->bootstrap);
|
|
||||||
|
|
||||||
_start(config->thread);
|
_start(config->thread);
|
||||||
skynet_socket_free();
|
skynet_socket_free();
|
||||||
|
|||||||
Reference in New Issue
Block a user