mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2024-12-05 21:38:26 +08:00
feat: Supervisor 适配 Debian 操作系统 (#1811)
This commit is contained in:
parent
6f6c836d9a
commit
202a2ad7ae
1
.gitignore
vendored
1
.gitignore
vendored
@ -33,3 +33,4 @@ install.sh
|
||||
quick_start.sh
|
||||
cmd/server/web/.DS_Store
|
||||
cmd/server/.DS_Store
|
||||
cmd/server/fileList.txt
|
||||
|
@ -11,7 +11,8 @@ type HostToolCreate struct {
|
||||
}
|
||||
|
||||
type SupervisorConfig struct {
|
||||
ConfigPath string `json:"configPath"`
|
||||
ConfigPath string `json:"configPath"`
|
||||
ServiceName string `json:"serviceName"`
|
||||
}
|
||||
|
||||
type HostToolLogReq struct {
|
||||
|
@ -6,15 +6,16 @@ type HostToolRes struct {
|
||||
}
|
||||
|
||||
type Supervisor struct {
|
||||
ConfigPath string `json:"configPath"`
|
||||
IncludeDir string `json:"includeDir"`
|
||||
LogPath string `json:"logPath"`
|
||||
IsExist bool `json:"isExist"`
|
||||
Init bool `json:"init"`
|
||||
Msg string `json:"msg"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
CtlExist bool `json:"ctlExist"`
|
||||
ConfigPath string `json:"configPath"`
|
||||
IncludeDir string `json:"includeDir"`
|
||||
LogPath string `json:"logPath"`
|
||||
IsExist bool `json:"isExist"`
|
||||
Init bool `json:"init"`
|
||||
Msg string `json:"msg"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"status"`
|
||||
CtlExist bool `json:"ctlExist"`
|
||||
ServiceName string `json:"serviceName"`
|
||||
}
|
||||
|
||||
type HostToolConfig struct {
|
||||
|
@ -43,29 +43,33 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host
|
||||
res.Type = req.Type
|
||||
switch req.Type {
|
||||
case constant.Supervisord:
|
||||
exist, err := systemctl.IsExist(constant.Supervisord)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exist, _ := systemctl.IsExist(constant.Supervisord)
|
||||
supervisorConfig := &response.Supervisor{}
|
||||
if !exist {
|
||||
supervisorConfig.IsExist = false
|
||||
return res, nil
|
||||
exist, _ = systemctl.IsExist(constant.Supervisor)
|
||||
if !exist {
|
||||
supervisorConfig.IsExist = false
|
||||
res.Config = supervisorConfig
|
||||
return res, nil
|
||||
} else {
|
||||
supervisorConfig.ServiceName = constant.Supervisor
|
||||
}
|
||||
} else {
|
||||
supervisorConfig.ServiceName = constant.Supervisord
|
||||
}
|
||||
supervisorConfig.IsExist = true
|
||||
|
||||
serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName))
|
||||
if serviceNameSet.ID != 0 || serviceNameSet.Value != "" {
|
||||
supervisorConfig.ServiceName = serviceNameSet.Value
|
||||
}
|
||||
|
||||
versionRes, _ := cmd.Exec("supervisord -v")
|
||||
supervisorConfig.Version = strings.TrimSuffix(versionRes, "\n")
|
||||
_, ctlRrr := exec.LookPath("supervisorctl")
|
||||
supervisorConfig.CtlExist = ctlRrr == nil
|
||||
|
||||
active, err := systemctl.IsActive(constant.Supervisord)
|
||||
if err != nil {
|
||||
supervisorConfig.Status = "unhealthy"
|
||||
supervisorConfig.Msg = err.Error()
|
||||
res.Config = supervisorConfig
|
||||
return res, nil
|
||||
}
|
||||
active, _ := systemctl.IsActive(supervisorConfig.ServiceName)
|
||||
if active {
|
||||
supervisorConfig.Status = "running"
|
||||
} else {
|
||||
@ -77,13 +81,14 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host
|
||||
supervisorConfig.ConfigPath = pathSet.Value
|
||||
res.Config = supervisorConfig
|
||||
return res, nil
|
||||
} else {
|
||||
supervisorConfig.Init = true
|
||||
}
|
||||
supervisorConfig.Init = true
|
||||
|
||||
servicePath := "/usr/lib/systemd/system/supervisord.service"
|
||||
servicePath := "/usr/lib/systemd/system/supervisor.service"
|
||||
fileOp := files.NewFileOp()
|
||||
if !fileOp.Stat(servicePath) {
|
||||
servicePath = "/lib/systemd/system/supervisord.service"
|
||||
servicePath = "/usr/lib/systemd/system/supervisord.service"
|
||||
}
|
||||
if fileOp.Stat(servicePath) {
|
||||
startCmd, _ := ini_conf.GetIniValue(servicePath, "Service", "ExecStart")
|
||||
@ -161,9 +166,12 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error {
|
||||
if err = settingRepo.Create(constant.SupervisorConfigPath, req.ConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = settingRepo.Create(constant.SupervisorServiceName, req.ServiceName); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
if err = systemctl.Restart(constant.Supervisord); err != nil {
|
||||
global.LOG.Errorf("[init] restart supervisord failed err %s", err.Error())
|
||||
if err = systemctl.Restart(req.ServiceName); err != nil {
|
||||
global.LOG.Errorf("[init] restart %s failed err %s", req.ServiceName, err.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -171,19 +179,31 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error {
|
||||
}
|
||||
|
||||
func (h *HostToolService) OperateTool(req request.HostToolReq) error {
|
||||
return systemctl.Operate(req.Operate, req.Type)
|
||||
serviceName := req.Type
|
||||
if req.Type == constant.Supervisord {
|
||||
serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName))
|
||||
if serviceNameSet.ID != 0 || serviceNameSet.Value != "" {
|
||||
serviceName = serviceNameSet.Value
|
||||
}
|
||||
}
|
||||
return systemctl.Operate(req.Operate, serviceName)
|
||||
}
|
||||
|
||||
func (h *HostToolService) OperateToolConfig(req request.HostToolConfig) (*response.HostToolConfig, error) {
|
||||
fileOp := files.NewFileOp()
|
||||
res := &response.HostToolConfig{}
|
||||
configPath := ""
|
||||
serviceName := "supervisord"
|
||||
switch req.Type {
|
||||
case constant.Supervisord:
|
||||
pathSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorConfigPath))
|
||||
if pathSet.ID != 0 || pathSet.Value != "" {
|
||||
configPath = pathSet.Value
|
||||
}
|
||||
serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName))
|
||||
if serviceNameSet.ID != 0 || serviceNameSet.Value != "" {
|
||||
serviceName = serviceNameSet.Value
|
||||
}
|
||||
}
|
||||
switch req.Operate {
|
||||
case "get":
|
||||
@ -208,7 +228,7 @@ func (h *HostToolService) OperateToolConfig(req request.HostToolConfig) (*respon
|
||||
if err = fileOp.WriteFile(configPath, strings.NewReader(req.Content), fileInfo.Mode()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = systemctl.Restart(req.Type); err != nil {
|
||||
if err = systemctl.Restart(serviceName); err != nil {
|
||||
_ = fileOp.WriteFile(configPath, bytes.NewReader(oldContent), fileInfo.Mode())
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
Supervisord = "supervisord"
|
||||
SupervisorConfigPath = "SupervisorConfigPath"
|
||||
Supervisord = "supervisord"
|
||||
Supervisor = "supervisor"
|
||||
SupervisorConfigPath = "SupervisorConfigPath"
|
||||
SupervisorServiceName = "SupervisorServiceName"
|
||||
)
|
||||
|
@ -15377,6 +15377,9 @@ const docTemplate = `{
|
||||
"configPath": {
|
||||
"type": "string"
|
||||
},
|
||||
"serviceName": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -15370,6 +15370,9 @@
|
||||
"configPath": {
|
||||
"type": "string"
|
||||
},
|
||||
"serviceName": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
|
@ -2652,6 +2652,8 @@ definitions:
|
||||
properties:
|
||||
configPath:
|
||||
type: string
|
||||
serviceName:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
required:
|
||||
|
@ -14,6 +14,7 @@ export namespace HostTool {
|
||||
version: string;
|
||||
status: string;
|
||||
ctlExist: boolean;
|
||||
serviceName: string;
|
||||
}
|
||||
|
||||
export interface SupersivorConfig {
|
||||
@ -30,6 +31,7 @@ export namespace HostTool {
|
||||
export interface SupersivorInit {
|
||||
type: string;
|
||||
configPath: string;
|
||||
serviceName: string;
|
||||
}
|
||||
|
||||
export interface SupersivorProcess {
|
||||
|
@ -1668,6 +1668,8 @@ const message = {
|
||||
'Because it is not compatible with the original configuration, initializing Supervisor will modify the files parameter of the configuration file, causing all existing processes to stop, please confirm the risk in advance. The modified process configuration folder is in <1Panel installation directory>/1panel/tools/supervisord/supervisor.d',
|
||||
operatorHelper: 'Operation {1} will be performed on {0}, continue? ',
|
||||
uptime: 'running time',
|
||||
notStartWarn: 'Supervisor is not started, please start it first',
|
||||
serviceName: 'Service name',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -1585,6 +1585,8 @@ const message = {
|
||||
'由於無法兼容原有配置,初始化 Supervisor 會修改配置文件的 files 參數,導致已有的進程全部停止,請提前確認風險。修改後的進程配置文件夾在 <1Panel安裝目錄>/1panel/tools/supervisord/supervisor.d 中',
|
||||
operatorHelper: '將對 {0} 進行 {1} 操作,是否繼續? ',
|
||||
uptime: '運行時長',
|
||||
notStartWarn: 'Supervisor 未啟動,請先啟動',
|
||||
serviceName: '服務名稱',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -1587,6 +1587,8 @@ const message = {
|
||||
'由于无法兼容原有配置,初始化 Supervisor 会修改配置文件的 files 参数,导致已有的进程全部停止,请提前确认风险。修改后的进程配置文件夹在 <1Panel安装目录>/1panel/tools/supervisord/supervisor.d 中',
|
||||
operatorHelper: '将对 {0} 进行 {1} 操作,是否继续?',
|
||||
uptime: '运行时长',
|
||||
notStartWarn: '当前未开启 Supervisor ,请先启动',
|
||||
serviceName: '服务名称',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div>
|
||||
<ToolRouter />
|
||||
<el-card v-if="!isRunningSuperVisor && maskShow" class="mask-prompt">
|
||||
<span>{{ $t('firewall.firewallNotStart') }}</span>
|
||||
<span>{{ $t('tool.supervisor.notStartWarn') }}</span>
|
||||
</el-card>
|
||||
<LayoutContent :title="$t('tool.supervisor.list')" v-loading="loading">
|
||||
<template #app>
|
||||
|
@ -72,6 +72,7 @@ const data = ref({
|
||||
init: false,
|
||||
configPath: '',
|
||||
ctlExist: false,
|
||||
serviceName: '',
|
||||
});
|
||||
|
||||
const em = defineEmits(['setting', 'isExist', 'isRunning', 'update:loading', 'update:maskShow']);
|
||||
@ -126,7 +127,7 @@ const getStatus = async () => {
|
||||
em('isExist', true);
|
||||
}
|
||||
if (data.value.init) {
|
||||
initRef.value.acceptParams(data.value.configPath);
|
||||
initRef.value.acceptParams(data.value.configPath, data.value.serviceName);
|
||||
}
|
||||
} catch (error) {}
|
||||
em('update:loading', false);
|
||||
|
@ -9,6 +9,9 @@
|
||||
<el-form-item :label="$t('tool.supervisor.primaryConfig')" prop="primaryConfig">
|
||||
<el-input v-model.trim="initModel.primaryConfig"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('tool.supervisor.serviceName')" prop="serviceName">
|
||||
<el-input v-model.trim="initModel.serviceName"></el-input>
|
||||
</el-form-item>
|
||||
<el-alert
|
||||
:title="$t('tool.supervisor.initWarn')"
|
||||
class="common-prompt"
|
||||
@ -41,15 +44,18 @@ const loading = ref(false);
|
||||
const initForm = ref<FormInstance>();
|
||||
const rules = ref({
|
||||
primaryConfig: [Rules.requiredInput],
|
||||
serviceName: [Rules.requiredInput],
|
||||
});
|
||||
const initModel = ref({
|
||||
primaryConfig: '',
|
||||
serviceName: '',
|
||||
});
|
||||
|
||||
const em = defineEmits(['close']);
|
||||
|
||||
const acceptParams = (primaryConfig: string) => {
|
||||
const acceptParams = (primaryConfig: string, serviceName: string) => {
|
||||
initModel.value.primaryConfig = primaryConfig;
|
||||
initModel.value.serviceName = serviceName;
|
||||
open.value = true;
|
||||
};
|
||||
|
||||
@ -60,7 +66,11 @@ const submit = async (formEl: FormInstance | undefined) => {
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
InitSupervisor({ type: 'supervisord', configPath: initModel.value.primaryConfig })
|
||||
InitSupervisor({
|
||||
type: 'supervisord',
|
||||
configPath: initModel.value.primaryConfig,
|
||||
serviceName: initModel.value.serviceName,
|
||||
})
|
||||
.then(() => {
|
||||
open.value = false;
|
||||
em('close', true);
|
||||
|
Loading…
Reference in New Issue
Block a user