-
Notifications
You must be signed in to change notification settings - Fork 12
/
service.go
58 lines (46 loc) · 1.44 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
* Vestibulum commodo. Ut rhoncus gravida arcu.
*/
package process_master
import (
"os"
"syscall"
"github.com/eolinker/eosc"
"github.com/eolinker/eosc/process-master/cli"
"github.com/eolinker/eosc/service"
grpc_unixsocket "github.com/eolinker/eosc/grpc-unixsocket"
"github.com/eolinker/eosc/log"
"google.golang.org/grpc"
)
// startService 开启master
func (m *Master) startService() error {
addr := service.ServerAddr(os.Getpid(), eosc.ProcessMaster)
// 移除unix socket
syscall.Unlink(addr)
log.Info("start Master :", addr)
l, err := grpc_unixsocket.Listener(addr)
if err != nil {
log.Error("start service error: ", err)
return err
}
grpcServer := grpc.NewServer()
service.RegisterCtiServiceServer(grpcServer, cli.NewMasterCliServer(m.etcdServer))
service.RegisterMasterDispatcherServer(grpcServer, m.dispatcherServe)
go func() {
err := grpcServer.Serve(l)
if err != nil {
log.Error("listen serve error: ", err)
}
}()
log.Info("start service successful")
m.masterSrv = grpcServer
return nil
}
func (m *Master) stopService() {
m.masterSrv.GracefulStop()
//syscall.Unlink(addr)
}