fix: proper systemd template, auto-enable after deploy

This commit is contained in:
admin 2026-08-01 19:30:42 +00:00
parent bf3ba41179
commit ddf0dd9884

View file

@ -106,7 +106,13 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
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)
fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir)
// 9. Set up systemd service
GenerateSystemdTemplate()
svc := "wallarm-node@" + node.Name
exec.Command("systemctl", "enable", svc).Run()
exec.Command("systemctl", "start", svc).Run()
fmt.Printf("[%s] Done. Installed to %s (systemctl status %s)\n", node.Name, instanceDir, svc)
return nil return nil
} }
@ -141,10 +147,45 @@ func cloudFromHost(host string) string {
return "EU" return "EU"
} }
func CreateNodesDir() error { return os.MkdirAll(BaseDir, 0755) } func CreateNodesDir() error { return os.MkdirAll(BaseDir, 0755) }
func GenerateSystemdTemplate() error { return nil }
func RemoveNode(name string) error { return nil } func GenerateSystemdTemplate() error {
func Status(name string) (string, error) { return "", nil } 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
WorkingDirectory=%s/%%i/wallarm
ExecStart=/bin/bash %s/%%i/wallarm/supervisord.sh start
ExecStop=/bin/bash %s/%%i/wallarm/supervisord.sh stop
Restart=on-failure
RestartSec=5
User=root
[Install]
WantedBy=multi-user.target
`, BaseDir, BaseDir, BaseDir)
os.WriteFile(tmpl, []byte(content), 0644)
exec.Command("systemctl", "daemon-reload").Run()
return nil
}
func RemoveNode(name string) error {
exec.Command("systemctl", "stop", "wallarm-node@"+name).Run()
exec.Command("systemctl", "disable", "wallarm-node@"+name).Run()
os.RemoveAll(filepath.Join(BaseDir, name))
return nil
}
func Status(name string) (string, error) {
out, _ := exec.Command("systemctl", "status", "wallarm-node@"+name, "--no-pager").CombinedOutput()
return string(out), nil
}
func startNginx(dir string, node state.Node, port string) { func startNginx(dir string, node state.Node, port string) {
nginxDir := filepath.Join(dir, "nginx") nginxDir := filepath.Join(dir, "nginx")