mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
feat: Add node service detection (#7545)
This commit is contained in:
parent
da73f26ebe
commit
9e551edf31
@ -63,3 +63,11 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) {
|
|||||||
func (b *BaseApi) LoadBaseDir(c *gin.Context) {
|
func (b *BaseApi) LoadBaseDir(c *gin.Context) {
|
||||||
helper.SuccessWithData(c, global.CONF.System.DataDir)
|
helper.SuccessWithData(c, global.CONF.System.DataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseApi) ReloadConn(c *gin.Context) {
|
||||||
|
if err := settingService.ReloadConn(); err != nil {
|
||||||
|
helper.InternalServer(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithOutData(c)
|
||||||
|
}
|
||||||
|
@ -5,7 +5,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/app/repo"
|
||||||
"github.com/1Panel-dev/1Panel/agent/constant"
|
"github.com/1Panel-dev/1Panel/agent/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/global"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SettingService struct{}
|
type SettingService struct{}
|
||||||
@ -13,6 +17,8 @@ type SettingService struct{}
|
|||||||
type ISettingService interface {
|
type ISettingService interface {
|
||||||
GetSettingInfo() (*dto.SettingInfo, error)
|
GetSettingInfo() (*dto.SettingInfo, error)
|
||||||
Update(key, value string) error
|
Update(key, value string) error
|
||||||
|
|
||||||
|
ReloadConn() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewISettingService() ISettingService {
|
func NewISettingService() ISettingService {
|
||||||
@ -59,3 +65,52 @@ func (u *SettingService) Update(key, value string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *SettingService) ReloadConn() error {
|
||||||
|
if global.IsMaster {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
isLocal, nodeInfo, err := xpack.LoadNodeInfo()
|
||||||
|
if err != nil {
|
||||||
|
global.LOG.Errorf("load new node info failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if isLocal {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
settingRepo := repo.NewISettingRepo()
|
||||||
|
itemKey, _ := encrypt.StringEncrypt(nodeInfo.ServerKey)
|
||||||
|
if err := settingRepo.Update("ServerKey", itemKey); err != nil {
|
||||||
|
global.LOG.Errorf("update server key failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
itemCrt, _ := encrypt.StringEncrypt(nodeInfo.ServerCrt)
|
||||||
|
if err := settingRepo.Update("ServerCrt", itemCrt); err != nil {
|
||||||
|
global.LOG.Errorf("update server crt failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := settingRepo.Update("CurrentNode", nodeInfo.CurrentNode); err != nil {
|
||||||
|
global.LOG.Errorf("update current node failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := settingRepo.Update("SystemVersion", nodeInfo.Version); err != nil {
|
||||||
|
global.LOG.Errorf("update system version failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := settingRepo.Update("BaseDir", nodeInfo.BaseDir); err != nil {
|
||||||
|
global.LOG.Errorf("update base dir failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := settingRepo.Update("MasterAddr", nodeInfo.MasterAddr); err != nil {
|
||||||
|
global.LOG.Errorf("update master addr failed, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
global.CONF.System.BaseDir, _ = settingRepo.GetValueByKey("BaseDir")
|
||||||
|
global.CONF.System.Version, _ = settingRepo.GetValueByKey("SystemVersion")
|
||||||
|
global.CONF.System.EncryptKey, _ = settingRepo.GetValueByKey("EncryptKey")
|
||||||
|
global.CONF.System.CurrentNode, _ = settingRepo.GetValueByKey("CurrentNode")
|
||||||
|
global.CONF.System.MasterAddr, _ = settingRepo.GetValueByKey("MasterAddr")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -11,7 +11,6 @@ require (
|
|||||||
github.com/docker/docker v27.1.0+incompatible
|
github.com/docker/docker v27.1.0+incompatible
|
||||||
github.com/docker/go-connections v0.5.0
|
github.com/docker/go-connections v0.5.0
|
||||||
github.com/fsnotify/fsnotify v1.7.0
|
github.com/fsnotify/fsnotify v1.7.0
|
||||||
github.com/gin-contrib/gzip v1.0.1
|
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/glebarez/sqlite v1.11.0
|
github.com/glebarez/sqlite v1.11.0
|
||||||
github.com/go-acme/lego/v4 v4.17.4
|
github.com/go-acme/lego/v4 v4.17.4
|
||||||
|
@ -217,8 +217,6 @@ github.com/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM4
|
|||||||
github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
|
github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||||
github.com/gin-contrib/gzip v1.0.1 h1:HQ8ENHODeLY7a4g1Au/46Z92bdGFl74OhxcZble9WJE=
|
|
||||||
github.com/gin-contrib/gzip v1.0.1/go.mod h1:njt428fdUNRvjuJf16tZMYZ2Yl+WQB53X5wmhDwXvC4=
|
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
initWithNodeJson()
|
service.NewISettingService().ReloadConn()
|
||||||
initGlobalData()
|
initGlobalData()
|
||||||
handleCronjobStatus()
|
handleCronjobStatus()
|
||||||
handleSnapStatus()
|
handleSnapStatus()
|
||||||
|
@ -14,6 +14,7 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
|
|||||||
settingRouter.POST("/search", baseApi.GetSettingInfo)
|
settingRouter.POST("/search", baseApi.GetSettingInfo)
|
||||||
settingRouter.GET("/search/available", baseApi.GetSystemAvailable)
|
settingRouter.GET("/search/available", baseApi.GetSystemAvailable)
|
||||||
settingRouter.POST("/update", baseApi.UpdateSetting)
|
settingRouter.POST("/update", baseApi.UpdateSetting)
|
||||||
|
settingRouter.POST("/conn/reload", baseApi.ReloadConn)
|
||||||
|
|
||||||
settingRouter.GET("/snapshot/load", baseApi.LoadSnapshotData)
|
settingRouter.GET("/snapshot/load", baseApi.LoadSnapshotData)
|
||||||
settingRouter.POST("/snapshot", baseApi.CreateSnapshot)
|
settingRouter.POST("/snapshot", baseApi.CreateSnapshot)
|
||||||
|
@ -187,7 +187,7 @@ func (u *SettingService) UpdatePort(port uint) error {
|
|||||||
if common.ScanPort(int(port)) {
|
if common.ScanPort(int(port)) {
|
||||||
return buserr.WithDetail(constant.ErrPortInUsed, port, nil)
|
return buserr.WithDetail(constant.ErrPortInUsed, port, nil)
|
||||||
}
|
}
|
||||||
oldPort, err := settingRepo.Get(repo.WithByKey("Port"))
|
oldPort, err := settingRepo.Get(repo.WithByKey("ServerPort"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -197,6 +197,20 @@ func (u *SettingService) UpdatePort(port uint) error {
|
|||||||
if err := firewall.UpdatePort(oldPort.Value, fmt.Sprintf("%v", port)); err != nil {
|
if err := firewall.UpdatePort(oldPort.Value, fmt.Sprintf("%v", port)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
masterAddr, err := settingRepo.Get(repo.WithByKey("MasterAddr"))
|
||||||
|
if err != nil {
|
||||||
|
global.LOG.Errorf("load master addr from db failed, err: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(masterAddr.Value) != 0 {
|
||||||
|
oldMasterPort := loadPort(masterAddr.Value)
|
||||||
|
if len(oldMasterPort) != 0 {
|
||||||
|
if err := xpack.UpdateMasterAddr(strings.ReplaceAll(masterAddr.Value, oldMasterPort, fmt.Sprintf("%v", port))); err != nil {
|
||||||
|
global.LOG.Errorf("update master addr from db failed, err: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := settingRepo.Update("ServerPort", strconv.Itoa(int(port))); err != nil {
|
if err := settingRepo.Update("ServerPort", strconv.Itoa(int(port))); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -208,20 +222,6 @@ func (u *SettingService) UpdatePort(port uint) error {
|
|||||||
global.LOG.Errorf("restart system port failed, err: %v", err)
|
global.LOG.Errorf("restart system port failed, err: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
masterAddr, err := settingRepo.Get(repo.WithByKey("MasterAddr"))
|
|
||||||
if err != nil {
|
|
||||||
global.LOG.Errorf("load master addr from db failed, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(masterAddr.Value) != 0 {
|
|
||||||
oldMasterPort := loadPort(masterAddr.Value)
|
|
||||||
if len(oldMasterPort) != 0 {
|
|
||||||
if err := xpack.UpdateMasterAddr(strings.ReplaceAll(masterAddr.Value, oldMasterPort, fmt.Sprintf("%v", port))); err != nil {
|
|
||||||
global.LOG.Errorf("update master addr from db failed, err: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ const (
|
|||||||
StatusWaiting = "Waiting"
|
StatusWaiting = "Waiting"
|
||||||
StatusPacking = "Packing"
|
StatusPacking = "Packing"
|
||||||
StatusSending = "Sending"
|
StatusSending = "Sending"
|
||||||
StatusChecking = "Checking"
|
|
||||||
StatusStarting = "Starting"
|
StatusStarting = "Starting"
|
||||||
StatusHealthy = "Healthy"
|
StatusHealthy = "Healthy"
|
||||||
StatusUnhealthy = "Unhealthy"
|
StatusUnhealthy = "Unhealthy"
|
||||||
|
69
frontend/src/components/dialog-pro/index.vue
Normal file
69
frontend/src/components/dialog-pro/index.vue
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:title="title"
|
||||||
|
v-model="dialogVisible"
|
||||||
|
:destroy-on-close="true"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:width="size"
|
||||||
|
>
|
||||||
|
<div v-if="slots.content">
|
||||||
|
<slot name="content"></slot>
|
||||||
|
</div>
|
||||||
|
<el-row v-else>
|
||||||
|
<el-col :span="22" :offset="1">
|
||||||
|
<slot></slot>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<template #footer v-if="slots.footer">
|
||||||
|
<slot name="footer"></slot>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, useSlots } from 'vue';
|
||||||
|
defineOptions({ name: 'DrawerPro' });
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
title: String,
|
||||||
|
size: {
|
||||||
|
type: String,
|
||||||
|
default: 'normal',
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const slots = useSlots();
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue', 'close']);
|
||||||
|
|
||||||
|
const size = computed(() => {
|
||||||
|
switch (props.size) {
|
||||||
|
case 'small':
|
||||||
|
return '30%';
|
||||||
|
case 'normal':
|
||||||
|
return '40%';
|
||||||
|
case 'large':
|
||||||
|
return '50%';
|
||||||
|
case 'full':
|
||||||
|
return '100%';
|
||||||
|
case '60%':
|
||||||
|
return '60%';
|
||||||
|
default:
|
||||||
|
return '50%';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const dialogVisible = computed({
|
||||||
|
get() {
|
||||||
|
return props.modelValue;
|
||||||
|
},
|
||||||
|
set(value: boolean) {
|
||||||
|
emit('update:modelValue', value);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
@ -12,6 +12,7 @@ import CopyButton from '@/components/copy-button/index.vue';
|
|||||||
import MsgInfo from '@/components/msg-info/index.vue';
|
import MsgInfo from '@/components/msg-info/index.vue';
|
||||||
import MainDiv from '@/components/main-div/index.vue';
|
import MainDiv from '@/components/main-div/index.vue';
|
||||||
import DrawerPro from '@/components/drawer-pro/index.vue';
|
import DrawerPro from '@/components/drawer-pro/index.vue';
|
||||||
|
import DialogPro from '@/components/dialog-pro/index.vue';
|
||||||
export default {
|
export default {
|
||||||
install(app: App) {
|
install(app: App) {
|
||||||
app.component(LayoutContent.name, LayoutContent);
|
app.component(LayoutContent.name, LayoutContent);
|
||||||
@ -27,5 +28,6 @@ export default {
|
|||||||
app.component(MsgInfo.name, MsgInfo);
|
app.component(MsgInfo.name, MsgInfo);
|
||||||
app.component(MainDiv.name, MainDiv);
|
app.component(MainDiv.name, MainDiv);
|
||||||
app.component(DrawerPro.name, DrawerPro);
|
app.component(DrawerPro.name, DrawerPro);
|
||||||
|
app.component(DialogPro.name, DialogPro);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user