mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-10 01:10:29 +08:00
优化安装程序
This commit is contained in:
@@ -12,6 +12,7 @@ func init() {
|
|||||||
Post("/validateDb", new(ValidateDbAction)).
|
Post("/validateDb", new(ValidateDbAction)).
|
||||||
Post("/validateAdmin", new(ValidateAdminAction)).
|
Post("/validateAdmin", new(ValidateAdminAction)).
|
||||||
Post("/install", new(InstallAction)).
|
Post("/install", new(InstallAction)).
|
||||||
|
Post("/status", new(StatusAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -32,7 +33,13 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
|
currentStatusText = ""
|
||||||
|
defer func() {
|
||||||
|
currentStatusText = ""
|
||||||
|
}()
|
||||||
|
|
||||||
// API节点配置
|
// API节点配置
|
||||||
|
currentStatusText = "正在检查API节点配置"
|
||||||
apiNodeMap := maps.Map{}
|
apiNodeMap := maps.Map{}
|
||||||
err := json.Unmarshal(params.ApiNodeJSON, &apiNodeMap)
|
err := json.Unmarshal(params.ApiNodeJSON, &apiNodeMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -40,6 +47,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 数据库
|
// 数据库
|
||||||
|
currentStatusText = "正在检查数据库配置"
|
||||||
dbMap := maps.Map{}
|
dbMap := maps.Map{}
|
||||||
err = json.Unmarshal(params.DbJSON, &dbMap)
|
err = json.Unmarshal(params.DbJSON, &dbMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,6 +55,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 管理员
|
// 管理员
|
||||||
|
currentStatusText = "正在检查管理员配置"
|
||||||
adminMap := maps.Map{}
|
adminMap := maps.Map{}
|
||||||
err = json.Unmarshal(params.AdminJSON, &adminMap)
|
err = json.Unmarshal(params.AdminJSON, &adminMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,6 +65,8 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
// 安装API节点
|
// 安装API节点
|
||||||
mode := apiNodeMap.GetString("mode")
|
mode := apiNodeMap.GetString("mode")
|
||||||
if mode == "new" {
|
if mode == "new" {
|
||||||
|
currentStatusText = "准备启动新API节点"
|
||||||
|
|
||||||
// 整个系统目录结构为:
|
// 整个系统目录结构为:
|
||||||
// edge-admin/
|
// edge-admin/
|
||||||
// edge-api/
|
// edge-api/
|
||||||
@@ -136,7 +147,9 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 开始安装
|
// 开始安装
|
||||||
|
currentStatusText = "正在安装数据库表结构并写入数据"
|
||||||
var resultMap = maps.Map{}
|
var resultMap = maps.Map{}
|
||||||
|
logs.Println("[INSTALL]setup edge-api")
|
||||||
{
|
{
|
||||||
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "setup", "-api-node-protocol=http", "-api-node-host=\""+apiNodeMap.GetString("newHost")+"\"", "-api-node-port=\""+apiNodeMap.GetString("newPort")+"\"")
|
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "setup", "-api-node-protocol=http", "-api-node-host=\""+apiNodeMap.GetString("newHost")+"\"", "-api-node-port=\""+apiNodeMap.GetString("newPort")+"\"")
|
||||||
output := bytes.NewBuffer([]byte{})
|
output := bytes.NewBuffer([]byte{})
|
||||||
@@ -156,7 +169,16 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭正在运行的API节点,防止冲突
|
||||||
|
logs.Println("[INSTALL]stop edge-api")
|
||||||
|
{
|
||||||
|
cmd := exec.Command(apiNodeDir+"/bin/edge-api", "stop")
|
||||||
|
_ = cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
// 启动API节点
|
// 启动API节点
|
||||||
|
currentStatusText = "正在启动API节点"
|
||||||
|
logs.Println("[INSTALL]start edge-api")
|
||||||
{
|
{
|
||||||
cmd := exec.Command(apiNodeDir + "/bin/edge-api")
|
cmd := exec.Command(apiNodeDir + "/bin/edge-api")
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
@@ -183,6 +205,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置管理员
|
// 设置管理员
|
||||||
|
currentStatusText = "正在设置管理员"
|
||||||
client, err := rpc.NewRPCClient(apiConfig)
|
client, err := rpc.NewRPCClient(apiConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
@@ -203,6 +226,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置访问日志保留天数
|
// 设置访问日志保留天数
|
||||||
|
currentStatusText = "正在配置访问日志保留天数"
|
||||||
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
|
var accessLogKeepDays = dbMap.GetInt("accessLogKeepDays")
|
||||||
if accessLogKeepDays > 0 {
|
if accessLogKeepDays > 0 {
|
||||||
var config = &systemconfigs.DatabaseConfig{}
|
var config = &systemconfigs.DatabaseConfig{}
|
||||||
|
|||||||
16
internal/web/actions/default/setup/status.go
Normal file
16
internal/web/actions/default/setup/status.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package setup
|
||||||
|
|
||||||
|
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
|
||||||
|
var currentStatusText = ""
|
||||||
|
|
||||||
|
type StatusAction struct {
|
||||||
|
actionutils.ParentAction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *StatusAction) RunPost(params struct{}) {
|
||||||
|
this.Data["statusText"] = currentStatusText
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
@@ -19,10 +19,10 @@ func (this *ValidateAdminAction) RunPost(params struct {
|
|||||||
}) {
|
}) {
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("adminUsername", params.AdminUsername).
|
Field("adminUsername", params.AdminUsername).
|
||||||
Require("请输入登录用户名").
|
Require("请输入管理员登录用户名").
|
||||||
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能包含英文、数字或下划线").
|
Match(`^[a-zA-Z0-9_]+$`, "用户名中只能包含英文、数字或下划线").
|
||||||
Field("adminPassword", params.AdminPassword).
|
Field("adminPassword", params.AdminPassword).
|
||||||
Require("请输入登录密码").
|
Require("请输入管理员登录密码").
|
||||||
Match(`^[a-zA-Z0-9_]+$`, "密码中只能包含英文、数字或下划线").
|
Match(`^[a-zA-Z0-9_]+$`, "密码中只能包含英文、数字或下划线").
|
||||||
Field("adminPassword2", params.AdminPassword2).
|
Field("adminPassword2", params.AdminPassword2).
|
||||||
Require("请输入确认密码").
|
Require("请输入确认密码").
|
||||||
|
|||||||
@@ -63,6 +63,20 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
width: @width;
|
width: @width;
|
||||||
bottom: 1em;
|
bottom: 1em;
|
||||||
|
|
||||||
|
button {
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-box {
|
||||||
|
position: absolute;
|
||||||
|
top: 3em;
|
||||||
|
left: 15em;
|
||||||
|
right: 15em;
|
||||||
|
bottom: 0;
|
||||||
|
text-align: center;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,18 @@
|
|||||||
width: 50em;
|
width: 50em;
|
||||||
bottom: 1em;
|
bottom: 1em;
|
||||||
}
|
}
|
||||||
|
.install-box .button-group button {
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
.install-box .button-group .status-box {
|
||||||
|
position: absolute;
|
||||||
|
top: 3em;
|
||||||
|
left: 15em;
|
||||||
|
right: 15em;
|
||||||
|
bottom: 0;
|
||||||
|
text-align: center;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
.install-box::-webkit-scrollbar {
|
.install-box::-webkit-scrollbar {
|
||||||
width: 4px;
|
width: 4px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"sources":["@install.less"],"names":[],"mappings":"AAAA;EAGC,WAAA;EACA,eAAA;EACA,SAAA;EACA,kBAAA;EACA,QAAA;EACA,WAAA;EACA,gBAAA;;AATD,YAWC,QAAO;EACN,eAAA;;AAZF,YAeC,QAAO;EACN,YAAA;;AAhBF,YAmBC,QAAO;EACN,YAAA;;AApBF,YAuBC,MACC,GAAE;EACD,WAAA;;AAzBH,YA6BC;EACC,iBAAA;;AA9BF,YA6BC,OAGC;EACC,0BAAA;EACA,2BAAA;;AAlCH,YAsCC;EACC,mBAAA;;AAvCF,YA0CC;EACC,gBAAA;EACA,eAAA;EACA,QAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,kBAAA;EACA,kBAAA;EACA,UAAA;;AAnDF,YAsDC,aAAY;EACX,UAAA;;AAvDF,YA0DC;EACC,eAAA;EACA,SAAA;EACA,kBAAA;EACA,UAAA;EACA,WAAA;EACA,WAAA;;AAIF,YAAY;EACX,UAAA","file":"index.css"}
|
{"version":3,"sources":["@install.less"],"names":[],"mappings":"AAAA;EAGC,WAAA;EACA,eAAA;EACA,SAAA;EACA,kBAAA;EACA,QAAA;EACA,WAAA;EACA,gBAAA;;AATD,YAWC,QAAO;EACN,eAAA;;AAZF,YAeC,QAAO;EACN,YAAA;;AAhBF,YAmBC,QAAO;EACN,YAAA;;AApBF,YAuBC,MACC,GAAE;EACD,WAAA;;AAzBH,YA6BC;EACC,iBAAA;;AA9BF,YA6BC,OAGC;EACC,0BAAA;EACA,2BAAA;;AAlCH,YAsCC;EACC,mBAAA;;AAvCF,YA0CC;EACC,gBAAA;EACA,eAAA;EACA,QAAA;EACA,WAAA;EACA,SAAA;EACA,WAAA;EACA,kBAAA;EACA,kBAAA;EACA,UAAA;;AAnDF,YAsDC,aAAY;EACX,UAAA;;AAvDF,YA0DC;EACC,eAAA;EACA,SAAA;EACA,kBAAA;EACA,UAAA;EACA,WAAA;EACA,WAAA;;AAhEF,YA0DC,cAQC;EACC,WAAA;;AAnEH,YA0DC,cAYC;EACC,kBAAA;EACA,QAAA;EACA,UAAA;EACA,WAAA;EACA,SAAA;EACA,kBAAA;EACA,UAAA;;AAKH,YAAY;EACX,UAAA","file":"index.css"}
|
||||||
@@ -349,6 +349,8 @@
|
|||||||
|
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
|
<div class="status-box"><span class="blue">{{statusText}}</span></div>
|
||||||
|
|
||||||
<button class="ui button" type="button" @click.prevent="goBackAdmin"><i class="icon long arrow left"></i>上一步</button>
|
<button class="ui button" type="button" @click.prevent="goBackAdmin"><i class="icon long arrow left"></i>上一步</button>
|
||||||
<button class="ui button primary" type="submit" v-if="!isInstalling">确认并开始安装</button>
|
<button class="ui button primary" type="submit" v-if="!isInstalling">确认并开始安装</button>
|
||||||
<button class="ui button disabled" type="button" v-if="isInstalling">安装中请耐心等待...</button>
|
<button class="ui button disabled" type="button" v-if="isInstalling">安装中请耐心等待...</button>
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ Tea.context(function () {
|
|||||||
|
|
||||||
this.step = this.STEP_INTRO
|
this.step = this.STEP_INTRO
|
||||||
|
|
||||||
|
this.$delay(function () {
|
||||||
|
this.loadStatusText()
|
||||||
|
})
|
||||||
|
|
||||||
// 介绍
|
// 介绍
|
||||||
this.goIntroNext = function () {
|
this.goIntroNext = function () {
|
||||||
this.step = this.STEP_API
|
this.step = this.STEP_API
|
||||||
@@ -114,4 +118,24 @@ Tea.context(function () {
|
|||||||
window.location = "/"
|
window.location = "/"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.statusText = ""
|
||||||
|
this.loadStatusText = function () {
|
||||||
|
if (!this.isInstalling) {
|
||||||
|
this.statusText = ""
|
||||||
|
this.$delay(function () {
|
||||||
|
this.loadStatusText()
|
||||||
|
}, 1000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.$post(".status")
|
||||||
|
.success(function (resp) {
|
||||||
|
this.statusText = resp.data.statusText
|
||||||
|
})
|
||||||
|
.done(function () {
|
||||||
|
this.$delay(function () {
|
||||||
|
this.loadStatusText()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user