Skip to content

Commit

Permalink
Merge pull request #349 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR : Graceful handling on SIGTERM and SIGINT (#348)
  • Loading branch information
UltraInstinct14 authored Jul 10, 2023
2 parents 177819d + 69c4dc2 commit dad68cb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
33 changes: 26 additions & 7 deletions api/restapi/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,34 @@ func DpEbpfInit(clusterEn bool, nodeNum int, rssEn bool, logLevel tk.LogLevelT)
return ne
}

// DpEbpfUnInit - uninitialize the ebpf dp subsystem
func (e *DpEbpfH) DpEbpfUnInit() {

e.tDone <- true
e.ToFinCh <- 1

// Make sure to unload eBPF programs
ifList, err := net.Interfaces()
if err != nil {
return
}

for _, intf := range ifList {

tk.LogIt(tk.LogInfo, "ebpf unload - %s\n", intf.Name)
ifStr := C.CString(intf.Name)
section := C.CString(string(C.TC_LL_SEC_DEFAULT))
if e.RssEn {
xSection := C.CString(string(C.XDP_LL_SEC_DEFAULT))
C.llb_dp_link_attach(ifStr, xSection, C.LL_BPF_MOUNT_XDP, 1)
C.free(unsafe.Pointer(xSection))
}
C.llb_dp_link_attach(ifStr, section, C.LL_BPF_MOUNT_TC, 1)
C.free(unsafe.Pointer(ifStr))
C.free(unsafe.Pointer(section))
}
}

func convNetIP2DPv6Addr(addr unsafe.Pointer, goIP net.IP) {
aPtr := (*C.uchar)(addr)
for bp := 0; bp < 16; bp++ {
Expand Down
10 changes: 7 additions & 3 deletions loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
apiserver "github.com/loxilb-io/loxilb/api"
nlp "github.com/loxilb-io/loxilb/api/loxinlp"
prometheus "github.com/loxilb-io/loxilb/api/prometheus"
restapi "github.com/loxilb-io/loxilb/api/restapi"
cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
tk "github.com/loxilb-io/loxilib"
Expand Down Expand Up @@ -179,8 +180,12 @@ func loxiNetTicker() {
try++
}
} else if sig == syscall.SIGHUP {
fmt.Printf("SIGHUP called\n")
tk.LogIt(tk.LogCritical, "SIGHUP received\n")
pprof.StopCPUProfile()
} else if sig == syscall.SIGINT || sig == syscall.SIGTERM {
tk.LogIt(tk.LogCritical, "Shutdown on sig %v\n", sig)
mh.dpEbpf.DpEbpfUnInit()
restapi.ServerSigShutOk()
}
case t := <-mh.ticker.C:
tk.LogIt(-1, "Tick at %v\n", t)
Expand Down Expand Up @@ -225,8 +230,7 @@ func loxiNetInit() {
mh.sumDis = opts.Opts.CSumDisable
mh.pProbe = opts.Opts.PassiveEPProbe
mh.sigCh = make(chan os.Signal, 5)
signal.Notify(mh.sigCh, os.Interrupt, syscall.SIGCHLD)
signal.Notify(mh.sigCh, os.Interrupt, syscall.SIGHUP)
signal.Notify(mh.sigCh, os.Interrupt, syscall.SIGCHLD, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)

// Check if profiling is enabled
if opts.Opts.CPUProfile != "none" {
Expand Down

0 comments on commit dad68cb

Please sign in to comment.