From 8d6f7008389d820d144df0339ceaa43913b07674 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Wed, 12 May 2021 11:53:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=88=9B=E5=BB=BA=E8=B7=AF=E7=94=B1=E5=90=8E=E9=87=8D?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 - server/api/v1/sys_system.go - server/config.yaml - server/config/auto_code.go - server/service/sys_auto_code.go 新增 - server/utils/reload.go --- server/api/v1/sys_system.go | 13 ++----------- server/config.yaml | 1 + server/config/auto_code.go | 27 ++++++++++++++------------- server/service/sys_auto_code.go | 5 +++++ server/utils/reload.go | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 server/utils/reload.go diff --git a/server/api/v1/sys_system.go b/server/api/v1/sys_system.go index dbf6a5b7..b18fe759 100644 --- a/server/api/v1/sys_system.go +++ b/server/api/v1/sys_system.go @@ -5,10 +5,7 @@ import ( "gin-vue-admin/model" "gin-vue-admin/model/response" "gin-vue-admin/service" - "os" - "os/exec" - "runtime" - "strconv" + "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" @@ -54,13 +51,7 @@ func SetSystemConfig(c *gin.Context) { // @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}" // @Router /system/reloadSystem [post] 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 { global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err)) response.FailWithMessage("重启系统失败", c) diff --git a/server/config.yaml b/server/config.yaml index 7d005764..fb77272f 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -70,6 +70,7 @@ local: # autocode configuration autocode: + transfer-restart: true root: "" server: /server server-api: /api/v1 diff --git a/server/config/auto_code.go b/server/config/auto_code.go index 18cd32f6..f941e398 100644 --- a/server/config/auto_code.go +++ b/server/config/auto_code.go @@ -1,17 +1,18 @@ package config type Autocode struct { - Root string `mapstructure:"root" json:"root" yaml:"root"` - Server string `mapstructure:"server" json:"server" yaml:"server"` - SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"` - SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"` - SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"` - SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"` - SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"` - SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"` - Web string `mapstructure:"web" json:"web" yaml:"web"` - WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"` - WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"` - WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"` - WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"` + TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"` + Root string `mapstructure:"root" json:"root" yaml:"root"` + Server string `mapstructure:"server" json:"server" yaml:"server"` + SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"` + SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"` + SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"` + SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"` + SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"` + SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"` + Web string `mapstructure:"web" json:"web" yaml:"web"` + WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"` + WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"` + WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"` + WFlow string `mapstructure:"web-flow" json:"webFlow" yaml:"web-flow"` } diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 835b02bd..4e529ecb 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -146,6 +146,11 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) { if err != nil { return err } + if global.GVA_CONFIG.AutoCode.TransferRestart { + go func() { + _ = utils.Reload() + }() + } return errors.New("创建代码成功并移动文件成功") } else { // 打包 if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { diff --git a/server/utils/reload.go b/server/utils/reload.go new file mode 100644 index 00000000..de5499bf --- /dev/null +++ b/server/utils/reload.go @@ -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() +} -- GitLab