From a914d29961a0b4d810007c4a962bc132a1cf34d0 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Wed, 21 Dec 2022 16:17:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=9D=99=E6=80=81?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E5=88=9B=E5=BB=BA=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/website.go | 9 +++------ backend/app/service/website_utils.go | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 7cd371196..5628df033 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -92,6 +92,8 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error { Proxy: create.Proxy, } + tx, ctx := getTxAndContext() + switch create.Type { case constant.Deployment: if create.AppType == constant.NewApp { @@ -99,19 +101,14 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error { req.Name = create.AppInstall.Name req.AppDetailId = create.AppInstall.AppDetailId req.Params = create.AppInstall.Params - install, err := ServiceGroupApp.Install(context.Background(), req) + install, err := ServiceGroupApp.Install(ctx, req) if err != nil { return err } website.AppInstallID = install.ID } - case constant.Static: - if err := createStaticHtml(website); err != nil { - return err - } } - tx, ctx := getTxAndContext() if err := websiteRepo.Create(ctx, website); err != nil { return err } diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index 5cc29b0b9..ad29d8954 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -94,6 +94,11 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) if err := fileOp.CreateDir(path.Join(siteFolder, "ssl"), 0755); err != nil { return err } + if website.Type == constant.Static { + if err := createStaticHtml(website); err != nil { + return err + } + } } return fileOp.CopyDir(path.Join(nginxFolder, "www", "common", "waf", "rules"), path.Join(siteFolder, "waf")) } @@ -151,9 +156,15 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) e } if err := opNginx(nginxInstall.ContainerName, constant.NginxCheck); err != nil { + _ = deleteWebsiteFolder(nginxInstall, website) return err } - return opNginx(nginxInstall.ContainerName, constant.NginxReload) + if err := opNginx(nginxInstall.ContainerName, constant.NginxReload); err != nil { + _ = deleteWebsiteFolder(nginxInstall, website) + return err + } + + return nil } func delNginxConfig(website model.Website, force bool) error { @@ -564,3 +575,17 @@ func copyConf(srcPath, dstPath string) error { _, _ = io.Copy(out, src) return nil } + +func deleteWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error { + nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name) + siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias) + fileOp := files.NewFileOp() + if fileOp.Stat(siteFolder) { + _ = fileOp.DeleteDir(siteFolder) + } + nginxFilePath := path.Join(nginxFolder, "conf", "conf.d", website.PrimaryDomain+".conf") + if fileOp.Stat(nginxFilePath) { + _ = fileOp.DeleteFile(nginxFilePath) + } + return nil +}