attempt to close the client on signal
This commit is contained in:
parent
61d5902786
commit
5a09866db4
@ -8,7 +8,9 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/envpprof"
|
"github.com/anacrolix/envpprof"
|
||||||
@ -150,6 +152,15 @@ func statsEnabled() bool {
|
|||||||
return *flags.Stats
|
return *flags.Stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exitSignalHandlers(client *torrent.Client) {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
for {
|
||||||
|
log.Printf("close signal received: %+v", <-c)
|
||||||
|
client.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
tagflag.Parse(&flags)
|
tagflag.Parse(&flags)
|
||||||
@ -183,6 +194,8 @@ func main() {
|
|||||||
log.Fatalf("error creating client: %s", err)
|
log.Fatalf("error creating client: %s", err)
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
go exitSignalHandlers(client)
|
||||||
|
|
||||||
// Write status on the root path on the default HTTP muxer. This will be
|
// Write status on the root path on the default HTTP muxer. This will be
|
||||||
// bound to localhost somewhere if GOPPROF is set, thanks to the envpprof
|
// bound to localhost somewhere if GOPPROF is set, thanks to the envpprof
|
||||||
// import.
|
// import.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user