mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 10:31:29 +00:00
Handle SIGHUP signal
This commit is contained in:
parent
9f6ff54a76
commit
aa8cdaee22
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
runtimeDebug "runtime/debug"
|
runtimeDebug "runtime/debug"
|
||||||
|
@ -13,7 +12,6 @@ import (
|
||||||
"github.com/sagernet/sing-box/common/json"
|
"github.com/sagernet/sing-box/common/json"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing/common/debug"
|
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -81,21 +79,19 @@ func create() (*box.Box, context.CancelFunc, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
|
for {
|
||||||
instance, cancel, err := create()
|
instance, cancel, err := create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if debug.Enabled {
|
|
||||||
http.HandleFunc("/debug/close", func(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
cancel()
|
|
||||||
instance.Close()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
runtimeDebug.FreeOSMemory()
|
runtimeDebug.FreeOSMemory()
|
||||||
osSignals := make(chan os.Signal, 1)
|
osSignals := make(chan os.Signal, 1)
|
||||||
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
<-osSignals
|
osSignal := <-osSignals
|
||||||
cancel()
|
cancel()
|
||||||
instance.Close()
|
instance.Close()
|
||||||
|
if osSignal != syscall.SIGHUP {
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue