From 207e5680997b2e7883ba0b00c66f06816e403cd2 Mon Sep 17 00:00:00 2001 From: coward Date: Wed, 5 Jun 2024 11:40:34 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command/wireguard.go | 16 +++++++++++++--- component/wireguard.go | 5 +---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/command/wireguard.go b/command/wireguard.go index 1001b0f..ee8763b 100644 --- a/command/wireguard.go +++ b/command/wireguard.go @@ -3,6 +3,7 @@ package command import ( "fmt" "gitee.ltd/lxh/logger/log" + "os" "os/exec" "strings" "wireguard-dashboard/repository" @@ -47,8 +48,13 @@ func RestartWireguard(isAsync bool) { func StopWireguard() { configFileName := getConfigFileName() - if err := exec.Command("/bin/sh", "-c", fmt.Sprintf("wg-quick down %s", configFileName)).Run(); err != nil { + cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("wg-quick down %s", configFileName)) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { log.Errorf("停止wireguard[%s]服务端失败: %v", configFileName, err.Error()) + } else { + log.Infof("停止wireguard[%s]服务端成功", configFileName) } return @@ -59,9 +65,13 @@ func StopWireguard() { func StartWireguard() { configFileName := getConfigFileName() - if err := exec.Command("/bin/sh", "-c", fmt.Sprintf("wg-quick up %s", configFileName)).Run(); err != nil { + cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("wg-quick up %s", configFileName)) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { log.Errorf("启动wireguard[%s]服务端失败: %v", configFileName, err.Error()) + } else { + log.Infof("启动wireguard[%s]服务端成功", configFileName) } - return } diff --git a/component/wireguard.go b/component/wireguard.go index dcf001a..781bb29 100644 --- a/component/wireguard.go +++ b/component/wireguard.go @@ -36,9 +36,6 @@ func (w wireguard) Apply(templateFilePath, configFilePath string, data any) (err switch config.Config.Wireguard.ListenConfig { case "auto": w.watchListConfig(configFilePath) - case "hand": // 手动操作 - command.RestartWireguard(true) - } return nil @@ -72,7 +69,7 @@ func (wireguard) watchListConfig(filePath string) { } // 打印监听事件 - log.Errorf("监听事件是:%s", event.String()) + log.Infof("监听事件是:%s", event.String()) case _, ok := <-watcher.Errors: if !ok { return