diff --git a/internal/native/native.go b/internal/native/native.go index aa08b93..e4d327a 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -162,9 +162,10 @@ 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 -p %s/%%i/wallarm/nginx/ -ExecStartPre=/bin/sleep 2 +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/ @@ -174,7 +175,7 @@ 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, BaseDir, BaseDir) os.WriteFile(tmpl, []byte(content), 0644) exec.Command("systemctl", "daemon-reload").Run() return nil @@ -251,27 +252,27 @@ func killPort(port string) { func patchPaths(dir string) { old := "/opt/wallarm" - // Patch all text config files (not binaries) 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) + 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() } -func fixElfBinaries(dir string) { - lib64 := filepath.Join(dir, "lib64", "ld-linux-x86-64.so.2") - if _, err := os.Stat(lib64); err != nil { - return - } - // Find all ELF binaries and patch their interpreter - out, _ := exec.Command("find", dir, "-type", "f", "-executable").CombinedOutput() - for _, f := range strings.Split(string(out), "\n") { - f = strings.TrimSpace(f) - if f == "" { - continue - } - exec.Command("patchelf", "--set-interpreter", lib64, f).Run() +func hashPort(s string) int { + h := 0 + for _, c := range s { + h = h*31 + int(c) } + if h < 0 { h = -h } + return h % 500 } + +// fixElfBinaries removed — patchelf breaks library paths. Use symlink instead.