fix: per-instance port offset, improved systemd nginx start

- Port offset from instance name hash avoids supervisord conflicts
- ExecStartPre kills old nginx before starting new one
- Removed broken patchelf approach
This commit is contained in:
admin 2026-08-02 07:57:05 +00:00
parent 3884f094fd
commit 6a9337553a

View file

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