fix: use bundled python3.10 in systemd, patch paths after move
This commit is contained in:
parent
a6359beb61
commit
8b49978ea1
1 changed files with 17 additions and 7 deletions
|
|
@ -138,6 +138,9 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
|||
os.RemoveAll(instanceDir)
|
||||
os.Rename(DeployTo, instanceDir)
|
||||
|
||||
// 8. Patch hardcoded /opt/wallarm paths
|
||||
patchPaths(instanceDir)
|
||||
|
||||
// 9. Set up systemd service
|
||||
GenerateSystemdTemplate()
|
||||
svc := "wallarm-node@" + node.Name
|
||||
|
|
@ -182,25 +185,23 @@ func CreateNodesDir() error { return os.MkdirAll(BaseDir, 0755) }
|
|||
|
||||
func GenerateSystemdTemplate() error {
|
||||
tmpl := `/etc/systemd/system/wallarm-node@.service`
|
||||
if _, err := os.Stat(tmpl); err == nil {
|
||||
return nil // already exists
|
||||
}
|
||||
content := fmt.Sprintf(`[Unit]
|
||||
Description=Wallarm Node - %%i
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
Type=simple
|
||||
WorkingDirectory=%s/%%i/wallarm
|
||||
ExecStart=/bin/bash %s/%%i/wallarm/supervisord.sh start
|
||||
ExecStop=/bin/bash %s/%%i/wallarm/supervisord.sh stop
|
||||
EnvironmentFile=-%s/%%i/wallarm/env.list
|
||||
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
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`, 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
|
||||
|
|
@ -255,3 +256,12 @@ func killPort(port string) {
|
|||
fmt.Printf(" Killed existing process on port %s\n", port)
|
||||
}
|
||||
}
|
||||
|
||||
func patchPaths(dir string) {
|
||||
exec.Command("sed", "-i", fmt.Sprintf("s|/opt/wallarm|%s|g", dir),
|
||||
filepath.Join(dir, "env.list")).Run()
|
||||
exec.Command("find", dir, "-name", "*.sh", "-exec",
|
||||
"sed", "-i", fmt.Sprintf("s|/opt/wallarm|%s|g", dir), "{}", ";").Run()
|
||||
exec.Command("sed", "-i", fmt.Sprintf("s|/opt/wallarm|%s|g", dir),
|
||||
filepath.Join(dir, "etc", "supervisord.conf")).Run()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue