集群可以设置systemd系统服务

This commit is contained in:
GoEdgeLab
2021-01-11 18:15:53 +08:00
parent e954e57f3d
commit 18f0f13cd0
12 changed files with 247 additions and 4 deletions

View File

@@ -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()
})
}

View File

@@ -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()
}

View File

@@ -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()
}