From 18f0f13cd0a68c6e02a1e44e3aa57c6695fb4d79 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 11 Jan 2021 18:15:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E5=8F=AF=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEsystemd=E7=B3=BB=E7=BB=9F=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/clusters/cluster/settings/init.go | 6 ++ .../cluster/settings/services/index.go | 77 +++++++++++++++++++ .../cluster/settings/services/status.go | 37 +++++++++ .../clusters/clusterutils/cluster_helper.go | 5 ++ .../web/actions/default/clusters/create.go | 21 ++++- web/public/js/components/common/checkbox.js | 9 ++- .../cluster/settings/services/@menu.html | 4 + .../cluster/settings/services/index.html | 23 ++++++ .../cluster/settings/services/index.js | 3 + .../cluster/settings/services/status.html | 37 +++++++++ .../cluster/settings/services/status.js | 22 ++++++ web/views/@default/clusters/create.html | 7 ++ 12 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 internal/web/actions/default/clusters/cluster/settings/services/index.go create mode 100644 internal/web/actions/default/clusters/cluster/settings/services/status.go create mode 100644 web/views/@default/clusters/cluster/settings/services/@menu.html create mode 100644 web/views/@default/clusters/cluster/settings/services/index.html create mode 100644 web/views/@default/clusters/cluster/settings/services/index.js create mode 100644 web/views/@default/clusters/cluster/settings/services/status.html create mode 100644 web/views/@default/clusters/cluster/settings/services/status.js diff --git a/internal/web/actions/default/clusters/cluster/settings/init.go b/internal/web/actions/default/clusters/cluster/settings/init.go index f59cfe1b..24fd85b8 100644 --- a/internal/web/actions/default/clusters/cluster/settings/init.go +++ b/internal/web/actions/default/clusters/cluster/settings/init.go @@ -4,6 +4,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/cache" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/services" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/toa" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf" clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils" @@ -37,6 +38,11 @@ func init() { Prefix("/clusters/cluster/settings/toa"). GetPost("", new(toa.IndexAction)). + // 系统服务设置 + Prefix("/clusters/cluster/settings/services"). + GetPost("", new(services.IndexAction)). + GetPost("/status", new(services.StatusAction)). + EndAll() }) } diff --git a/internal/web/actions/default/clusters/cluster/settings/services/index.go b/internal/web/actions/default/clusters/cluster/settings/services/index.go new file mode 100644 index 00000000..2d714970 --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/services/index.go @@ -0,0 +1,77 @@ +package services + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "setting") + this.SecondMenu("service") +} + +func (this *IndexAction) RunGet(params struct { + ClusterId int64 +}) { + serviceParamsResp, err := this.RPC().NodeClusterRPC().FindNodeClusterSystemService(this.AdminContext(), &pb.FindNodeClusterSystemServiceRequest{ + NodeClusterId: params.ClusterId, + Type: nodeconfigs.SystemServiceTypeSystemd, + }) + if err != nil { + this.ErrorPage(err) + return + } + + paramsJSON := serviceParamsResp.ParamsJSON + if len(paramsJSON) == 0 { + this.Data["systemdIsOn"] = false + } else { + config := &nodeconfigs.SystemdServiceConfig{} + err = json.Unmarshal(paramsJSON, config) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["systemdIsOn"] = config.IsOn + } + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + ClusterId int64 + SystemdIsOn bool + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + defer this.CreateLogInfo("修改集群 %d 的系统服务设置", params.ClusterId) + + serviceParams := &nodeconfigs.SystemdServiceConfig{ + IsOn: params.SystemdIsOn, + } + serviceParamsJSON, err := json.Marshal(serviceParams) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().NodeClusterRPC().UpdateNodeClusterSystemService(this.AdminContext(), &pb.UpdateNodeClusterSystemServiceRequest{ + NodeClusterId: params.ClusterId, + Type: nodeconfigs.SystemServiceTypeSystemd, + ParamsJSON: serviceParamsJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/clusters/cluster/settings/services/status.go b/internal/web/actions/default/clusters/cluster/settings/services/status.go new file mode 100644 index 00000000..bcc9c73d --- /dev/null +++ b/internal/web/actions/default/clusters/cluster/settings/services/status.go @@ -0,0 +1,37 @@ +package services + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils" + "github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs" + "github.com/iwind/TeaGo/actions" +) + +type StatusAction struct { + actionutils.ParentAction +} + +func (this *StatusAction) Init() { + this.Nav("", "setting", "status") + this.SecondMenu("service") +} + +func (this *StatusAction) RunGet(params struct { +}) { + this.Show() +} + +func (this *StatusAction) RunPost(params struct { + ClusterId int64 + + Must *actions.Must +}) { + results, err := nodeutils.SendMessageToCluster(this.AdminContext(), params.ClusterId, messageconfigs.MessageCodeCheckSystemdService, &messageconfigs.CheckSystemdServiceMessage{}, 10) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["results"] = results + + this.Success() +} diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index 0c5b1b46..1eae3cae 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -96,6 +96,11 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt "url": "/clusters/cluster/settings/dns?clusterId=" + clusterId, "isActive": selectedItem == "dns", }) + items = append(items, maps.Map{ + "name": "系统服务", + "url": "/clusters/cluster/settings/services?clusterId=" + clusterId, + "isActive": selectedItem == "service", + }) items = append(items, maps.Map{ "name": "TOA设置", "url": "/clusters/cluster/settings/toa?clusterId=" + clusterId, diff --git a/internal/web/actions/default/clusters/create.go b/internal/web/actions/default/clusters/create.go index 4ec83dea..0d4bf4d5 100644 --- a/internal/web/actions/default/clusters/create.go +++ b/internal/web/actions/default/clusters/create.go @@ -1,9 +1,11 @@ package clusters import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils" + "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" ) @@ -37,8 +39,9 @@ func (this *CreateAction) RunPost(params struct { HttpFirewallPolicyId int64 // SSH相关 - GrantId int64 - InstallDir string + GrantId int64 + InstallDir string + SystemdServiceIsOn bool // DNS相关 DnsDomainId int64 @@ -79,6 +82,19 @@ func (this *CreateAction) RunPost(params struct { // TODO 检查DnsDomainId的有效性 + // 系统服务 + systemServices := map[string]interface{}{} + if params.SystemdServiceIsOn { + systemServices[nodeconfigs.SystemServiceTypeSystemd] = &nodeconfigs.SystemdServiceConfig{ + IsOn: true, + } + } + systemServicesJSON, err := json.Marshal(systemServices) + if err != nil { + this.ErrorPage(err) + return + } + createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{ Name: params.Name, GrantId: params.GrantId, @@ -87,6 +103,7 @@ func (this *CreateAction) RunPost(params struct { DnsName: params.DnsName, HttpCachePolicyId: params.CachePolicyId, HttpFirewallPolicyId: params.HttpFirewallPolicyId, + SystemServicesJSON: systemServicesJSON, }) if err != nil { this.ErrorPage(err) diff --git a/web/public/js/components/common/checkbox.js b/web/public/js/components/common/checkbox.js index 6bafcf01..9b0e1fca 100644 --- a/web/public/js/components/common/checkbox.js +++ b/web/public/js/components/common/checkbox.js @@ -1,6 +1,6 @@ let checkboxId = 0 Vue.component("checkbox", { - props: ["name", "value", "v-value", "id"], + props: ["name", "value", "v-value", "id", "checked"], data: function () { checkboxId++ let elementId = this.id @@ -13,10 +13,15 @@ Vue.component("checkbox", { elementValue = "1" } + let checkedValue = this.value + if (checkedValue == null && this.checked == "checked") { + checkedValue = elementValue + } + return { elementId: elementId, elementValue: elementValue, - newValue: this.value + newValue: checkedValue } }, methods: { diff --git a/web/views/@default/clusters/cluster/settings/services/@menu.html b/web/views/@default/clusters/cluster/settings/services/@menu.html new file mode 100644 index 00000000..72236865 --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/services/@menu.html @@ -0,0 +1,4 @@ + + 设置 + 状态 + \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/services/index.html b/web/views/@default/clusters/cluster/settings/services/index.html new file mode 100644 index 00000000..ad40eeef --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/services/index.html @@ -0,0 +1,23 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + +
+ + + + + + + + +
自动加入Systemd服务 + +

加入后可以利用systemd对节点进程进行管理,并可自动随开机启动。

+
+ + +
+
\ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/services/index.js b/web/views/@default/clusters/cluster/settings/services/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/services/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/services/status.html b/web/views/@default/clusters/cluster/settings/services/status.html new file mode 100644 index 00000000..62bfb4ee --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/services/status.html @@ -0,0 +1,37 @@ +{$layout} +{$template "/left_menu"} + +
+ {$template "menu"} + +
正在节点服务检测中,请稍候...
+
+
暂时还没有节点。
+
+
+ + + + + + + + + + + + + +
节点名是否已启用服务提示消息
{{result.nodeName}} + Y + N + + {{result.message}} +
+ +

+ [刷新] +

+
+
+
\ No newline at end of file diff --git a/web/views/@default/clusters/cluster/settings/services/status.js b/web/views/@default/clusters/cluster/settings/services/status.js new file mode 100644 index 00000000..49549e32 --- /dev/null +++ b/web/views/@default/clusters/cluster/settings/services/status.js @@ -0,0 +1,22 @@ +Tea.context(function () { + this.isRequesting = true + this.results = [] + + this.$delay(function () { + this.reload() + }, 2000) + + this.reload = function () { + this.isRequesting = true + this.$post("$") + .params({ + clusterId: this.clusterId + }) + .success(function (resp) { + this.results = resp.data.results + }) + .done(function () { + this.isRequesting = false + }) + } +}) \ No newline at end of file diff --git a/web/views/@default/clusters/create.html b/web/views/@default/clusters/create.html index 91e4c514..30b8c21f 100644 --- a/web/views/@default/clusters/create.html +++ b/web/views/@default/clusters/create.html @@ -40,6 +40,13 @@ 目录。

+ + 自动加入Systemd服务 + + +

加入后可以利用systemd对节点进程进行管理,并可自动随开机启动。

+ +

DNS设置选项