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 @@
+
| 节点名 | +是否已启用服务 | +提示消息 | +
|---|---|---|
| {{result.nodeName}} | ++ Y + N + | ++ {{result.message}} + | +
+ [刷新] +
+加入后可以利用systemd对节点进程进行管理,并可自动随开机启动。
+