Delete old docker nginx conf

This commit is contained in:
Magnus Root 2026-03-19 18:03:50 +03:00
parent 417f005e04
commit 44285ad992

View file

@ -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]