fix: use bash -c for find+sed, kill temp nginx, simplify systemd

- patchPaths uses bash -c 'find ... -exec sed {} +' instead of Go exec
- Port offset applied to ALL yaml/yml/conf files across instance
- Kill deploy-time nginx before systemd starts
- Simplified systemd template (removed broken fuser line)
This commit is contained in:
admin 2026-08-02 08:18:06 +00:00
parent 6a9337553a
commit f4e931bbd4

View file

@ -106,7 +106,8 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
return fmt.Errorf("register: %w\n%s", regErr, string(data))
}
// 8. Move /opt/wallarm → /opt/fw/{name}/wallarm
// 8. Move /opt/wallarm → /opt/fw/{name}/wallarm, kill temp nginx
exec.Command("pkill", "-f", filepath.Join(DeployTo, "nginx")).Run()
os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755)
os.RemoveAll(instanceDir)
os.Rename(DeployTo, instanceDir)
@ -162,20 +163,18 @@ After=network.target
Type=simple
WorkingDirectory=%s/%%i/wallarm
EnvironmentFile=-%s/%%i/wallarm/env.list
ExecStartPre=/bin/sh -c 'fuser -k %%s/%%i/wallarm/nginx/nginx.pid 2>/dev/null; true' %s
ExecStartPre=/bin/ln -sf %s/%%i/wallarm /opt/wallarm
ExecStartPre=%s/%%i/wallarm/nginx/sbin/nginx -c %s/%%i/wallarm/nginx/conf/nginx.conf
ExecStartPre=/bin/sleep 1
ExecStart=%s/%%i/wallarm/usr/bin/python3.10 %s/%%i/wallarm/usr/bin/supervisord -c %s/%%i/wallarm/etc/supervisord.conf
ExecStop=%s/%%i/wallarm/usr/bin/python3.10 %s/%%i/wallarm/usr/bin/supervisord -c %s/%%i/wallarm/etc/supervisord.conf shutdown
ExecStopPost=-%s/%%i/wallarm/nginx/sbin/nginx -s quit -p %s/%%i/wallarm/nginx/
Restart=on-failure
RestartSec=5
User=root
[Install]
WantedBy=multi-user.target
`, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir)
`, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir, BaseDir)
os.WriteFile(tmpl, []byte(content), 0644)
exec.Command("systemctl", "daemon-reload").Run()
return nil
@ -252,18 +251,15 @@ func killPort(port string) {
func patchPaths(dir string) {
old := "/opt/wallarm"
for _, pattern := range []string{
"*.sh", "*.list", "*.conf", "*.yaml", "*.yml", "*.json",
} {
exec.Command("find", dir, "-name", pattern, "-exec",
"sed", "-i", fmt.Sprintf("s|%s|%s|g", old, dir), "{}", ";").Run()
}
// Unique internal ports per instance (offset by name hash)
// Use bash to execute find+sed reliably
exec.Command("bash", "-c",
fmt.Sprintf("find %s -type f \\( -name '*.sh' -o -name '*.list' -o -name '*.conf' -o -name '*.yaml' -o -name '*.yml' -o -name '*.json' \\) -exec sed -i 's|%s|%s|g' {} +",
dir, old, dir)).Run()
// Unique internal ports per instance
offset := hashPort(filepath.Base(filepath.Dir(dir)))
exec.Command("sed", "-i",
fmt.Sprintf("s|:3313|:%d|g; s|:8088|:%d|g; s|:9667|:%d|g",
3313+offset, 8088+offset, 9667+offset),
filepath.Join(dir, "etc", "supervisord.conf")).Run()
exec.Command("bash", "-c",
fmt.Sprintf("find %s -type f \\( -name '*.yaml' -o -name '*.yml' -o -name '*.conf' \\) -exec sed -i 's|:3313|:%d|g; s|:6388|:%d|g; s|:9001|:%d|g; s|:8088|:%d|g; s|:9667|:%d|g' {} +",
dir, 3313+offset, 6388+offset, 9001+offset, 8088+offset, 9667+offset)).Run()
}
func hashPort(s string) int {