Skip to content

Commit

Permalink
fix: correctly close the listener
Browse files Browse the repository at this point in the history
  • Loading branch information
zmaplex committed Jul 18, 2024
1 parent f0ca85e commit 9433dbd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"log"
"net"
"net/http"
"os"
"os/signal"
"strings"
"syscall"

"github.com/spf13/cobra"
v "github.com/spf13/viper"
Expand Down Expand Up @@ -66,6 +69,20 @@ set WD_CERT.`,
lnet = "tcp"
}
listener, err := net.Listen(lnet, laddr)

sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM)

go func(c chan os.Signal) {
// Wait for a SIGINT or SIGKILL:
sig := <-c
log.Printf("Caught signal %s: shutting down.", sig)
// Stop listening (and unlink the socket if unix type):
listener.Close()
// And we're done:
os.Exit(0)
}(sigc)

if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 9433dbd

Please sign in to comment.