Skip to content

Commit 18eb694

Browse files
committed
refactor: rewrite signal with go-signalcontext
1 parent 173abec commit 18eb694

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Make sure you can clone code. After the fresh image was named and tagged, it wil
7676
2. Deploy core itself
7777

7878
```shell
79-
<cli_execute_path> container deploy --pod <pod_name> [--node <node_name>] --entry core --network <network_name> --image <projecteru2/core>|<your_own_image> --file <core_config_yaml>:/core.yaml [--count <count_num>] [--cpu 0.3 | --mem 1024000000] http://bit.ly/EruCore
79+
<cli_execute_path> workloads deploy --pod <pod_name> [--node <node_name>] --entry core --network <network_name> --image <projecteru2/core>|<your_own_image> --file <core_config_yaml>:/core.yaml [--count <count_num>] [--cpu 0.3 | --mem 1024000000] http://bit.ly/EruCore
8080
```
8181

8282
Now you will find core was started in nodes.

core.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"net/http"
77
_ "net/http/pprof" // nolint
88
"os"
9-
"os/signal"
10-
"syscall"
119

1210
"github.com/projecteru2/core/auth"
1311
"github.com/projecteru2/core/cluster/calcium"
@@ -17,6 +15,7 @@ import (
1715
"github.com/projecteru2/core/utils"
1816
"github.com/projecteru2/core/versioninfo"
1917
"github.com/prometheus/client_golang/prometheus/promhttp"
18+
"github.com/sethvargo/go-signalcontext"
2019
log "github.com/sirupsen/logrus"
2120
cli "github.com/urfave/cli/v2"
2221
"google.golang.org/grpc"
@@ -111,10 +110,11 @@ func serve(c *cli.Context) error {
111110
log.Info("[main] Cluster started successfully.")
112111

113112
// wait for unix signals and try to GracefulStop
114-
sigs := make(chan os.Signal, 1)
115-
signal.Notify(sigs, syscall.SIGINT, syscall.SIGHUP, syscall.SIGTERM)
116-
sig := <-sigs
117-
log.Infof("[main] Get signal %v.", sig)
113+
ctx, cancel := signalcontext.OnInterrupt()
114+
defer cancel()
115+
<-ctx.Done()
116+
117+
log.Info("[main] Interrupt by signal")
118118
close(rpcch)
119119
unregisterService()
120120
grpcServer.GracefulStop()

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/projecteru2/libyavirt v0.0.0-20200831030711-2bb3f2ba0cb7
3232
github.com/prometheus/client_golang v1.7.1
3333
github.com/sanity-io/litter v1.3.0
34+
github.com/sethvargo/go-signalcontext v0.1.0
3435
github.com/sirupsen/logrus v1.6.0
3536
github.com/stretchr/testify v1.6.1
3637
github.com/urfave/cli/v2 v2.2.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ github.com/sanity-io/litter v1.3.0 h1:5ZO+weUsqdSWMUng5JnpkW/Oz8iTXiIdeumhQr1sSj
250250
github.com/sanity-io/litter v1.3.0/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
251251
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
252252
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
253+
github.com/sethvargo/go-signalcontext v0.1.0 h1:3IU7HOlmRXF0PSDf85C4nJ/zjYDjF+DS+LufcKfLvyk=
254+
github.com/sethvargo/go-signalcontext v0.1.0/go.mod h1:PXu9UmR2f7mmp8kEwgkKmaDbxq/PbqixkiC66WIkkWE=
253255
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
254256
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
255257
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=

0 commit comments

Comments
 (0)