Skip to content

Commit

Permalink
feat: 处理 1Panel 重启导致运行环境状态异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 committed Nov 2, 2023
1 parent 05029a3 commit f9205a2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
16 changes: 16 additions & 0 deletions backend/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type IRuntimeService interface {
OperateRuntime(req request.RuntimeOperate) error
GetNodeModules(req request.NodeModuleReq) ([]response.NodeModule, error)
OperateNodeModules(req request.NodeModuleOperateReq) error
SyncForRestart() error
}

func NewRuntimeService() IRuntimeService {
Expand Down Expand Up @@ -555,3 +556,18 @@ func (r *RuntimeService) OperateNodeModules(req request.NodeModuleOperateReq) er
cmd += " " + req.Module
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
}
2 changes: 2 additions & 0 deletions backend/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ type DBContext string

const (
DB DBContext = "db"

SystemRestart = "systemRestart"
)
7 changes: 7 additions & 0 deletions backend/init/business/business.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func Init() {
go syncApp()
go syncInstalledApp()
go syncRuntime()
}

func syncApp() {
Expand All @@ -22,3 +23,9 @@ func syncInstalledApp() {
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())
}
}
2 changes: 1 addition & 1 deletion backend/utils/ssl/acme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestAppToV2(t *testing.T) {
}
_ = fileOp.DeleteFile(newVersionDir + "/config.json")
oldReadMefile := newVersionDir + "/README.md"
_ = fileOp.Cut([]string{oldReadMefile}, newAppDir)
_ = fileOp.Cut([]string{oldReadMefile}, newAppDir, "", false)
_ = fileOp.DeleteFile(oldReadMefile)
}
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const message = {
starting: 'Starting',
recreating: 'Recreating',
creating: 'Creating',
systemrestart: 'Interrupt',
},
units: {
second: 'Second',
Expand Down Expand Up @@ -1842,6 +1843,7 @@ const message = {
customScript: 'Custom startup command',
customScriptHelper: 'Please fill in the complete startup command, for example: npm run start',
portError: 'Cannot fill in the same port',
systemRestartHelper: 'Status description: Interruption - status acquisition failed due to system restart',
},
process: {
pid: 'Process ID',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const message = {
starting: '啟動中',
recreating: '重建中',
creating: '創建中',
systemrestart: '中',
},
units: {
second: '秒',
Expand Down Expand Up @@ -1738,6 +1739,7 @@ const message = {
customScript: '自訂啟動指令',
customScriptHelper: '請填寫完整的啟動指令例如npm run start',
portError: '不能填寫相同連接埠',
systemRestartHelper: '狀態說明中斷-系統重新啟動導致狀態取得失敗',
},
process: {
pid: '進程ID',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const message = {
starting: '启动中',
recreating: '重建中',
creating: '创建中',
systemrestart: '中',
},
units: {
second: '秒',
Expand Down Expand Up @@ -1738,6 +1739,7 @@ const message = {
customScript: '自定义启动命令',
customScriptHelper: '请填写完整的启动命令例如npm run start',
portError: '不能填写相同端口',
systemRestartHelper: '状态说明中断-系统重启导致状态获取失败',
},
process: {
pid: '进程ID',
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/views/website/runtime/php/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<div>
<RouterMenu />
<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>
<el-button type="primary" @click="openCreate">
{{ $t('runtime.create') }}
Expand All @@ -24,7 +31,7 @@
<el-table-column :label="$t('commons.table.status')" prop="status">
<template #default="{ row }">
<el-popover
v-if="row.status === 'error'"
v-if="row.status === 'error' || row.status === 'systemRestart'"
placement="bottom"
:width="400"
trigger="hover"
Expand Down

0 comments on commit f9205a2

Please sign in to comment.