mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-26 21:21:54 +08:00
fix: correctly close the listener
This commit is contained in:
+17
@@ -4,7 +4,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v "github.com/spf13/viper"
|
v "github.com/spf13/viper"
|
||||||
@@ -66,6 +69,20 @@ set WD_CERT.`,
|
|||||||
lnet = "tcp"
|
lnet = "tcp"
|
||||||
}
|
}
|
||||||
listener, err := net.Listen(lnet, laddr)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user