fix:Fix issue with error during OpenResty reinstallation (#8117)

This commit is contained in:
zhengkunwang 2025-03-11 13:45:50 +08:00 committed by GitHub
parent 6c251e1a49
commit c56456203f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -537,6 +537,11 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
if err = runScript(t, appInstall, "init"); err != nil {
return err
}
if app.Key == "openresty" {
if err = handleOpenrestyFile(appInstall); err != nil {
return err
}
}
if err = upApp(t, appInstall, req.PullImage); err != nil {
return err
}

View file

@ -1821,3 +1821,29 @@ func getAppTags(appID uint, lang string) ([]response.TagDTO, error) {
}
return res, nil
}
func handleOpenrestyFile(appInstall *model.AppInstall) error {
websites, _ := websiteRepo.List()
if len(websites) == 0 {
return nil
}
hasDefaultWebsite := false
for _, website := range websites {
if website.DefaultServer {
hasDefaultWebsite = true
break
}
}
if !hasDefaultWebsite {
return nil
}
installDir := appInstall.GetPath()
defaultConfigPath := path.Join(installDir, "conf", "default", "00.default.conf")
fileOp := files.NewFileOp()
content, err := fileOp.GetContent(defaultConfigPath)
if err != nil {
return err
}
newContent := strings.ReplaceAll(string(content), "default_server", "")
return fileOp.WriteFile(defaultConfigPath, strings.NewReader(newContent), constant.FilePerm)
}