瀏覽代碼

Check configuration before reload

世界 3 年之前
父節點
當前提交
88469d4aaa
共有 1 個文件被更改,包括 17 次插入7 次删除
  1. 17 7
      cmd/sing-box/cmd_run.go

+ 17 - 7
cmd/sing-box/cmd_run.go

@@ -79,19 +79,29 @@ func create() (*box.Box, context.CancelFunc, error) {
 }
 
 func run() error {
+	osSignals := make(chan os.Signal, 1)
+	signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
 	for {
 		instance, cancel, err := create()
 		if err != nil {
 			return err
 		}
 		runtimeDebug.FreeOSMemory()
-		osSignals := make(chan os.Signal, 1)
-		signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
-		osSignal := <-osSignals
-		cancel()
-		instance.Close()
-		if osSignal != syscall.SIGHUP {
-			return nil
+		for {
+			osSignal := <-osSignals
+			if osSignal == syscall.SIGHUP {
+				err = check()
+				if err != nil {
+					log.Error(E.Cause(err, "reload service"))
+					continue
+				}
+			}
+			cancel()
+			instance.Close()
+			if osSignal != syscall.SIGHUP {
+				return nil
+			}
+			break
 		}
 	}
 }