mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 13:35:23 +00:00
Add handling for closing the socket
This commit is contained in:
parent
b91c115ade
commit
9954a3c599
15
app.go
15
app.go
@ -10,9 +10,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
@ -352,6 +354,19 @@ func (h *Headscale) Serve() error {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle common process-killing signals so we can gracefully shut down:
|
||||||
|
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):
|
||||||
|
socketListener.Close()
|
||||||
|
// And we're done:
|
||||||
|
os.Exit(0)
|
||||||
|
}(sigc)
|
||||||
|
|
||||||
networkListener, err := net.Listen("tcp", h.cfg.Addr)
|
networkListener, err := net.Listen("tcp", h.cfg.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user