Delete old docker nginx conf
This commit is contained in:
parent
417f005e04
commit
44285ad992
1 changed files with 22 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"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")
|
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{}
|
containerPorts := []PortMapping{}
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
ports, ok := resourcePortMap[res.L7ResourceID]
|
ports, ok := resourcePortMap[res.L7ResourceID]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue