feat: Supervisor supports automatic restart configuration. (#8413)

Refs https://github.com/1Panel-dev/1Panel/issues/7406
This commit is contained in:
ChengPlay 2025-04-17 22:22:24 +08:00 committed by GitHub
parent b520b748c6
commit 52ec3b9887
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 44 additions and 14 deletions

View file

@ -26,12 +26,13 @@ type HostToolConfig struct {
}
type SupervisorProcessConfig struct {
Name string `json:"name"`
Operate string `json:"operate"`
Command string `json:"command"`
User string `json:"user"`
Dir string `json:"dir"`
Numprocs string `json:"numprocs"`
Name string `json:"name"`
Operate string `json:"operate"`
Command string `json:"command"`
User string `json:"user"`
Dir string `json:"dir"`
Numprocs string `json:"numprocs"`
AutoRestart string `json:"autoRestart"`
}
type SupervisorProcessFileReq struct {

View file

@ -23,13 +23,14 @@ type HostToolConfig struct {
}
type SupervisorProcessConfig struct {
Name string `json:"name"`
Command string `json:"command"`
User string `json:"user"`
Dir string `json:"dir"`
Numprocs string `json:"numprocs"`
Msg string `json:"msg"`
Status []ProcessStatus `json:"status"`
Name string `json:"name"`
Command string `json:"command"`
User string `json:"user"`
Dir string `json:"dir"`
Numprocs string `json:"numprocs"`
Msg string `json:"msg"`
Status []ProcessStatus `json:"status"`
AutoRestart string `json:"autoRestart"`
}
type ProcessStatus struct {

View file

@ -322,7 +322,7 @@ func handleProcess(supervisordDir string, req request.SupervisorProcessConfig, c
}
_, _ = section.NewKey("command", strings.TrimSpace(req.Command))
_, _ = section.NewKey("directory", req.Dir)
_, _ = section.NewKey("autorestart", "true")
_, _ = section.NewKey("autorestart", req.AutoRestart)
_, _ = section.NewKey("startsecs", "3")
_, _ = section.NewKey("stdout_logfile", outLog)
_, _ = section.NewKey("stderr_logfile", errLog)
@ -358,6 +358,8 @@ func handleProcess(supervisordDir string, req request.SupervisorProcessConfig, c
userKey.SetValue(req.User)
numprocsKey := section.Key("numprocs")
numprocsKey.SetValue(req.Numprocs)
autoRestart := section.Key("autorestart")
autoRestart.SetValue(req.AutoRestart)
if err = configFile.SaveTo(iniPath); err != nil {
return err
@ -424,6 +426,9 @@ func handleProcessConfig(configDir, containerName string) ([]response.Supervisor
if numprocs, _ := section.GetKey("numprocs"); numprocs != nil {
config.Numprocs = numprocs.Value()
}
if autoRestart, _ := section.GetKey("autorestart"); autoRestart != nil {
config.AutoRestart = autoRestart.Value()
}
_ = getProcessStatus(&config, containerName)
result = append(result, config)
}

View file

@ -262,6 +262,7 @@ ErrDBNotExist: "数据库不存在"
allow: "允许"
deny: "禁止"
OpenrestyNotFound: "Openresty 未安装"
remoteIpIsNull: "IP 列表为空"
#task
TaskStart: "{{ .name }} 任务开始 [START]"

View file

@ -42,6 +42,7 @@ export namespace HostTool {
dir: string;
numprocs: string;
status?: ProcessStatus[];
autoRestart: string;
}
export interface ProcessStatus {

View file

@ -2753,6 +2753,7 @@ const message = {
ERROR: 'Error',
statusCode: 'Status code',
manage: 'Management',
autoRestart: 'Auto Restart',
},
},
xpack: {
@ -3013,6 +3014,7 @@ const message = {
strict: 'Strict Mode',
strictHelper: 'Use stricter rules to validate requests',
saveLog: 'Save Log',
remoteURLHelper: 'The remote URL needs to ensure one IP per line and no other characters',
},
monitor: {
name: 'Website Monitoring',

View file

@ -2619,6 +2619,7 @@ const message = {
ERROR: 'エラー',
statusCode: 'ステータスコード',
manage: '管理',
autoRestart: '自動再起動',
},
},
xpack: {
@ -2873,6 +2874,7 @@ const message = {
strict: '厳格モード',
strictHelper: 'より厳格なルールを使用してリクエストを検証します',
saveLog: 'ログを保存',
remoteURLHelper: 'リモート URL 1行に1つのIPで他の文字がないことを保証する必要があります',
},
monitor: {
name: 'ウェブサイトモニタリング',

View file

@ -2578,6 +2578,7 @@ const message = {
ERROR: '오류',
statusCode: '상태 코드',
manage: '관리',
autoRestart: '자동 재시작',
},
},
xpack: {
@ -2828,6 +2829,7 @@ const message = {
strict: '엄격 모드',
strictHelper: ' 엄격한 규칙을 사용하여 요청을 검증합니다',
saveLog: '로그 저장',
remoteURLHelper: '원격 URL은 줄에 하나의 IP만 포함하고 다른 문자는 포함하지 않아야 합니다',
},
monitor: {
name: '웹사이트 모니터링',

View file

@ -2680,6 +2680,7 @@ const message = {
ERROR: 'Ralat',
statusCode: 'Kod status',
manage: 'Pengurusan',
autoRestart: 'Auto Restart',
},
},
xpack: {
@ -2938,6 +2939,7 @@ const message = {
strict: 'Mod Strict',
strictHelper: 'Gunakan peraturan yang lebih ketat untuk mengesahkan permintaan',
saveLog: 'Simpan Log',
remoteURLHelper: 'URL jauh perlu memastikan satu IP setiap baris dan tiada aksara lain',
},
monitor: {
name: 'Pemantauan Laman Web',

View file

@ -2677,6 +2677,7 @@ const message = {
ERROR: 'Erro',
statusCode: 'Código de status',
manage: 'Gerenciamento',
autoRestart: 'Reinicialização Automática',
},
},
xpack: {
@ -2938,6 +2939,7 @@ const message = {
strict: 'Modo estrito',
strictHelper: 'Usa regras mais rigorosas para validar solicitações',
saveLog: 'Salvar log',
remoteURLHelper: 'O URL remoto precisa garantir um IP por linha e nenhum outro caractere',
},
monitor: {
name: 'Monitoramento de Websites',

View file

@ -2673,6 +2673,7 @@ const message = {
ERROR: 'Ошибка',
statusCode: 'Код статуса',
manage: 'Управление',
autoRestart: 'Автоматический перезапуск',
},
},
xpack: {
@ -2932,6 +2933,7 @@ const message = {
strict: 'Строгий режим',
strictHelper: 'Использует более строгие правила для проверки запросов',
saveLog: 'Сохранить лог',
remoteURLHelper: 'Удаленный URL должен содержать один IP на строку и не содержать других символов',
},
monitor: {
name: 'Мониторинг веб-сайта',

View file

@ -2550,6 +2550,7 @@ const message = {
ERROR: '錯誤',
statusCode: '狀態碼',
manage: '管理',
autoRestart: '自動重啟',
},
},
xpack: {
@ -2793,6 +2794,7 @@ const message = {
strict: '嚴格模式',
strictHelper: '使用更嚴格的規則來校驗請求',
saveLog: '保存日誌',
remoteURLHelper: '遠程 URL 需要保證每行一個 IP 並且沒有其他字符',
},
monitor: {
name: '網站監控',

View file

@ -2542,6 +2542,7 @@ const message = {
ERROR: '错误',
statusCode: '状态码',
manage: '管理',
autoRestart: '自动重启',
},
},
xpack: {
@ -2782,6 +2783,7 @@ const message = {
strict: '严格模式',
strictHelper: '使用更严格的规则来校验请求',
saveLog: '保存日志',
remoteURLHelper: '远程 URL 需要保证每行一个 IP 并且没有其他字符',
},
monitor: {
name: '网站监控',

View file

@ -30,6 +30,9 @@
<el-form-item :label="$t('tool.supervisor.numprocs')" prop="numprocsNum">
<el-input type="number" v-model.number="process.numprocsNum"></el-input>
</el-form-item>
<el-form-item :label="$t('tool.supervisor.autoRestart')" prop="autoRestart">
<el-switch v-model="process.autoRestart" active-value="true" inactive-value="false"></el-switch>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
@ -70,6 +73,7 @@ const initData = () => ({
dir: '',
numprocsNum: 1,
numprocs: '1',
autoRestart: 'true',
});
const process = ref(initData());
@ -100,6 +104,7 @@ const acceptParams = (operate: string, config: HostTool.SupersivorProcess) => {
dir: config.dir,
numprocsNum: 1,
numprocs: config.numprocs,
autoRestart: config.autoRestart,
};
process.value.numprocsNum = Number(config.numprocs);
}