Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR : Graceful handling on SIGTERM and SIGINT (#348) #349

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading