2020-07-08 10:09:59 +08:00
|
|
|
package main
|
|
|
|
|
2020-07-08 11:39:36 +08:00
|
|
|
import (
|
2020-10-09 16:59:03 +08:00
|
|
|
"flag"
|
2020-07-08 11:39:36 +08:00
|
|
|
"gokins/comm"
|
2020-09-30 20:26:50 +08:00
|
|
|
"gokins/core"
|
2020-10-02 16:04:26 +08:00
|
|
|
"gokins/mgr"
|
2020-07-08 15:39:23 +08:00
|
|
|
"gokins/route"
|
2020-10-12 20:00:26 +08:00
|
|
|
"gokins/service"
|
2020-09-30 20:26:50 +08:00
|
|
|
"gokins/service/dbService"
|
2020-07-08 15:39:23 +08:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-09-30 20:26:50 +08:00
|
|
|
|
2020-10-20 09:54:05 +08:00
|
|
|
ruisIo "github.com/mgr9525/go-ruisutil/ruisio"
|
|
|
|
|
2020-09-30 20:26:50 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2020-07-08 11:39:36 +08:00
|
|
|
)
|
|
|
|
|
2020-10-12 20:00:26 +08:00
|
|
|
var (
|
|
|
|
clearPass = ""
|
|
|
|
mvData = ""
|
2020-10-20 18:00:39 +08:00
|
|
|
upgrade = false
|
2020-10-12 20:00:26 +08:00
|
|
|
)
|
2020-10-11 12:25:41 +08:00
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
func init() {
|
|
|
|
path, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
println("path err:" + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println("path:" + path)
|
2020-10-09 16:59:03 +08:00
|
|
|
comm.Path = path
|
2020-07-08 15:39:23 +08:00
|
|
|
dir, err := filepath.Abs(filepath.Dir(path))
|
|
|
|
if err != nil {
|
|
|
|
println("dir err:" + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println("dir:" + dir)
|
2020-10-09 16:59:03 +08:00
|
|
|
flag.StringVar(&comm.Dir, "d", dir, "数据目录")
|
2020-10-09 17:10:13 +08:00
|
|
|
flag.StringVar(&comm.Host, "bind", ":8030", "绑定地址")
|
2020-10-13 13:01:39 +08:00
|
|
|
flag.IntVar(&comm.RunTaskLen, "rln", 5, "同时执行的流水线数量")
|
2020-10-12 20:00:26 +08:00
|
|
|
flag.StringVar(&clearPass, "clp", "", "清除某个用户密码(请先关闭服务在执行)")
|
2020-10-20 18:00:39 +08:00
|
|
|
flag.StringVar(&mvData, "mvdata", "", "转移某个库数据到本地(目前不转移运行日志记录)")
|
|
|
|
flag.BoolVar(&upgrade, "up", false, "升级数据库(迁移流水线,触发器)")
|
2020-10-09 16:59:03 +08:00
|
|
|
flag.Parse()
|
2020-07-08 11:39:36 +08:00
|
|
|
comm.Gin = gin.Default()
|
2020-07-08 15:39:23 +08:00
|
|
|
}
|
|
|
|
func main() {
|
2020-10-20 18:00:39 +08:00
|
|
|
if upgrade {
|
2020-10-21 13:37:34 +08:00
|
|
|
os.RemoveAll(comm.Dir + "/data/logs")
|
2020-10-20 19:09:38 +08:00
|
|
|
if !ruisIo.PathExists(comm.Dir + "/db.dat") {
|
|
|
|
println("未找到原有数据库")
|
|
|
|
return
|
2020-10-20 18:00:39 +08:00
|
|
|
}
|
2020-10-20 19:09:38 +08:00
|
|
|
os.Remove(comm.Dir + "/db.bak")
|
|
|
|
os.Rename(comm.Dir+"/db.dat", comm.Dir+"/db.bak")
|
2020-10-20 18:00:39 +08:00
|
|
|
}
|
2020-10-20 09:54:05 +08:00
|
|
|
if !ruisIo.PathExists(comm.Dir + "/data") {
|
|
|
|
err := os.MkdirAll(comm.Dir+"/data", 0755)
|
|
|
|
if err != nil {
|
|
|
|
println("Mkdir data err:" + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 15:39:23 +08:00
|
|
|
err := comm.InitDb()
|
|
|
|
if err != nil {
|
|
|
|
println("InitDb err:" + err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-10-12 20:00:26 +08:00
|
|
|
if clearPass != "" {
|
|
|
|
service.ClearUPass(clearPass)
|
2020-10-11 12:25:41 +08:00
|
|
|
return
|
|
|
|
}
|
2020-10-12 20:00:26 +08:00
|
|
|
if mvData != "" {
|
|
|
|
service.MoveData(mvData)
|
|
|
|
return
|
|
|
|
}
|
2020-10-20 18:00:39 +08:00
|
|
|
if upgrade {
|
|
|
|
service.Upgrade()
|
|
|
|
return
|
|
|
|
}
|
2020-10-12 20:00:26 +08:00
|
|
|
|
|
|
|
runWeb()
|
|
|
|
}
|
|
|
|
func runWeb() {
|
2020-09-30 20:26:50 +08:00
|
|
|
jwtKey := dbService.GetParam("jwt-key")
|
|
|
|
jkey := jwtKey.GetString("key")
|
|
|
|
if jkey == "" {
|
|
|
|
jkey = core.RandomString(32)
|
|
|
|
jwtKey.Set("key", jkey)
|
|
|
|
dbService.SetParam("jwt-key", jwtKey)
|
|
|
|
}
|
|
|
|
core.JwtKey = jkey
|
2020-07-08 15:39:23 +08:00
|
|
|
route.Init()
|
2020-10-02 16:04:26 +08:00
|
|
|
mgr.ExecMgr.Start()
|
2020-10-20 17:23:23 +08:00
|
|
|
mgr.TriggerMgr.Start()
|
2020-10-12 20:00:26 +08:00
|
|
|
err := comm.Gin.Run(comm.Host)
|
2020-07-08 12:05:33 +08:00
|
|
|
if err != nil {
|
2020-07-08 15:39:23 +08:00
|
|
|
println("gin run err:" + err.Error())
|
2020-07-08 12:05:33 +08:00
|
|
|
}
|
2020-10-02 16:04:26 +08:00
|
|
|
mgr.Cancel()
|
2020-07-08 10:09:59 +08:00
|
|
|
}
|