集群可以设置systemd系统服务

This commit is contained in:
刘祥超
2021-01-11 18:16:04 +08:00
parent d0138fa736
commit 5c7f456207
8 changed files with 186 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"strconv"
@@ -102,7 +103,7 @@ func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeClu
}
// 创建集群
func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64) (clusterId int64, err error) {
func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map) (clusterId int64, err error) {
uniqueId, err := this.genUniqueId(tx)
if err != nil {
return 0, err
@@ -139,6 +140,13 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
// WAF策略
op.HttpFirewallPolicyId = httpFirewallPolicyId
// 系统服务
systemServicesJSON, err := json.Marshal(systemServices)
if err != nil {
return 0, err
}
op.SystemServices = systemServicesJSON
op.UseAllAPINodes = 1
op.ApiNodes = "[]"
op.UniqueId = uniqueId
@@ -652,6 +660,89 @@ func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, cl
return err
}
// 修改集群的系统服务设置
func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType, params maps.Map) error {
if clusterId <= 0 {
return errors.New("invalid clusterId")
}
service, err := this.Query(tx).
Pk(clusterId).
Result("systemServices").
FindStringCol("")
if err != nil {
return err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
err = json.Unmarshal([]byte(service), &servicesMap)
if err != nil {
return err
}
}
if params == nil {
params = maps.Map{}
}
servicesMap[serviceType] = params
servicesJSON, err := json.Marshal(servicesMap)
if err != nil {
return err
}
_, err = this.Query(tx).
Pk(clusterId).
Set("systemServices", servicesJSON).
Update()
if err != nil {
return err
}
return nil
}
// 查找集群的系统服务设置
func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType) (params maps.Map, err error) {
if clusterId <= 0 {
return nil, errors.New("invalid clusterId")
}
service, err := this.Query(tx).
Pk(clusterId).
Result("systemServices").
FindStringCol("")
if err != nil {
return nil, err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
err = json.Unmarshal([]byte(service), &servicesMap)
if err != nil {
return nil, err
}
}
return servicesMap[serviceType], nil
}
// 查找集群的所有服务设置
func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId int64) (services map[string]maps.Map, err error) {
if clusterId <= 0 {
return nil, errors.New("invalid clusterId")
}
service, err := this.Query(tx).
Pk(clusterId).
Result("systemServices").
FindStringCol("")
if err != nil {
return nil, err
}
servicesMap := map[string]maps.Map{}
if IsNotNull(service) {
err = json.Unmarshal([]byte(service), &servicesMap)
if err != nil {
return nil, err
}
}
return servicesMap, nil
}
// 生成唯一ID
func (this *NodeClusterDAO) genUniqueId(tx *dbs.Tx) (string, error) {
for {

View File

@@ -24,6 +24,7 @@ type NodeCluster struct {
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID
AccessLog string `field:"accessLog"` // 访问日志设置
SystemServices string `field:"systemServices"` // 系统服务设置
}
type NodeClusterOperator struct {
@@ -49,6 +50,7 @@ type NodeClusterOperator struct {
CachePolicyId interface{} // 缓存策略ID
HttpFirewallPolicyId interface{} // WAF策略ID
AccessLog interface{} // 访问日志设置
SystemServices interface{} // 系统服务设置
}
func NewNodeClusterOperator() *NodeClusterOperator {

View File

@@ -553,6 +553,15 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*nodeconfigs.N
}
config.TOA = toaConfig
// 系统服务
services, err := SharedNodeClusterDAO.FindNodeClusterSystemServices(tx, clusterId)
if err != nil {
return nil, err
}
if len(services) > 0 {
config.SystemServices = services
}
return config, nil
}