mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-09 23:17:21 +08:00
feat: openresty 异常状态下支持修改配置文件 (#6538)
Some checks failed
sync2gitee / repo-sync (push) Failing after -9m16s
Some checks failed
sync2gitee / repo-sync (push) Failing after -9m16s
This commit is contained in:
parent
8a5cb6c946
commit
6a4897b0aa
8 changed files with 60 additions and 28 deletions
|
@ -97,10 +97,10 @@ func (n NginxService) GetStatus() (response.NginxStatus, error) {
|
||||||
func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error {
|
func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
|
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
|
||||||
filePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "nginx.conf")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
filePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "nginx.conf")
|
||||||
if req.Backup {
|
if req.Backup {
|
||||||
backupPath := path.Join(path.Dir(filePath), "bak")
|
backupPath := path.Join(path.Dir(filePath), "bak")
|
||||||
if !fileOp.Stat(backupPath) {
|
if !fileOp.Stat(backupPath) {
|
||||||
|
@ -123,6 +123,14 @@ func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error
|
||||||
if err = fileOp.WriteFile(filePath, strings.NewReader(req.Content), 0644); err != nil {
|
if err = fileOp.WriteFile(filePath, strings.NewReader(req.Content), 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if status, err := checkContainerStatus(nginxInstall.ContainerName); err == nil && status != "running" {
|
||||||
|
if out, err := compose.DownAndUp(nginxInstall.GetComposePath()); err != nil {
|
||||||
|
_ = fileOp.SaveFile(filePath, string(oldContent), 0644)
|
||||||
|
return fmt.Errorf("nginx restart failed: %v", out)
|
||||||
|
} else {
|
||||||
|
return nginxCheckAndReload(string(oldContent), filePath, nginxInstall.ContainerName)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nginxCheckAndReload(string(oldContent), filePath, nginxInstall.ContainerName)
|
return nginxCheckAndReload(string(oldContent), filePath, nginxInstall.ContainerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -475,6 +475,22 @@ func checkContainerName(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkContainerStatus(name string) (string, error) {
|
||||||
|
dockerCli, err := docker.NewClient()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer dockerCli.Close()
|
||||||
|
names, err := dockerCli.ListContainersByName([]string{name})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(names) > 0 {
|
||||||
|
return names[0].State, nil
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
func unInstallPHPExtension(runtime *model.Runtime, delExtensions []string) error {
|
func unInstallPHPExtension(runtime *model.Runtime, delExtensions []string) error {
|
||||||
dir := runtime.GetPath()
|
dir := runtime.GetPath()
|
||||||
fileOP := files.NewFileOp()
|
fileOP := files.NewFileOp()
|
||||||
|
|
|
@ -1155,8 +1155,9 @@ func (w WebsiteService) UpdateNginxConfigFile(req request.WebsiteNginxUpdate) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := nginxFull.SiteConfig.FilePath
|
filePath := nginxFull.SiteConfig.FilePath
|
||||||
if err := files.NewFileOp().WriteFile(filePath, strings.NewReader(req.Content), 0755); err != nil {
|
if err = files.NewFileOp().WriteFile(filePath, strings.NewReader(req.Content), 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nginxCheckAndReload(nginxFull.SiteConfig.OldContent, filePath, nginxFull.Install.ContainerName)
|
return nginxCheckAndReload(nginxFull.SiteConfig.OldContent, filePath, nginxFull.Install.ContainerName)
|
||||||
|
|
|
@ -4,11 +4,6 @@ import (
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Pull(filePath string) (string, error) {
|
|
||||||
stdout, err := cmd.Execf("docker compose -f %s pull", filePath)
|
|
||||||
return stdout, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Up(filePath string) (string, error) {
|
func Up(filePath string) (string, error) {
|
||||||
stdout, err := cmd.Execf("docker compose -f %s up -d", filePath)
|
stdout, err := cmd.Execf("docker compose -f %s up -d", filePath)
|
||||||
return stdout, err
|
return stdout, err
|
||||||
|
@ -19,11 +14,6 @@ func Down(filePath string) (string, error) {
|
||||||
return stdout, err
|
return stdout, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(filePath string) (string, error) {
|
|
||||||
stdout, err := cmd.Execf("docker compose -f %s start", filePath)
|
|
||||||
return stdout, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Stop(filePath string) (string, error) {
|
func Stop(filePath string) (string, error) {
|
||||||
stdout, err := cmd.Execf("docker compose -f %s stop", filePath)
|
stdout, err := cmd.Execf("docker compose -f %s stop", filePath)
|
||||||
return stdout, err
|
return stdout, err
|
||||||
|
@ -38,3 +28,12 @@ func Operate(filePath, operation string) (string, error) {
|
||||||
stdout, err := cmd.Execf("docker compose -f %s %s", filePath, operation)
|
stdout, err := cmd.Execf("docker compose -f %s %s", filePath, operation)
|
||||||
return stdout, err
|
return stdout, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DownAndUp(filePath string) (string, error) {
|
||||||
|
stdout, err := cmd.Execf("docker compose -f %s down", filePath)
|
||||||
|
if err != nil {
|
||||||
|
return stdout, err
|
||||||
|
}
|
||||||
|
stdout, err = cmd.Execf("docker compose -f %s up -d", filePath)
|
||||||
|
return stdout, err
|
||||||
|
}
|
||||||
|
|
|
@ -46,15 +46,7 @@
|
||||||
{{ $t('app.reload') }}
|
{{ $t('app.reload') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
||||||
<el-button
|
<el-button type="primary" @click="setting" link :disabled="data.status === 'Installing'">
|
||||||
type="primary"
|
|
||||||
@click="setting"
|
|
||||||
link
|
|
||||||
:disabled="
|
|
||||||
data.status === 'Installing' ||
|
|
||||||
(data.status !== 'Running' && data.app === 'OpenResty')
|
|
||||||
"
|
|
||||||
>
|
|
||||||
{{ $t('commons.button.set') }}
|
{{ $t('commons.button.set') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
<el-divider v-if="data.app === 'OpenResty'" direction="vertical" />
|
||||||
|
|
|
@ -64,7 +64,7 @@ const webSiteRouter = {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
component: () => import('@/views/website/runtime/java/index.vue'),
|
component: () => import('@/views/website/runtime/java/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
activeMenu: '/websites/runtimes/java',
|
activeMenu: '/websites/runtimes/php',
|
||||||
requiresAuth: false,
|
requiresAuth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -74,7 +74,7 @@ const webSiteRouter = {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
component: () => import('@/views/website/runtime/go/index.vue'),
|
component: () => import('@/views/website/runtime/go/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
activeMenu: '/websites/runtimes/go',
|
activeMenu: '/websites/runtimes/php',
|
||||||
requiresAuth: false,
|
requiresAuth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<LayoutContent :title="$t('nginx.nginxConfig')" :reload="true">
|
<LayoutContent :title="$t('nginx.nginxConfig')" :reload="true">
|
||||||
<template #leftToolBar>
|
<template #leftToolBar>
|
||||||
<el-button type="primary" :plain="activeName !== '1'" @click="changeTab('1')">
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:plain="activeName !== '1'"
|
||||||
|
@click="changeTab('1')"
|
||||||
|
:disabled="status != 'Running'"
|
||||||
|
>
|
||||||
{{ $t('nginx.status') }}
|
{{ $t('nginx.status') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="primary" :plain="activeName !== '2'" @click="changeTab('2')">
|
<el-button type="primary" :plain="activeName !== '2'" @click="changeTab('2')">
|
||||||
|
@ -10,7 +15,12 @@
|
||||||
<el-button type="primary" :plain="activeName !== '3'" @click="changeTab('3')">
|
<el-button type="primary" :plain="activeName !== '3'" @click="changeTab('3')">
|
||||||
{{ $t('website.nginxPer') }}
|
{{ $t('website.nginxPer') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="primary" :plain="activeName !== '4'" @click="changeTab('4')">
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:plain="activeName !== '4'"
|
||||||
|
@click="changeTab('4')"
|
||||||
|
:disabled="status != 'Running'"
|
||||||
|
>
|
||||||
{{ $t('website.log') }}
|
{{ $t('website.log') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
@ -30,8 +40,8 @@ import ContainerLog from '@/components/container-log/index.vue';
|
||||||
import NginxPer from './performance/index.vue';
|
import NginxPer from './performance/index.vue';
|
||||||
import Status from './status/index.vue';
|
import Status from './status/index.vue';
|
||||||
|
|
||||||
let activeName = ref('1');
|
const activeName = ref('1');
|
||||||
let dialogContainerLogRef = ref();
|
const dialogContainerLogRef = ref();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
containerName: {
|
containerName: {
|
||||||
|
@ -55,4 +65,10 @@ const changeTab = (index: string) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.status != 'Running') {
|
||||||
|
activeName.value = '2';
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-loading="loading">
|
<div v-loading="loading">
|
||||||
<CodemirrorPro v-model="content" mode="nginx"></CodemirrorPro>
|
<CodemirrorPro v-model="content" mode="nginx" :heightDiff="350"></CodemirrorPro>
|
||||||
<div class="mt-2.5">
|
<div class="mt-2.5">
|
||||||
<el-button @click="getDefaultConfig()" :disabled="loading">
|
<el-button @click="getDefaultConfig()" :disabled="loading">
|
||||||
{{ $t('app.defaultConfig') }}
|
{{ $t('app.defaultConfig') }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue