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:
parent
3884f094fd
commit
6a9337553a
1 changed files with 18 additions and 17 deletions
|
|
@ -162,9 +162,10 @@ After=network.target
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=%s/%%i/wallarm
|
WorkingDirectory=%s/%%i/wallarm
|
||||||
EnvironmentFile=-%s/%%i/wallarm/env.list
|
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=/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=%s/%%i/wallarm/nginx/sbin/nginx -c %s/%%i/wallarm/nginx/conf/nginx.conf
|
||||||
ExecStartPre=/bin/sleep 2
|
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
|
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
|
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/
|
ExecStopPost=-%s/%%i/wallarm/nginx/sbin/nginx -s quit -p %s/%%i/wallarm/nginx/
|
||||||
|
|
@ -174,7 +175,7 @@ User=root
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
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)
|
os.WriteFile(tmpl, []byte(content), 0644)
|
||||||
exec.Command("systemctl", "daemon-reload").Run()
|
exec.Command("systemctl", "daemon-reload").Run()
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -251,27 +252,27 @@ func killPort(port string) {
|
||||||
|
|
||||||
func patchPaths(dir string) {
|
func patchPaths(dir string) {
|
||||||
old := "/opt/wallarm"
|
old := "/opt/wallarm"
|
||||||
// Patch all text config files (not binaries)
|
|
||||||
for _, pattern := range []string{
|
for _, pattern := range []string{
|
||||||
"*.sh", "*.list", "*.conf", "*.yaml", "*.yml", "*.json",
|
"*.sh", "*.list", "*.conf", "*.yaml", "*.yml", "*.json",
|
||||||
} {
|
} {
|
||||||
exec.Command("find", dir, "-name", pattern, "-exec",
|
exec.Command("find", dir, "-name", pattern, "-exec",
|
||||||
"sed", "-i", fmt.Sprintf("s|%s|%s|g", old, dir), "{}", ";").Run()
|
"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) {
|
func hashPort(s string) int {
|
||||||
lib64 := filepath.Join(dir, "lib64", "ld-linux-x86-64.so.2")
|
h := 0
|
||||||
if _, err := os.Stat(lib64); err != nil {
|
for _, c := range s {
|
||||||
return
|
h = h*31 + int(c)
|
||||||
}
|
|
||||||
// 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()
|
|
||||||
}
|
}
|
||||||
|
if h < 0 { h = -h }
|
||||||
|
return h % 500
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixElfBinaries removed — patchelf breaks library paths. Use symlink instead.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue