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:
parent
6a9337553a
commit
f4e931bbd4
1 changed files with 11 additions and 15 deletions
|
|
@ -106,7 +106,8 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
return fmt.Errorf("register: %w\n%s", regErr, string(data))
|
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.MkdirAll(filepath.Join(BaseDir, node.Name), 0755)
|
||||||
os.RemoveAll(instanceDir)
|
os.RemoveAll(instanceDir)
|
||||||
os.Rename(DeployTo, instanceDir)
|
os.Rename(DeployTo, instanceDir)
|
||||||
|
|
@ -162,20 +163,18 @@ 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
|
ExecStartPre=%s/%%i/wallarm/nginx/sbin/nginx -c %s/%%i/wallarm/nginx/conf/nginx.conf
|
||||||
ExecStartPre=/bin/sleep 1
|
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/
|
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
User=root
|
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)
|
||||||
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
|
||||||
|
|
@ -252,18 +251,15 @@ func killPort(port string) {
|
||||||
|
|
||||||
func patchPaths(dir string) {
|
func patchPaths(dir string) {
|
||||||
old := "/opt/wallarm"
|
old := "/opt/wallarm"
|
||||||
for _, pattern := range []string{
|
// Use bash to execute find+sed reliably
|
||||||
"*.sh", "*.list", "*.conf", "*.yaml", "*.yml", "*.json",
|
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' {} +",
|
||||||
exec.Command("find", dir, "-name", pattern, "-exec",
|
dir, old, dir)).Run()
|
||||||
"sed", "-i", fmt.Sprintf("s|%s|%s|g", old, dir), "{}", ";").Run()
|
// Unique internal ports per instance
|
||||||
}
|
|
||||||
// Unique internal ports per instance (offset by name hash)
|
|
||||||
offset := hashPort(filepath.Base(filepath.Dir(dir)))
|
offset := hashPort(filepath.Base(filepath.Dir(dir)))
|
||||||
exec.Command("sed", "-i",
|
exec.Command("bash", "-c",
|
||||||
fmt.Sprintf("s|:3313|:%d|g; s|:8088|:%d|g; s|:9667|:%d|g",
|
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' {} +",
|
||||||
3313+offset, 8088+offset, 9667+offset),
|
dir, 3313+offset, 6388+offset, 9001+offset, 8088+offset, 9667+offset)).Run()
|
||||||
filepath.Join(dir, "etc", "supervisord.conf")).Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashPort(s string) int {
|
func hashPort(s string) int {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue