1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-12 11:30:07 +08:00

feat: 处理 1Panel 重启导致运行环境状态异常的问题 (#2773)

This commit is contained in:
zhengkunwang 2023-11-02 14:35:58 +08:00 committed by GitHub
parent 2d8a7bbbc3
commit 47b75673f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 2 deletions

View File

@ -40,6 +40,7 @@ type IRuntimeService interface {
OperateRuntime(req request.RuntimeOperate) error OperateRuntime(req request.RuntimeOperate) error
GetNodeModules(req request.NodeModuleReq) ([]response.NodeModule, error) GetNodeModules(req request.NodeModuleReq) ([]response.NodeModule, error)
OperateNodeModules(req request.NodeModuleOperateReq) error OperateNodeModules(req request.NodeModuleOperateReq) error
SyncForRestart() error
} }
func NewRuntimeService() IRuntimeService { func NewRuntimeService() IRuntimeService {
@ -555,3 +556,18 @@ func (r *RuntimeService) OperateNodeModules(req request.NodeModuleOperateReq) er
cmd += " " + req.Module cmd += " " + req.Module
return cmd2.ExecContainerScript(containerName, cmd, 5*time.Minute) return cmd2.ExecContainerScript(containerName, cmd, 5*time.Minute)
} }
func (r *RuntimeService) SyncForRestart() error {
runtimes, err := runtimeRepo.List()
if err != nil {
return err
}
for _, runtime := range runtimes {
if runtime.Status == constant.RuntimeBuildIng || runtime.Status == constant.RuntimeReCreating || runtime.Status == constant.RuntimeStarting || runtime.Status == constant.RuntimeCreating {
runtime.Status = constant.SystemRestart
runtime.Message = "System restart causing interrupt"
_ = runtimeRepo.Save(&runtime)
}
}
return nil
}

View File

@ -4,4 +4,6 @@ type DBContext string
const ( const (
DB DBContext = "db" DB DBContext = "db"
SystemRestart = "systemRestart"
) )

View File

@ -8,6 +8,7 @@ import (
func Init() { func Init() {
go syncApp() go syncApp()
go syncInstalledApp() go syncInstalledApp()
go syncRuntime()
} }
func syncApp() { func syncApp() {
@ -22,3 +23,9 @@ func syncInstalledApp() {
global.LOG.Errorf("sync instaled app error: %s", err.Error()) global.LOG.Errorf("sync instaled app error: %s", err.Error())
} }
} }
func syncRuntime() {
if err := service.NewRuntimeService().SyncForRestart(); err != nil {
global.LOG.Errorf("sync runtime status error : %s", err.Error())
}
}

View File

@ -144,7 +144,7 @@ func TestAppToV2(t *testing.T) {
} }
_ = fileOp.DeleteFile(newVersionDir + "/config.json") _ = fileOp.DeleteFile(newVersionDir + "/config.json")
oldReadMefile := newVersionDir + "/README.md" oldReadMefile := newVersionDir + "/README.md"
// _ = fileOp.Cut([]string{oldReadMefile}, newAppDir) _ = fileOp.Cut([]string{oldReadMefile}, newAppDir, "", false)
_ = fileOp.DeleteFile(oldReadMefile) _ = fileOp.DeleteFile(oldReadMefile)
} }
} }

View File

@ -234,6 +234,7 @@ const message = {
starting: 'Starting', starting: 'Starting',
recreating: 'Recreating', recreating: 'Recreating',
creating: 'Creating', creating: 'Creating',
systemrestart: 'Interrupt',
}, },
units: { units: {
second: 'Second', second: 'Second',
@ -1842,6 +1843,7 @@ const message = {
customScript: 'Custom startup command', customScript: 'Custom startup command',
customScriptHelper: 'Please fill in the complete startup command, for example: npm run start', customScriptHelper: 'Please fill in the complete startup command, for example: npm run start',
portError: 'Cannot fill in the same port', portError: 'Cannot fill in the same port',
systemRestartHelper: 'Status description: Interruption - status acquisition failed due to system restart',
}, },
process: { process: {
pid: 'Process ID', pid: 'Process ID',

View File

@ -233,6 +233,7 @@ const message = {
starting: '啟動中', starting: '啟動中',
recreating: '重建中', recreating: '重建中',
creating: '創建中', creating: '創建中',
systemrestart: '中斷',
}, },
units: { units: {
second: '秒', second: '秒',
@ -1738,6 +1739,7 @@ const message = {
customScript: '自訂啟動指令', customScript: '自訂啟動指令',
customScriptHelper: '請填寫完整的啟動指令例如npm run start', customScriptHelper: '請填寫完整的啟動指令例如npm run start',
portError: '不能填寫相同連接埠', portError: '不能填寫相同連接埠',
systemRestartHelper: '狀態說明中斷-系統重新啟動導致狀態取得失敗',
}, },
process: { process: {
pid: '進程ID', pid: '進程ID',

View File

@ -233,6 +233,7 @@ const message = {
starting: '启动中', starting: '启动中',
recreating: '重建中', recreating: '重建中',
creating: '创建中', creating: '创建中',
systemrestart: '中断',
}, },
units: { units: {
second: '秒', second: '秒',
@ -1738,6 +1739,7 @@ const message = {
customScript: '自定义启动命令', customScript: '自定义启动命令',
customScriptHelper: '请填写完整的启动命令例如npm run start', customScriptHelper: '请填写完整的启动命令例如npm run start',
portError: '不能填写相同端口', portError: '不能填写相同端口',
systemRestartHelper: '状态说明中断-系统重启导致状态获取失败',
}, },
process: { process: {
pid: '进程ID', pid: '进程ID',

View File

@ -2,6 +2,13 @@
<div> <div>
<RouterMenu /> <RouterMenu />
<LayoutContent :title="'PHP'" v-loading="loading"> <LayoutContent :title="'PHP'" v-loading="loading">
<template #prompt>
<el-alert type="info" :closable="false">
<template #default>
<span>{{ $t('runtime.systemRestartHelper') }}</span>
</template>
</el-alert>
</template>
<template #toolbar> <template #toolbar>
<el-button type="primary" @click="openCreate"> <el-button type="primary" @click="openCreate">
{{ $t('runtime.create') }} {{ $t('runtime.create') }}
@ -24,7 +31,7 @@
<el-table-column :label="$t('commons.table.status')" prop="status"> <el-table-column :label="$t('commons.table.status')" prop="status">
<template #default="{ row }"> <template #default="{ row }">
<el-popover <el-popover
v-if="row.status === 'error'" v-if="row.status === 'error' || row.status === 'systemRestart'"
placement="bottom" placement="bottom"
:width="400" :width="400"
trigger="hover" trigger="hover"