From 44285ad992be2e0c0bb5756a4819a40cc465a60b Mon Sep 17 00:00:00 2001 From: Magnus Root Date: Thu, 19 Mar 2026 18:03:50 +0300 Subject: [PATCH] Delete old docker nginx conf --- containers_part1.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/containers_part1.go b/containers_part1.go index f330d03..9cc151b 100644 --- a/containers_part1.go +++ b/containers_part1.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "time" ) @@ -96,6 +97,27 @@ func setupContainers(config Config, clientTitle string, clientInfo *ClientInfo, } confDPath := filepath.Join("/home/install/conf/ptaf-nginx", clientTitle, fmt.Sprintf("ptaf-agent%03d", containerNum), "conf.d") + + // Удаляем конфиги ресурсов которых больше нет в БД + activeConfFiles := make(map[string]bool) + for _, res := range resources { + activeConfFiles[fmt.Sprintf("%s_%d.conf", clientTitle, res.L7ResourceID)] = true + } + if entries, err := os.ReadDir(confDPath); err == nil { + for _, entry := range entries { + if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".conf") { + if !activeConfFiles[entry.Name()] { + stalePath := filepath.Join(confDPath, entry.Name()) + if err := os.Remove(stalePath); err == nil { + log.Printf(" → Удалён устаревший конфиг ресурса: %s", entry.Name()) + containerChanges[containerNum] = true + } else { + log.Printf(" ⚠ Ошибка удаления устаревшего конфига %s: %v", entry.Name(), err) + } + } + } + } + } containerPorts := []PortMapping{} for _, res := range resources { ports, ok := resourcePortMap[res.L7ResourceID]