File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ import (
5
5
"gin-vue-admin/model"
6
6
"gin-vue-admin/model/response"
7
7
"gin-vue-admin/service"
8
+ "os"
9
+ "os/exec"
10
+ "runtime"
11
+ "strconv"
12
+
8
13
"github.com/gin-gonic/gin"
9
14
"go.uber.org/zap"
10
15
)
@@ -42,7 +47,6 @@ func SetSystemConfig(c *gin.Context) {
42
47
}
43
48
}
44
49
45
- // 本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
46
50
// @Tags System
47
51
// @Summary 重启系统
48
52
// @Security ApiKeyAuth
@@ -51,14 +55,20 @@ func SetSystemConfig(c *gin.Context) {
51
55
// @Success 200 {string} string "{"success":true,"data":{},"msg":"重启系统成功"}"
52
56
// @Router /system/ReloadSystem [post]
53
57
func ReloadSystem (c * gin.Context ) {
54
- var sys model.System
55
- _ = c .ShouldBindJSON (& sys )
56
- if err := service .SetSystemConfig (sys ); err != nil {
58
+ if runtime .GOOS == "windows" {
59
+ response .FailWithMessage ("系统不支持" , c )
60
+ return
61
+ }
62
+ pid := os .Getpid ()
63
+ cmd := exec .Command ("kill" , "-1" , strconv .Itoa (pid ))
64
+ err := cmd .Run ()
65
+ if err != nil {
57
66
global .GVA_LOG .Error ("重启系统失败!" , zap .Any ("err" , err ))
58
67
response .FailWithMessage ("重启系统失败" , c )
59
- } else {
60
- response .OkWithMessage ("重启系统成功" , c )
68
+ return
61
69
}
70
+ response .OkWithMessage ("重启系统成功" , c )
71
+ return
62
72
}
63
73
64
74
// @Tags System
Original file line number Diff line number Diff line change @@ -12,5 +12,6 @@ func InitSystemRouter(Router *gin.RouterGroup) {
12
12
SystemRouter .POST ("getSystemConfig" , v1 .GetSystemConfig ) // 获取配置文件内容
13
13
SystemRouter .POST ("setSystemConfig" , v1 .SetSystemConfig ) // 设置配置文件内容
14
14
SystemRouter .POST ("getServerInfo" , v1 .GetServerInfo ) // 获取服务器信息
15
+ SystemRouter .POST ("reloadSystem" , v1 .ReloadSystem ) // 获取服务器信息
15
16
}
16
17
}
You can’t perform that action at this time.
0 commit comments