🎨添加命令进行服务端重启、启动、停止
This commit is contained in:
parent
259cd39902
commit
a988b66ccd
69
command/wireguard.go
Normal file
69
command/wireguard.go
Normal file
@ -0,0 +1,69 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.ltd/lxh/logger/log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"wireguard-dashboard/repository"
|
||||
)
|
||||
|
||||
// RestartWireguard
|
||||
// @description: 重启wireguard服务端
|
||||
func RestartWireguard() {
|
||||
configPath, err := repository.System().GetServerSetting()
|
||||
if err != nil {
|
||||
log.Errorf("获取服务端配置失败: %v", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if configPath.ConfigFilePath != "" {
|
||||
configPath.ConfigFilePath = strings.Split(configPath.ConfigFilePath, "/")[len(strings.Split(configPath.ConfigFilePath, "/"))-1]
|
||||
}
|
||||
|
||||
if err = exec.Command(fmt.Sprintf("wg-quick down %s", configPath.ConfigFilePath)).Run(); err != nil {
|
||||
log.Errorf("停止wireguard服务端失败: %v", err.Error())
|
||||
}
|
||||
|
||||
if err = exec.Command(fmt.Sprintf("wg-quick up %s", configPath.ConfigFilePath)).Run(); err != nil {
|
||||
log.Errorf("启动wireguard服务端失败: %v", err.Error())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// StopWireguard
|
||||
// @description: 停止服务端
|
||||
func StopWireguard() {
|
||||
configPath, err := repository.System().GetServerSetting()
|
||||
if err != nil {
|
||||
log.Errorf("获取服务端配置失败: %v", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if configPath.ConfigFilePath != "" {
|
||||
configPath.ConfigFilePath = strings.Split(configPath.ConfigFilePath, "/")[len(strings.Split(configPath.ConfigFilePath, "/"))-1]
|
||||
}
|
||||
|
||||
if err = exec.Command(fmt.Sprintf("wg-quick down %s", configPath.ConfigFilePath)).Run(); err != nil {
|
||||
log.Errorf("停止wireguard服务端失败: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// StartWireguard
|
||||
// @description: 启动服务端
|
||||
func StartWireguard() {
|
||||
configPath, err := repository.System().GetServerSetting()
|
||||
if err != nil {
|
||||
log.Errorf("获取服务端配置失败: %v", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if configPath.ConfigFilePath != "" {
|
||||
configPath.ConfigFilePath = strings.Split(configPath.ConfigFilePath, "/")[len(strings.Split(configPath.ConfigFilePath, "/"))-1]
|
||||
}
|
||||
|
||||
if err = exec.Command(fmt.Sprintf("wg-quick up %s", configPath.ConfigFilePath)).Run(); err != nil {
|
||||
log.Errorf("启动wireguard服务端失败: %v", err.Error())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user