新增单进程模式
This commit is contained in:
1 parent
669a524153
commit
6136e57919
73 files changed
+1900
-153
No files matched your search
@@ -0,0 +1,120 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/cmd/nats"
|
||||
cfg "hk4e/common/config"
|
||||
dispatchapp "hk4e/dispatch/app"
|
||||
gateapp "hk4e/gate/app"
|
||||
gmapp "hk4e/gm/app"
|
||||
gsapp "hk4e/gs/app"
|
||||
nodeapp "hk4e/node/app"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
cfg.InitConfig(*config)
|
||||
|
||||
logger.InitLogger("standalone")
|
||||
logger.Warn("standalone start")
|
||||
defer func() {
|
||||
logger.Warn("standalone exit")
|
||||
logger.CloseLogger()
|
||||
}()
|
||||
|
||||
stopChan := make(chan struct{})
|
||||
|
||||
ctxNats, cancelNats := context.WithCancel(context.Background())
|
||||
ctxNode, cancelNode := context.WithCancel(context.Background())
|
||||
ctxDispatch, cancelDispatch := context.WithCancel(context.Background())
|
||||
ctxGate, cancelGate := context.WithCancel(context.Background())
|
||||
ctxGs, cancelGs := context.WithCancel(context.Background())
|
||||
ctxGm, cancelGm := context.WithCancel(context.Background())
|
||||
|
||||
go func() {
|
||||
err := nats.RunNatsServer(ctxNats)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
stopChan <- struct{}{}
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
go func() {
|
||||
err := nodeapp.Run(ctxNode)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cancelNats()
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
go func() {
|
||||
err := dispatchapp.Run(ctxDispatch)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cancelNode()
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
go func() {
|
||||
err := gateapp.Run(ctxGate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cancelDispatch()
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
go func() {
|
||||
err := gsapp.Run(ctxGs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cancelGate()
|
||||
}()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
go func() {
|
||||
err := gmapp.Run(ctxGm)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cancelGs()
|
||||
}()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
select {
|
||||
case s := <-c:
|
||||
logger.Warn("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
cancelGm()
|
||||
<-stopChan
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user