mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 06:40:27 +08:00
集群可以设置systemd系统服务
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
"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/cache"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/dns"
|
"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/toa"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings/waf"
|
||||||
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
||||||
@@ -37,6 +38,11 @@ func init() {
|
|||||||
Prefix("/clusters/cluster/settings/toa").
|
Prefix("/clusters/cluster/settings/toa").
|
||||||
GetPost("", new(toa.IndexAction)).
|
GetPost("", new(toa.IndexAction)).
|
||||||
|
|
||||||
|
// 系统服务设置
|
||||||
|
Prefix("/clusters/cluster/settings/services").
|
||||||
|
GetPost("", new(services.IndexAction)).
|
||||||
|
GetPost("/status", new(services.StatusAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
@@ -96,6 +96,11 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, selectedIt
|
|||||||
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
|
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
|
||||||
"isActive": selectedItem == "dns",
|
"isActive": selectedItem == "dns",
|
||||||
})
|
})
|
||||||
|
items = append(items, maps.Map{
|
||||||
|
"name": "系统服务",
|
||||||
|
"url": "/clusters/cluster/settings/services?clusterId=" + clusterId,
|
||||||
|
"isActive": selectedItem == "service",
|
||||||
|
})
|
||||||
items = append(items, maps.Map{
|
items = append(items, maps.Map{
|
||||||
"name": "TOA设置",
|
"name": "TOA设置",
|
||||||
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterId,
|
"url": "/clusters/cluster/settings/toa?clusterId=" + clusterId,
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package clusters
|
package clusters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
|
"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/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
)
|
)
|
||||||
@@ -37,8 +39,9 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
HttpFirewallPolicyId int64
|
HttpFirewallPolicyId int64
|
||||||
|
|
||||||
// SSH相关
|
// SSH相关
|
||||||
GrantId int64
|
GrantId int64
|
||||||
InstallDir string
|
InstallDir string
|
||||||
|
SystemdServiceIsOn bool
|
||||||
|
|
||||||
// DNS相关
|
// DNS相关
|
||||||
DnsDomainId int64
|
DnsDomainId int64
|
||||||
@@ -79,6 +82,19 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
|
|
||||||
// TODO 检查DnsDomainId的有效性
|
// 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{
|
createResp, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
GrantId: params.GrantId,
|
GrantId: params.GrantId,
|
||||||
@@ -87,6 +103,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
DnsName: params.DnsName,
|
DnsName: params.DnsName,
|
||||||
HttpCachePolicyId: params.CachePolicyId,
|
HttpCachePolicyId: params.CachePolicyId,
|
||||||
HttpFirewallPolicyId: params.HttpFirewallPolicyId,
|
HttpFirewallPolicyId: params.HttpFirewallPolicyId,
|
||||||
|
SystemServicesJSON: systemServicesJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
let checkboxId = 0
|
let checkboxId = 0
|
||||||
Vue.component("checkbox", {
|
Vue.component("checkbox", {
|
||||||
props: ["name", "value", "v-value", "id"],
|
props: ["name", "value", "v-value", "id", "checked"],
|
||||||
data: function () {
|
data: function () {
|
||||||
checkboxId++
|
checkboxId++
|
||||||
let elementId = this.id
|
let elementId = this.id
|
||||||
@@ -13,10 +13,15 @@ Vue.component("checkbox", {
|
|||||||
elementValue = "1"
|
elementValue = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let checkedValue = this.value
|
||||||
|
if (checkedValue == null && this.checked == "checked") {
|
||||||
|
checkedValue = elementValue
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elementId: elementId,
|
elementId: elementId,
|
||||||
elementValue: elementValue,
|
elementValue: elementValue,
|
||||||
newValue: this.value
|
newValue: checkedValue
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<first-menu>
|
||||||
|
<menu-item :href="'/clusters/cluster/settings/services?clusterId=' + clusterId" code="setting">设置</menu-item>
|
||||||
|
<menu-item :href="'/clusters/cluster/settings/services/status?clusterId=' + clusterId" code="status">状态</menu-item>
|
||||||
|
</first-menu>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "menu"}
|
||||||
|
|
||||||
|
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<input type="hidden" name="clusterId" :value="clusterId"/>
|
||||||
|
<csrf-token></csrf-token>
|
||||||
|
|
||||||
|
<table class="ui table definition selectable">
|
||||||
|
<tr>
|
||||||
|
<td class="title">自动加入Systemd服务</td>
|
||||||
|
<td>
|
||||||
|
<checkbox name="systemdIsOn" v-model="systemdIsOn"></checkbox>
|
||||||
|
<p class="comment">加入后可以利用systemd对节点进程进行管理,并可自动随开机启动。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{$layout}
|
||||||
|
{$template "/left_menu"}
|
||||||
|
|
||||||
|
<div class="right-box">
|
||||||
|
{$template "menu"}
|
||||||
|
|
||||||
|
<div v-if="isRequesting" class="ui message">正在节点服务检测中,请稍候...</div>
|
||||||
|
<div v-if="!isRequesting">
|
||||||
|
<div v-if="results.length == 0">暂时还没有节点。</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="margin"></div>
|
||||||
|
<table class="ui table selectable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>节点名</th>
|
||||||
|
<th>是否已启用服务</th>
|
||||||
|
<th>提示消息</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tr v-for="result in results">
|
||||||
|
<td>{{result.nodeName}}</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="result.isOk" class="green">Y</span>
|
||||||
|
<span v-else class="red">N</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span :class="{red: !result.isOk}">{{result.message}}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p class="comment">
|
||||||
|
<a href="" @click.prevent="reload()">[刷新]</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -40,6 +40,13 @@
|
|||||||
目录。</p>
|
目录。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>自动加入Systemd服务</td>
|
||||||
|
<td>
|
||||||
|
<checkbox name="systemdServiceIsOn" checked="checked"></checkbox>
|
||||||
|
<p class="comment">加入后可以利用systemd对节点进程进行管理,并可自动随开机启动。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h4>DNS设置选项</h4>
|
<h4>DNS设置选项</h4>
|
||||||
|
|||||||
Reference in New Issue
Block a user