This commit is contained in:
parent
1e8e1c0196
commit
207e568099
@ -3,6 +3,7 @@ package command
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitee.ltd/lxh/logger/log"
|
"gitee.ltd/lxh/logger/log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"wireguard-dashboard/repository"
|
"wireguard-dashboard/repository"
|
||||||
@ -47,8 +48,13 @@ func RestartWireguard(isAsync bool) {
|
|||||||
func StopWireguard() {
|
func StopWireguard() {
|
||||||
configFileName := getConfigFileName()
|
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())
|
log.Errorf("停止wireguard[%s]服务端失败: %v", configFileName, err.Error())
|
||||||
|
} else {
|
||||||
|
log.Infof("停止wireguard[%s]服务端成功", configFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -59,9 +65,13 @@ func StopWireguard() {
|
|||||||
func StartWireguard() {
|
func StartWireguard() {
|
||||||
configFileName := getConfigFileName()
|
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())
|
log.Errorf("启动wireguard[%s]服务端失败: %v", configFileName, err.Error())
|
||||||
|
} else {
|
||||||
|
log.Infof("启动wireguard[%s]服务端成功", configFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,6 @@ func (w wireguard) Apply(templateFilePath, configFilePath string, data any) (err
|
|||||||
switch config.Config.Wireguard.ListenConfig {
|
switch config.Config.Wireguard.ListenConfig {
|
||||||
case "auto":
|
case "auto":
|
||||||
w.watchListConfig(configFilePath)
|
w.watchListConfig(configFilePath)
|
||||||
case "hand": // 手动操作
|
|
||||||
command.RestartWireguard(true)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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:
|
case _, ok := <-watcher.Errors:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user