奇淼(piexlmax
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
40 additions and
24 deletions
-
server/api/v1/sys_system.go
-
server/config.yaml
-
server/config/auto_code.go
-
server/service/sys_auto_code.go
-
server/utils/reload.go
|
@ -5,10 +5,7 @@ import ( |
|
|
"gin-vue-admin/model" |
|
|
"gin-vue-admin/model" |
|
|
"gin-vue-admin/model/response" |
|
|
"gin-vue-admin/model/response" |
|
|
"gin-vue-admin/service" |
|
|
"gin-vue-admin/service" |
|
|
"os" |
|
|
|
|
|
"os/exec" |
|
|
|
|
|
"runtime" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
|
|
|
"gin-vue-admin/utils" |
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/gin-gonic/gin" |
|
|
"go.uber.org/zap" |
|
|
"go.uber.org/zap" |
|
@ -54,13 +51,7 @@ func SetSystemConfig(c *gin.Context) { |
|
|
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
|
|
|
// @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}"
|
|
|
// @Router /system/reloadSystem [post]
|
|
|
// @Router /system/reloadSystem [post]
|
|
|
func ReloadSystem(c *gin.Context) { |
|
|
func ReloadSystem(c *gin.Context) { |
|
|
if runtime.GOOS == "windows" { |
|
|
|
|
|
response.FailWithMessage("系统不支持", c) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
pid := os.Getpid() |
|
|
|
|
|
cmd := exec.Command("kill", "-1", strconv.Itoa(pid)) |
|
|
|
|
|
err := cmd.Run() |
|
|
|
|
|
|
|
|
err := utils.Reload() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err)) |
|
|
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err)) |
|
|
response.FailWithMessage("重启系统失败", c) |
|
|
response.FailWithMessage("重启系统失败", c) |
|
|
|
@ -70,6 +70,7 @@ local: |
|
|
|
|
|
|
|
|
# autocode configuration |
|
|
# autocode configuration |
|
|
autocode: |
|
|
autocode: |
|
|
|
|
|
transfer-restart: true |
|
|
root: "" |
|
|
root: "" |
|
|
server: /server |
|
|
server: /server |
|
|
server-api: /api/v1 |
|
|
server-api: /api/v1 |
|
|
|
@ -1,6 +1,7 @@ |
|
|
package config |
|
|
package config |
|
|
|
|
|
|
|
|
type Autocode struct { |
|
|
type Autocode struct { |
|
|
|
|
|
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"` |
|
|
Root string `mapstructure:"root" json:"root" yaml:"root"` |
|
|
Root string `mapstructure:"root" json:"root" yaml:"root"` |
|
|
Server string `mapstructure:"server" json:"server" yaml:"server"` |
|
|
Server string `mapstructure:"server" json:"server" yaml:"server"` |
|
|
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"` |
|
|
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"` |
|
|
|
@ -146,6 +146,11 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) { |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
if global.GVA_CONFIG.AutoCode.TransferRestart { |
|
|
|
|
|
go func() { |
|
|
|
|
|
_ = utils.Reload() |
|
|
|
|
|
}() |
|
|
|
|
|
} |
|
|
return errors.New("创建代码成功并移动文件成功") |
|
|
return errors.New("创建代码成功并移动文件成功") |
|
|
} else { // 打包
|
|
|
} else { // 打包
|
|
|
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { |
|
|
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { |
|
|
|
@ -0,0 +1,18 @@ |
|
|
|
|
|
package utils |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"errors" |
|
|
|
|
|
"os" |
|
|
|
|
|
"os/exec" |
|
|
|
|
|
"runtime" |
|
|
|
|
|
"strconv" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Reload() error { |
|
|
|
|
|
if runtime.GOOS == "windows" { |
|
|
|
|
|
return errors.New("系统不支持") |
|
|
|
|
|
} |
|
|
|
|
|
pid := os.Getpid() |
|
|
|
|
|
cmd := exec.Command("kill", "-1", strconv.Itoa(pid)) |
|
|
|
|
|
return cmd.Run() |
|
|
|
|
|
} |