Quellcode durchsuchen

增加升级脚本

zou.yingbin vor 4 Jahren
Ursprung
Commit
9eb1e90e2d
3 geänderte Dateien mit 87 neuen und 0 gelöschten Zeilen
  1. 67 0
      controllers/other/update.go
  2. 19 0
      res/sh/upmtpgo.sh
  3. 1 0
      routers/router.go

+ 67 - 0
controllers/other/update.go

@@ -0,0 +1,67 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/10/20 15:20
+* @Modify  : 2021/10/20 15:20
+* @Note    : 生成用于内网升级的.sh脚本
+ */
+
+package other
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"net/http"
+	"os"
+	"path/filepath"
+	"strings"
+)
+
+// MakeUpdateScript 生成脚本
+func MakeUpdateScript(c *gin.Context) {
+	if createsh() {
+		c.String(http.StatusOK, "创建升级脚本成功, 请手动执行升级脚本update.sh(在程序所在目录), 升级会保留原有的config.xml,且重启服务.")
+	} else {
+		c.String(http.StatusBadRequest, "创建脚本失败, 可能是权限不足")
+	}
+}
+
+// 生成update.sh文件
+func createsh() bool {
+	dir := ""
+	if str, err := filepath.Abs(filepath.Dir(os.Args[0])); err == nil {
+		dir = strings.Replace(str, "\\", "/", -1)
+		fmt.Println("currentDir:", dir)
+	} else {
+		return false
+	}
+
+	sh :=
+		"# author : zyb\n" +
+			"# note   : 在程序运行目录执行此脚本, 升级go服务到最新构建的版本。升级完成自动重启go服务\n" +
+			"# --------------------------------------------------------------------\n" +
+			"\n" +
+			"mkdir -p upmtpgo\n" +
+			"cd upmtpgo\n" +
+			"rm -f console\n" +
+			"wget -c http://192.168.30.153:8080/view/mtp2.0_release/job/mtp2.0_QueryService_linux/label=192.168.31.56/lastBuild/console\n" +
+			"filename=`grep -o -w -m1 mtp2.*zip console`\n" +
+			"wget -c http://192.168.30.153/share/build/mtp2.0_release/$filename\n" +
+			"rm -rf queryservice\n" +
+			"unzip $filename -d queryservice\n" +
+			"cp ../config/config.xml ./queryservice/config/config.xml\n" +
+			"cp -rf ./queryservice/* ../\n" +
+			"cd ..\n" +
+			"rm -rf upmtpgo\n" +
+			"pkill QueryService\n" +
+			"nohup `pwd`/QueryService &"
+
+	// 创建文件
+	if f, err := os.Create(dir + "/update.sh"); err == nil {
+		_, err = f.Write([]byte(sh))
+		f.Chmod(777)
+		f.Close()
+	} else {
+		return false
+	}
+	return true
+}

+ 19 - 0
res/sh/upmtpgo.sh

@@ -0,0 +1,19 @@
+# author : zyb
+# create : 2021-10-20
+# note   : 在程序运行目录执行此脚本, 升级go服务到最新构建的版本。升级完成自动重启go服务
+# --------------------------------------------------------------------
+
+mkdir -p upmtpgo
+cd upmtpgo
+rm -f console
+wget -c http://192.168.30.153:8080/view/mtp2.0_release/job/mtp2.0_QueryService_linux/label=192.168.31.56/lastBuild/console
+filename=`grep -o -w -m1 mtp2.*zip console`
+wget -c http://192.168.30.153/share/build/mtp2.0_release/$filename
+rm -rf queryservice
+unzip $filename -d queryservice
+cp ../config/config.xml ./queryservice/config/config.xml
+cp -rf ./queryservice/* ../
+cd ..
+rm -rf upmtpgo
+pkill QueryService
+nohup `pwd`/QueryService &

+ 1 - 0
routers/router.go

@@ -56,6 +56,7 @@ func InitRouter() *gin.Engine {
 		r.GET("/debug/log", other.LogList)
 		r.GET("/debug/log/view", other.LogView)
 		r.GET("/debug/download", other.DownloadFile)
+		r.GET("/debug/update", other.MakeUpdateScript)
 	}
 	// 终端配置
 	r.GET("/cfg", cfg.QueryCfg)